|
21 | 21 | from packaging.requirements import Requirement |
22 | 22 |
|
23 | 23 |
|
| 24 | +async def get_package_from_pypi(package_name, plugin_path): |
| 25 | + """ |
| 26 | + Download a package from PyPI. |
| 27 | +
|
| 28 | + :param name: name of the package to download from PyPI |
| 29 | + :return: String path to the package |
| 30 | + """ |
| 31 | + config = BandersnatchConfig().config |
| 32 | + config["mirror"]["master"] = "https://pypi.org" |
| 33 | + config["mirror"]["workers"] = "1" |
| 34 | + config["mirror"]["directory"] = plugin_path |
| 35 | + if not config.has_section("plugins"): |
| 36 | + config.add_section("plugins") |
| 37 | + config["plugins"]["enabled"] = "blocklist_release\n" |
| 38 | + if not config.has_section("allowlist"): |
| 39 | + config.add_section("allowlist") |
| 40 | + config["plugins"]["enabled"] += "allowlist_release\nallowlist_project\n" |
| 41 | + config["allowlist"]["packages"] = "\n".join([package_name]) |
| 42 | + os.makedirs(os.path.join(plugin_path, "dist"), exist_ok=True) |
| 43 | + async with Master("https://pypi.org/") as master: |
| 44 | + mirror = BandersnatchMirror(homedir=plugin_path, master=master) |
| 45 | + name = Requirement(package_name).name |
| 46 | + result = await mirror.synchronize([name]) |
| 47 | + package_found = False |
| 48 | + |
| 49 | + for package in result[name]: |
| 50 | + current_path = os.path.join(plugin_path, package) |
| 51 | + destination_path = os.path.join(plugin_path, "dist", os.path.basename(package)) |
| 52 | + shutil.move(current_path, destination_path) |
| 53 | + package_found = True |
| 54 | + return package_found |
| 55 | + |
24 | 56 |
|
25 | 57 | def create_release_commits(repo, release_version, plugin_path): |
26 | 58 | """Build changelog, set version, commit, bump to next dev version, commit.""" |
@@ -96,7 +128,9 @@ def create_tag_and_build_package(repo, desired_tag, commit_sha, plugin_path): |
96 | 128 |
|
97 | 129 | # Check if Package is available on PyPI |
98 | 130 | loop = asyncio.get_event_loop() # noqa |
99 | | - package_found = asyncio.run(get_package_from_pypi("pulp-python=={tag.name}", plugin_path)) |
| 131 | + package_found = asyncio.run( |
| 132 | + get_package_from_pypi("pulp-python=={tag.name}", plugin_path) |
| 133 | + ) # noqa |
100 | 134 |
|
101 | 135 | if not package_found: |
102 | 136 | os.system("python3 setup.py sdist bdist_wheel --python-tag py3") |
|
0 commit comments