diff --git a/CHANGELOG.md b/CHANGELOG.md index d3f8f3f..be49008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixed + +- On macOS with `/opt/homebrew` on `PATH`, removing it from the `PATH` used to compile modules also dropped the folder where already compiled modules install their binaries (`deps/bin`), and the `/usr/bin:/bin` fallback + ## v2.2.0 ### Fixed diff --git a/docs/configuration/portable-python-yml.md b/docs/configuration/portable-python-yml.md index d0e479e..a18dc5b 100644 --- a/docs/configuration/portable-python-yml.md +++ b/docs/configuration/portable-python-yml.md @@ -3,7 +3,7 @@ type: Configuration title: portable-python.yml description: The YAML configuration file controlling folders, module selection, configure flags, cleanup, and per-module overrides — with platform-specific sections. tags: [configuration, yaml, config] -timestamp: 2026-06-23T00:00:00Z +timestamp: 2026-12-03T00:00:00Z --- # portable-python.yml @@ -26,6 +26,7 @@ portable-python is configured via a YAML file — by default `portable-python.ym | `cpython-additional-packages` | list | Extra pip packages to install into the build. | | `cpython-use-github` | bool | Fetch the available version list from GitHub tags instead of python.org. | | `include` | path | Layer another config file (a leading `+` puts it in front). | +| `allow-homebrew` | bool | Keep `/opt/homebrew` folders in the `PATH` used to compile modules (removed by default, to reduce the chances of linking against homebrew libraries on macOS). | ## `folders` diff --git a/docs/log.md b/docs/log.md index 86e5a7e..b14b155 100644 --- a/docs/log.md +++ b/docs/log.md @@ -2,6 +2,7 @@ ## 2026-12-03 +* **Update**: [Configuration](/configuration/portable-python-yml.md): documented `allow-homebrew`. * **Update**: [Cpython](/architecture/cpython.md): `sysconfig` refers to the C++ compiler by name rather than by its build host path, and compiler wrappers recorded in `sysconfig` are reported with a warning. ## 2026-10-09 diff --git a/src/portable_python/__init__.py b/src/portable_python/__init__.py index ef8ee3c..0821495 100644 --- a/src/portable_python/__init__.py +++ b/src/portable_python/__init__.py @@ -597,10 +597,15 @@ def xenv_LDFLAGS(self): yield from (f"-L{lib_dir}" for lib_dir in self.deps_lib_dirs) def xenv_PATH(self): - yield f"{self.deps}/bin" - yield from os.environ.get("PATH", "").split(":") - yield "/usr/bin" - yield "/bin" + paths = [f"{self.deps}/bin", *os.environ.get("PATH", "").split(os.pathsep), "/usr/bin", "/bin"] + if not PPG.config.get_value("allow-homebrew"): + # Remove any mention of /opt/homebrew from PATH (reduce chances of dynamic links to homebrew) + revised = [x for x in paths if not x.startswith("/opt/homebrew")] + if revised != paths: + LOG.info("Removed /opt/homebrew mentions from PATH") + paths = revised + + yield from paths def xenv_LD_LIBRARY_PATH(self): yield from os.environ.get("LD_LIBRARY_PATH", "").split(":") @@ -706,16 +711,6 @@ def compile(self): runez.decompress(path, self.m_src_build, simplify=True) env_vars = self._get_env_vars() - if not PPG.config.get_value("allow-homebrew"): - # Remove any mention of /opt/homebrew from PATH (reduce chances of dynamic links to homebrew) - path_env_var = env_vars.get("PATH") - if path_env_var: - _paths = os.environ.get("PATH", "").split(":") - _revised = [p for p in _paths if not p.startswith("/opt/homebrew")] - if _revised != _paths: - LOG.info("Removed /opt/homebrew mentions from PATH") - env_vars["PATH"] = runez.joined(_revised, delimiter=":") - prev_env_vars = {} for var_name, value in env_vars.items(): LOG.info("env %s=%s", var_name, runez.short(value, size=2048)) diff --git a/tests/test_build.py b/tests/test_build.py index 6ec1678..be8c650 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -147,7 +147,7 @@ def test_finalization(cli, monkeypatch): """ -def testgroom_makefile_compilers(temp_folder, logged, monkeypatch): +def test_groom_makefile_compilers(temp_folder, logged, monkeypatch): PPG.grab_config(target="linux-x86_64") python_builder = BuildSetup(required_python_spec("3.14.6")).python_builder assert isinstance(python_builder, Cpython) @@ -182,3 +182,18 @@ def testgroom_makefile_compilers(temp_folder, logged, monkeypatch): python_builder.groom_makefile_compilers() assert f"sysconfig will record compiler wrapper 'CXX={wrapper}'" in logged.pop() assert list(runez.readlines("Makefile"))[2] == f"CXX=\t\t{wrapper}" # User provided CXX is not modified + + +def test_path_homebrew(cli, monkeypatch): + monkeypatch.setenv("PATH", "/opt/homebrew/bin:/usr/local/bin:/opt/homebrew/sbin") + cli.run("-n", "-tmacos-arm64", "build", "3.14.4", "-mxz") + assert cli.succeeded + assert "Removed /opt/homebrew mentions from PATH" in cli.logged + # Folder where external modules install their binaries is still first in PATH, followed by the /usr/bin:/bin fallback + assert "env PATH=build/deps/bin:/usr/local/bin:/usr/bin:/bin\n" in cli.logged + + runez.write("pp.yml", "allow-homebrew: true", logger=None) + cli.run("-n", "-tmacos-arm64", "-cpp.yml", "build", "3.14.4", "-mxz") + assert cli.succeeded + assert "Removed /opt/homebrew" not in cli.logged + assert "env PATH=build/deps/bin:/opt/homebrew/bin:/usr/local/bin:/opt/homebrew/sbin:/usr/bin:/bin\n" in cli.logged