Skip to content
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

fix: evaluate environment-pass before environment, so environment can reference or override those variables #1617

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cibuildwheel/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
4 changes: 2 additions & 2 deletions cibuildwheel/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,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 | (
Expand Down
19 changes: 19 additions & 0 deletions unit_test/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@ def test_container_engine_option(tmp_path: Path, toml_assignment, result_name, r
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",
}


@pytest.mark.parametrize(
("toml_assignment", "result_name", "result_args"),
[
Expand Down