From 2ce4d89f751d58ada6e0918ecf631e82605029bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 4 Jan 2023 08:36:05 -0800 Subject: [PATCH] Add more c-extension env-vars to default pass_env (#2818) --- docs/changelog/2818.bugfix.rst | 3 +++ src/tox/tox_env/api.py | 6 ++++++ src/tox/tox_env/python/api.py | 3 ++- tests/session/cmd/test_show_config.py | 7 ++++--- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 docs/changelog/2818.bugfix.rst diff --git a/docs/changelog/2818.bugfix.rst b/docs/changelog/2818.bugfix.rst new file mode 100644 index 000000000..a0acde1cb --- /dev/null +++ b/docs/changelog/2818.bugfix.rst @@ -0,0 +1,3 @@ +Add ``CC``, ``CFLAGS``, ``CCSHARED``, ``CXX``, ``CPPFLAGS``, ``LDFLAGS``, ``PKG_CONFIG`` and ``PKG_CONFIG_SYSROOT_DIR`` +to the default passed through environment variables list as these are needed for building various C-extensions +- by :user:`gaborbernat`. diff --git a/src/tox/tox_env/api.py b/src/tox/tox_env/api.py index 3ce15b993..1542a8fc6 100644 --- a/src/tox/tox_env/api.py +++ b/src/tox/tox_env/api.py @@ -211,7 +211,13 @@ def _default_pass_env(self) -> list[str]: "LANGUAGE", # localization "CURL_CA_BUNDLE", # curl certificates "SSL_CERT_FILE", # https certificates + "CC", # C compiler command + "CFLAGS", # C compiler flags + "CCSHARED", # compiler flags used to build a shared library + "CXX", # C++ compiler command + "CPPFLAGS", # C++ compiler flags "LD_LIBRARY_PATH", # location of libs + "LDFLAGS", # linker flags ] if sys.stdout.isatty(): # if we're on a interactive shell pass on the TERM env.append("TERM") diff --git a/src/tox/tox_env/python/api.py b/src/tox/tox_env/python/api.py index 9772a9412..9a8ff6ce3 100644 --- a/src/tox/tox_env/python/api.py +++ b/src/tox/tox_env/python/api.py @@ -118,7 +118,8 @@ def _default_pass_env(self) -> list[str]: "NUMBER_OF_PROCESSORS", # multiprocessing.cpu_count() ], ) - env.extend(["PKG_CONFIG_PATH"]) # used by binary extensions during installation + binary_extension_build = ["PKG_CONFIG", "PKG_CONFIG_PATH", "PKG_CONFIG_SYSROOT_DIR"] + env.extend(binary_extension_build) # used by binary extensions during installation env.extend(["REQUESTS_CA_BUNDLE"]) return env diff --git a/tests/session/cmd/test_show_config.py b/tests/session/cmd/test_show_config.py index f0acb3d79..9ef9f3007 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -115,10 +115,11 @@ def test_pass_env_config_default(tox_project: ToxProjectCreator, stdout_is_atty: pass_env = outcome.env_conf("py")["pass_env"] is_win = sys.platform == "win32" expected = ( - (["COMSPEC"] if is_win else []) - + ["CURL_CA_BUNDLE", "LANG", "LANGUAGE", "LD_LIBRARY_PATH"] + ["CC", "CCSHARED", "CFLAGS"] + + (["COMSPEC"] if is_win else []) + + ["CPPFLAGS", "CURL_CA_BUNDLE", "CXX", "LANG", "LANGUAGE", "LDFLAGS", "LD_LIBRARY_PATH"] + (["MSYSTEM", "NUMBER_OF_PROCESSORS", "PATHEXT"] if is_win else []) - + ["PIP_*", "PKG_CONFIG_PATH"] + + ["PIP_*", "PKG_CONFIG", "PKG_CONFIG_PATH", "PKG_CONFIG_SYSROOT_DIR"] + (["PROCESSOR_ARCHITECTURE"] if is_win else []) + (["PROGRAMDATA"] if is_win else []) + (["PROGRAMFILES"] if is_win else [])