Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ environment variable will be used.

```toml
[plugins]
[plugins.pypi_mirror]
[plugins.pypi_mirror.simple]
url = "https://example.org/repository/pypi-proxy/simple/"

[plugins.pypi_mirror.pypi_example]
url = "https://pypi.example.org/simple/"

[plugins.pypi_mirror.enterprise]
url = "https://me:[email protected]/pypi/simple/"
```

... in [either](https://python-poetry.org/docs/configuration/) a project's
Expand Down
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