-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure private PyPi repositories in the environment #471
Changes from 3 commits
34a5b62
134bd76
84d13d8
90981e6
57391f3
effce6b
6b0a631
052b256
4b74246
c2083e5
665e8c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import os | ||
import re | ||
import sys | ||
|
||
from functools import lru_cache | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Dict, List, Optional | ||
from urllib.parse import urldefrag, urlsplit, urlunsplit | ||
|
@@ -373,6 +375,9 @@ def _prepare_repositories_pool(allow_pypi_requests: bool) -> Pool: | |
factory = Factory() | ||
config = factory.create_config() | ||
repos = [ | ||
factory.create_legacy_repository({"name": name, "url": url}, config) | ||
for name, url in _parse_repositories_from_environment().items() | ||
] + [ | ||
factory.create_legacy_repository( | ||
{"name": source[0], "url": source[1]["url"]}, config | ||
) | ||
Comment on lines
381
to
383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've left the previous method here so this is not a breaking change. However since this is exposing an implementation detail as an interface, it might be worth adding a deprecation warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we're ready yet to deprecate it. I'm very eager to ditch anything Poetry-related, but setting up environment variables can be a pain, and until we get something better in place, some people may prefer the Poetry interface. |
||
|
@@ -383,10 +388,21 @@ def _prepare_repositories_pool(allow_pypi_requests: bool) -> Pool: | |
return Pool(repositories=[*repos]) | ||
|
||
|
||
@lru_cache(maxsize=1) | ||
def _parse_repositories_from_environment() -> Dict[str, str]: | ||
env_prefix = "CONDA_LOCK_PYPI_REPOSITORY_" | ||
return { | ||
key[len(env_prefix) :].lower(): value | ||
for key, value in os.environ.items() | ||
if key.startswith(env_prefix) | ||
} | ||
|
||
|
||
def _strip_auth(url: str) -> str: | ||
"""Strip HTTP Basic authentication from a URL.""" | ||
parts = urlsplit(url, allow_fragments=True) | ||
# Remove everything before and including the last '@' character in the part | ||
# between 'scheme://' and the subsequent '/'. | ||
netloc = parts.netloc.split("@")[-1] | ||
return urlunsplit((parts.scheme, netloc, parts.path, parts.query, parts.fragment)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please write a test for
_prepare_repositories_pool
to exercise this functionality?