1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Add per-requirement --config-settings

This commit is contained in:
q0w 2022-12-05 08:05:26 +03:00
parent 5f3f592c45
commit 227fe23b0e
6 changed files with 42 additions and 2 deletions

1
news/11325.feature.rst Normal file
View file

@ -0,0 +1 @@
Support a per-requirement ``--config-settings`` option.

View file

@ -438,6 +438,9 @@ class RequirementCommand(IndexGroupCommand):
isolated=options.isolated_mode,
use_pep517=options.use_pep517,
user_supplied=True,
config_settings=parsed_req.options.get("config_settings")
if parsed_req.options
else None,
)
requirements.append(req_to_add)

View file

@ -72,6 +72,7 @@ SUPPORTED_OPTIONS_REQ: List[Callable[..., optparse.Option]] = [
cmdoptions.install_options,
cmdoptions.global_options,
cmdoptions.hash,
cmdoptions.config_settings,
]
# the 'dest' string values

View file

@ -150,6 +150,8 @@ class InstallRequirement:
self.global_options = global_options if global_options else []
self.hash_options = hash_options if hash_options else {}
self.config_settings = config_settings
if isinstance(comes_from, InstallRequirement) and comes_from.config_settings:
self.config_settings = comes_from.config_settings
# Set to True after successful preparation of this requirement
self.prepared = False
# User supplied requirement are explicitly requested for installation

View file

@ -112,6 +112,20 @@ def test_backend_sees_config(script: PipTestEnvironment) -> None:
assert json.loads(output) == {"FOO": "Hello"}
def test_backend_sees_config_reqs(script: PipTestEnvironment) -> None:
name, version, project_dir = make_project(script.scratch_path)
script.scratch_path.joinpath("reqs.txt").write_text(
f"{project_dir} --config-settings FOO=Hello"
)
script.pip("wheel", "-r", "reqs.txt")
wheel_file_name = f"{name}-{version}-py3-none-any.whl"
wheel_file_path = script.cwd / wheel_file_name
with open(wheel_file_path, "rb") as f:
with ZipFile(f) as z:
output = z.read("config.json")
assert json.loads(output) == {"FOO": "Hello"}
def test_install_sees_config(script: PipTestEnvironment) -> None:
_, _, project_dir = make_project(script.scratch_path)
script.pip(
@ -125,6 +139,17 @@ def test_install_sees_config(script: PipTestEnvironment) -> None:
assert json.load(f) == {"FOO": "Hello"}
def test_install_sees_config_reqs(script: PipTestEnvironment) -> None:
_, _, project_dir = make_project(script.scratch_path)
script.scratch_path.joinpath("reqs.txt").write_text(
f"{project_dir} --config-settings FOO=Hello"
)
script.pip("install", "-r", "reqs.txt")
config = script.site_packages_path / "config.json"
with open(config, "rb") as f:
assert json.load(f) == {"FOO": "Hello"}
def test_install_editable_sees_config(script: PipTestEnvironment) -> None:
_, _, project_dir = make_project(script.scratch_path)
script.pip(

View file

@ -74,7 +74,13 @@ def parse_reqfile(
options=options,
constraint=constraint,
):
yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)
yield install_req_from_parsed_requirement(
parsed_req,
isolated=isolated,
config_settings=parsed_req.options.get("config_settings")
if parsed_req.options
else None,
)
def test_read_file_url(tmp_path: Path, session: PipSession) -> None:
@ -346,12 +352,14 @@ class TestProcessLine:
def test_options_on_a_requirement_line(self, line_processor: LineProcessor) -> None:
line = (
"SomeProject --install-option=yo1 --install-option yo2 "
'--global-option="yo3" --global-option "yo4"'
'--global-option="yo3" --global-option "yo4" '
'--config-settings="yo3=yo4" --config-settings "yo1=yo2"'
)
filename = "filename"
req = line_processor(line, filename, 1)[0]
assert req.global_options == ["yo3", "yo4"]
assert req.install_options == ["yo1", "yo2"]
assert req.config_settings == {"yo3": "yo4", "yo1": "yo2"}
def test_hash_options(self, line_processor: LineProcessor) -> None:
"""Test the --hash option: mostly its value storage.