From 647b509c74583100dcc428b93ae9e1fe51bdc633 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Mon, 18 Sep 2023 17:06:09 +0100 Subject: [PATCH 1/2] Add test for environment and environment_pass references --- unit_test/options_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/unit_test/options_test.py b/unit_test/options_test.py index 134db012e..009900df2 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -253,3 +253,22 @@ def test_container_engine_option(tmp_path: Path, toml_assignment, result_name, r assert parsed_container_engine.name == result_name assert parsed_container_engine.create_args == result_create_args + + +def test_environment_pass_references(): + options = Options( + platform="linux", + command_line_arguments=CommandLineArguments.defaults(), + env={ + "CIBW_ENVIRONMENT_PASS_LINUX": "STARTER MAIN_COURSE", + "STARTER": "green eggs", + "MAIN_COURSE": "ham", + "CIBW_ENVIRONMENT": 'MEAL="$STARTER and $MAIN_COURSE"', + }, + ) + parsed_environment = options.build_options(identifier=None).environment + assert parsed_environment.as_dictionary(prev_environment={}) == { + "MEAL": "green eggs and ham", + "STARTER": "green eggs", + "MAIN_COURSE": "ham", + } From 62a06d28b51365be808658b576c67129fa9505ea Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Mon, 18 Sep 2023 17:08:30 +0100 Subject: [PATCH 2/2] Change order of environment-pass, so environment can reference it --- cibuildwheel/environment.py | 8 ++++++-- cibuildwheel/options.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index d7727ae48..e4018b915 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -124,8 +124,12 @@ def as_dictionary( return environment - def add(self, name: str, value: str) -> None: - self.assignments.append(EnvironmentAssignmentRaw(name=name, value=value)) + def add(self, name: str, value: str, prepend: bool = False) -> None: + assignment = EnvironmentAssignmentRaw(name=name, value=value) + if prepend: + self.assignments.insert(0, assignment) + else: + self.assignments.append(assignment) def __repr__(self) -> str: return f"{self.__class__.__name__}({[repr(a) for a in self.assignments]!r})" diff --git a/cibuildwheel/options.py b/cibuildwheel/options.py index 581e576b8..899240526 100644 --- a/cibuildwheel/options.py +++ b/cibuildwheel/options.py @@ -530,9 +530,9 @@ def build_options(self, identifier: str | None) -> BuildOptions: # Pass through environment variables if self.platform == "linux": - for env_var_name in environment_pass: + for env_var_name in reversed(environment_pass): with contextlib.suppress(KeyError): - environment.add(env_var_name, self.env[env_var_name]) + environment.add(env_var_name, self.env[env_var_name], prepend=True) if dependency_versions == "pinned": dependency_constraints: None | (