-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
[Feature] Allow Environment Override #1842
base: main
Are you sure you want to change the base?
Changes from all commits
cd84368
678f496
06d6509
27d7458
91aa49b
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 |
---|---|---|
|
@@ -25,12 +25,14 @@ | |
from ..repositories.base import BaseRepository | ||
from ..resolver import BacktrackingResolver, LegacyResolver | ||
from ..utils import ( | ||
PEP508_ENVIRONMENT_MARKERS, | ||
UNSAFE_PACKAGES, | ||
dedup, | ||
drop_extras, | ||
is_pinned_requirement, | ||
key_from_ireq, | ||
parse_requirements_from_wheel_metadata, | ||
validate_environment_overrides, | ||
) | ||
from ..writer import OutputWriter | ||
|
||
|
@@ -302,6 +304,14 @@ def _determine_linesep( | |
help="Specify a package to consider unsafe; may be used more than once. " | ||
f"Replaces default unsafe packages: {', '.join(sorted(UNSAFE_PACKAGES))}", | ||
) | ||
@click.option( | ||
"--override-environment", | ||
multiple=True, | ||
type=(str, str), | ||
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. can we add validation on the values that people can override? I would expect this to fail if I pass 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. Added argument validation |
||
help="Specify an environment marker to override." | ||
"This can be used to fetch requirements for a different platform", | ||
callback=validate_environment_overrides, | ||
) | ||
def cli( | ||
ctx: click.Context, | ||
verbose: int, | ||
|
@@ -340,6 +350,7 @@ def cli( | |
emit_index_url: bool, | ||
emit_options: bool, | ||
unsafe_package: tuple[str, ...], | ||
override_environment: dict[str, str], | ||
) -> None: | ||
""" | ||
Compiles requirements.txt from requirements.in, pyproject.toml, setup.cfg, | ||
|
@@ -429,6 +440,21 @@ def cli( | |
pip_args.extend(["--cache-dir", cache_dir]) | ||
pip_args.extend(right_args) | ||
|
||
env_dict = dict(override_environment) | ||
if len(env_dict) > 0: | ||
# Since the environment is overriden globally, handle it here in the | ||
# top level instead of within the resolver. | ||
import pip._vendor.packaging.markers | ||
|
||
default_env = pip._vendor.packaging.markers.default_environment() | ||
|
||
def overriden_environment() -> dict[str, str]: | ||
return { | ||
k: env_dict.get(k, default_env[k]) for k in PEP508_ENVIRONMENT_MARKERS | ||
} | ||
|
||
pip._vendor.packaging.markers.default_environment = overriden_environment | ||
|
||
repository: BaseRepository | ||
repository = PyPIRepository(pip_args, cache_dir=cache_dir) | ||
|
||
|
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.
It would be great to have a short example in the
README
.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.
Added an example for a 'typical' Linux machine