-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: use pip sources config from poetry #887
base: main
Are you sure you want to change the base?
Changes from all commits
0c42b89
5b8acdf
c960b7a
a49ed6d
bb0de87
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from typing import Iterator | ||
from typing import Optional | ||
from typing import Tuple | ||
from urllib.parse import urlparse | ||
|
||
import nox | ||
from packaging.requirements import InvalidRequirement | ||
|
@@ -90,6 +91,38 @@ def _to_constraints() -> Iterator[str]: | |
return "\n".join(_to_constraints()) | ||
|
||
|
||
def to_global_pip_args(requirements: str) -> Tuple[Optional[str]]: | ||
"""Convert the requirements to global pip arguments.""" | ||
index_args = set() | ||
trusted_hosts = set() | ||
for requirement in requirements.splitlines(): | ||
for re_pattern, kwarg_pattern in [ | ||
(re.compile(r"^(-i|--index-url)[ =]+(?P<url>.*)$"), "--index-url={url}"), | ||
( | ||
re.compile(r"^--extra-index-url[ =]+(?P<url>.*)$"), | ||
"--extra-index-url={url}", | ||
), | ||
]: | ||
|
||
match = re_pattern.match(requirement.strip()) | ||
if match: | ||
index_args.add(kwarg_pattern.format(**match.groupdict())) | ||
|
||
# if there is a url in the captured pattern, ensure the domain gets | ||
# added as a trusted host | ||
try: | ||
trusted_hosts.add(urlparse(match.group("url")).netloc) | ||
except IndexError: | ||
pass | ||
|
||
# add the trusted hosts | ||
index_args = tuple(sorted(index_args)) | ||
for trusted_host in sorted(trusted_hosts): | ||
index_args += (f"--trusted-host={trusted_host}",) | ||
|
||
return index_args | ||
|
||
|
||
class _PoetrySession: | ||
"""Poetry-related utilities for session functions.""" | ||
|
||
|
@@ -148,6 +181,8 @@ def rewrite(arg: str, extras: Optional[str]) -> str: | |
except CommandSkippedError: | ||
return | ||
|
||
# args += to_global_pip_args(requirements) | ||
|
||
self.session.install(f"--constraint={requirements}", *args, **kwargs) | ||
|
||
def installroot( | ||
|
@@ -224,8 +259,10 @@ def export_requirements(self) -> Path: | |
digest = hashlib.blake2b(lockdata).hexdigest() | ||
|
||
if not hashfile.is_file() or hashfile.read_text() != digest: | ||
constraints = to_constraints(self.poetry.export()) | ||
path.write_text(constraints) | ||
requirements_text = self.poetry.export() | ||
constraints = to_constraints(requirements_text) | ||
pip_args = "\n".join(to_global_pip_args(requirements_text)) | ||
path.write_text("\n".join([pip_args, constraints])) | ||
Comment on lines
+262
to
+265
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 not sure if this data should be here or sent as arguments in the install command. Thoughts? |
||
hashfile.write_text(digest) | ||
|
||
return path | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,12 @@ pygments = ["pygments"] | |
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[[tool.poetry.source]] | ||
name = "pypi-all-source1" | ||
url = "https://pypi.python.org/simple" | ||
default = true | ||
|
||
[[tool.poetry.source]] | ||
name = "pypi-all-source2" | ||
url = "https://pypi.python.org/all" | ||
Comment on lines
+27
to
+30
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.
|
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.
This is where I had the config being injected before. I'll update this based on your opinion of how to best proceed.