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

feat: support passenv #914

Merged
merged 10 commits into from Nov 21, 2021
3 changes: 3 additions & 0 deletions cibuildwheel/environment.py
Expand Up @@ -84,6 +84,9 @@ def as_dictionary(

return environment

def add(self, name: str, value: str) -> None:
self.assignments.append(EnvironmentAssignment(f'{name}="{value}"'))
henryiii marked this conversation as resolved.
Show resolved Hide resolved

def as_shell_commands(self) -> List[str]:
return [a.as_shell_assignment() for a in self.assignments]

Expand Down
9 changes: 9 additions & 0 deletions cibuildwheel/options.py
Expand Up @@ -408,6 +408,7 @@ def build_options(self, identifier: Optional[str]) -> BuildOptions:
environment_config = self.reader.get(
"environment", table={"item": '{k}="{v}"', "sep": " "}
)
passenv = self.reader.get("passenv", sep=",").split(",")
henryiii marked this conversation as resolved.
Show resolved Hide resolved
before_build = self.reader.get("before-build", sep=" && ")
repair_command = self.reader.get("repair-wheel-command", sep=" && ")

Expand Down Expand Up @@ -438,6 +439,14 @@ def build_options(self, identifier: Optional[str]) -> BuildOptions:
traceback.print_exc(None, sys.stderr)
sys.exit(2)

# Pass through environment variables
if self.platform == "linux":
for passedenv in passenv:
try:
environment.add(passedenv, os.environ[passedenv])
except KeyError:
pass

if dependency_versions == "pinned":
dependency_constraints: Optional[
DependencyConstraints
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/resources/defaults.toml
Expand Up @@ -7,6 +7,7 @@ archs = ["auto"]
build-frontend = "pip"
dependency-versions = "pinned"
environment = {}
passenv = []
build-verbosity = ""

before-all = ""
Expand Down
20 changes: 20 additions & 0 deletions unit_test/options_test.py
Expand Up @@ -15,6 +15,8 @@

manylinux-x86_64-image = "manylinux1"

passenv = ["EXAMPLE_ENV"]

[tool.cibuildwheel.macos]
test-requires = "else"

Expand Down Expand Up @@ -66,3 +68,21 @@ def test_options_1(tmp_path, monkeypatch):
assert local.manylinux_images is not None
assert local.test_command == "pyproject-override"
assert local.manylinux_images["x86_64"] == pinned_x86_64_docker_image["manylinux2014"]


def test_passthrough(tmp_path, monkeypatch):

with tmp_path.joinpath("pyproject.toml").open("w") as f:
f.write(PYPROJECT_1)

args = get_default_command_line_arguments()
args.package_dir = str(tmp_path)

monkeypatch.setattr(platform_module, "machine", lambda: "x86_64")
monkeypatch.setenv("EXAMPLE_ENV", "ONE")

options = Options(platform="linux", command_line_arguments=args)

default_build_options = options.build_options(identifier=None)

assert default_build_options.environment == parse_environment('FOO="BAR" EXAMPLE_ENV="ONE"')