Skip to content

Commit

Permalink
Implemented changes to support several mirrors (see arcesium#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucharo committed Dec 10, 2022
1 parent b650dc5 commit 8e44d6a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/poetry_plugin_pypi_mirror/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class PyPIMirrorPlugin(Plugin):
def activate(self, poetry: Poetry, io: IO):

# Environment var overrides poetry configuration
pypi_mirror_url = os.environ.get("POETRY_PYPI_MIRROR_URL")
pypi_mirror_url = pypi_mirror_url or poetry.config.get("plugins", {}).get(
"pypi_mirror", {}
).get("url")
pypi_mirror_url_env = os.environ.get("POETRY_PYPI_MIRROR_URL")
pypi_mirror_url_config = [ (name, details['url']) for name, details in poetry.config.\
get("plugins", {}). \
get("pypi_mirror", {}).values() ]
pypi_mirror_url = pypi_mirror_url_env or pypi_mirror_url_config

if not pypi_mirror_url:
return
Expand All @@ -47,7 +48,7 @@ def activate(self, poetry: Poetry, io: IO):

replacement_repository = SourceStrippedLegacyRepository(
DEFAULT_REPO_NAME,
pypi_mirror_url,
pypi_mirror_url[0],
config=poetry.config,
disable_cache=pypi_prioritized_repository.repository._disable_cache,
)
Expand All @@ -61,6 +62,19 @@ def activate(self, poetry: Poetry, io: IO):
secondary=priority == Priority.SECONDARY,
)

for name, url in pypi_mirror_url[1:]:
repo = SourceStrippedLegacyRepository(
name,
url,
config=poetry.config,
disable_cache=pypi_prioritized_repository.repository._disable_cache,
)
poetry.pool.add_repository(
repository=repo,
default=False,
secondary=True,
)


class SourceStrippedLegacyRepository(LegacyRepository):
def __init__(
Expand Down

0 comments on commit 8e44d6a

Please sign in to comment.