Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration/portable-python-yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`

Expand Down
1 change: 1 addition & 0 deletions docs/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions src/portable_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(":")
Expand Down Expand Up @@ -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))
Expand Down
17 changes: 16 additions & 1 deletion tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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