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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
python-version: "3.14"

- uses: astral-sh/setup-uv@v10.3.0
- uses: astral-sh/setup-uv@v10.4.2
- run: uvx --with tox-uv tox -e py,style,ty,pyrefly,pyright,mypy,zuban
- run: uv build
- name: Publish to PyPI
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- uses: astral-sh/setup-uv@v10.3.0
- uses: astral-sh/setup-uv@v10.4.2
- run: uvx --with tox-uv tox -e py

- uses: coverallsapp/github-action@v2
Expand Down Expand Up @@ -55,5 +55,5 @@ jobs:
with:
python-version: "3.14"

- uses: astral-sh/setup-uv@v10.3.0
- uses: astral-sh/setup-uv@v10.4.2
- run: uvx --with tox-uv tox -e style,ty,pyrefly,pyright,mypy,zuban
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## v2.2.0

### Fixed

- `sysconfig` refers to the C++ compiler by name (`CXX`, `LDCXXSHARED`), as it does for the C compiler, instead of by the build host path where `./configure` found it. Since python 3.14.6, that path could be a build-host-only wrapper such as `/usr/lib/ccache/g++`, making C++ extension builds fail on hosts without it. A compiler wrapper (`ccache`, `sccache`, `distcc`) explicitly configured into `sysconfig` is reported with a warning.

### Bundled components

| Component | Version | Why |
|-----------|---------|-----|
| OpenSSL | 3.5.9 → 3.5.10 | Security patch release, staying on the 3.5 LTS line |
| libffi | 3.8.0 → 3.8.2 | Patch releases with security fixes |
| xz | 5.8.4 → 5.8.5 | Security fixes |
| SQLite | 3.53.4 → 3.54.1 | New line, now past its `.0` |
| zlib | 1.3.2 → 1.4 | Several CVE fixes, breaking changes affect CMake/MSVC/Cygwin builds only |
| zstd | 1.5.7 → 1.6.0 | CVE fix release, "highly recommended" upstream |

These match [python-build-standalone](https://github.com/astral-sh/python-build-standalone)'s current choices, including the move to the zlib 1.4 and zstd 1.6.0 lines, except xz (5.8.5 is a security release newer than theirs).
Every other component was re-checked against upstream: already current, or deliberately held back (see the `version` property comments).

### Changed

- Library use: `ModuleBuilder.version` is now always a `Version` (external modules used to report a `str`)

_Also: refreshed the dependency lock, bumped `astral-sh/setup-uv` in CI._

## v2.1.0

- portable-python's code is now checked by multiple type checkers on every change
Expand Down
7 changes: 6 additions & 1 deletion docs/architecture/cpython.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: Class
title: Cpython
description: The concrete PythonBuilder that compiles CPython — configure/make/install, optimization flags, and the finalize step that makes the install relocatable.
tags: [class, cpython, build, finalize]
timestamp: 2026-06-23T00:00:00Z
timestamp: 2026-12-03T00:00:00Z
---

# Cpython
Expand All @@ -14,6 +14,11 @@ The concrete [`PythonBuilder`](/architecture/python-builder.md) that compiles CP

CPython is configured purely through flags — never source patches (the [no-patches principle](/overview.md)). Defaults come from `cpython-configure` in [config](/configuration/portable-python-yml.md) (optimizations, LTO, ensurepip), plus computed flags that point the build at the statically-compiled [deps](/concepts/static-linking.md).

Right after `./configure`, the compiler commands it recorded in the generated `Makefile` (which become `sysconfig`'s `CC`, `CXX`, `LDSHARED`, `LDCXXSHARED`, used to build extensions on the user's machine) are groomed:

- `./configure` looks up the C++ compiler on `PATH`, so a missing one is noticed at configure time, and records it by the absolute path where it found it. That path is specific to the build host: for example `/usr/lib/ccache/g++` when a compiler cache masquerade folder is first on `PATH`. A portable python builds extensions on other hosts, so `CXX` refers to the compiler by name instead (as `CC` does), to be found on that host's `PATH`. The build is unchanged: on the build host, that name resolves to the same path, ccache included. A `CXX` set by the user is left alone.
- A compiler wrapper (`ccache`, `sccache`, `distcc`) that still ends up in `sysconfig`, for example via an explicit `CC="ccache gcc"`, is reported with a warning.

## Finalize — making it relocatable

After `make install`, a portable build's interpreter still thinks it lives at the placeholder [`/ppp-marker/{version}`](/concepts/ppp-marker.md). Finalizing turns it into a [portable](/concepts/portability.md) install:
Expand Down
4 changes: 4 additions & 0 deletions docs/log.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Knowledge Bundle Update Log

## 2026-12-03

* **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

* **Update**: [Configuration](/configuration/portable-python-yml.md): `{module}-configure` substitutes `$lib_dir` and `$lib64_dir` (not `$deps_lib`), and its value is split into separate args.
Expand Down
22 changes: 12 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --universal -o requirements.txt --python-version 3.10 --group dev
certifi==2026.10.19
certifi==2026.11.20
# via requests
charset-normalizer==3.5.2
charset-normalizer==3.5.3
# via requests
click==8.5.0
click==8.5.1
# via portable-python (pyproject.toml)
colorama==0.4.6 ; sys_platform == 'win32'
# via pytest
coverage==7.16.2
coverage==7.16.2 ; python_full_version < '3.11'
# via pytest-cov
exceptiongroup==1.3.1 ; python_full_version < '3.11'
coverage==7.18.0 ; python_full_version >= '3.11'
# via pytest-cov
exceptiongroup==1.3.2 ; python_full_version < '3.11'
# via pytest
idna==3.20
# via requests
iniconfig==2.3.1
# via pytest
packaging==26.3
packaging==26.4
# via pytest
pluggy==1.7.0
# via
# pytest
# pytest-cov
pygments==2.21.0
# via pytest
pytest==9.1.1
pytest==9.2.0
# via pytest-cov
pytest-cov==7.1.0
# via portable-python (pyproject.toml:dev)
pyyaml==6.0.3
pyyaml==6.0.4
# via portable-python (pyproject.toml)
requests==2.34.2
# via portable-python (pyproject.toml)
runez==5.11.1
runez==5.11.3
# via portable-python (pyproject.toml)
tomli==2.5.0 ; python_full_version <= '3.11'
tomli==2.5.0 ; python_full_version < '3.11'
# via
# coverage
# pytest
Expand Down
20 changes: 10 additions & 10 deletions src/portable_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import runez
from runez.http import RestClient
from runez.pyenv import PythonSpec
from runez.pyenv import PythonSpec, Version
from runez.render import Header, PrettyTable

from portable_python.versions import PPG
Expand Down Expand Up @@ -506,8 +506,9 @@ def is_usable_module(self, name):
"""Is module with name either selected or usable as a shared lib, as determined via its telltale"""
return self.modules.is_usable_module(name)

def cfg_version(self, default):
return PPG.config.get_value("%s-version" % self.m_name) or default
def cfg_version(self, default: str) -> Version:
# str(): a version in yaml config may have been parsed as a float (eg: `gdbm-version: 1.26`)
return Version(str(PPG.config.get_value("%s-version" % self.m_name) or default))

def cfg_http_headers(self):
if config_http_headers := PPG.config.get_value("%s-http-headers" % self.m_name):
Expand Down Expand Up @@ -554,9 +555,12 @@ def src_suffix(self):
return self.cfg_src_suffix()

@property
def version(self):
"""Version to use"""
return self.parent_module and self.parent_module.version
def version(self) -> Version:
"""Version to use, sub-modules (such as tcl/tk/tix) share the version of their parent module by default"""
if self.parent_module is None:
return self.setup.python_spec.version # Top of the module tree: the python being built

return self.parent_module.version

@property
def deps(self):
Expand Down Expand Up @@ -822,10 +826,6 @@ def bin_python(self) -> pathlib.Path:

return self._bin_python

@property
def version(self):
return self.setup.python_spec.version

def xenv_LDFLAGS(self):
"""Python builder does not reuse the common setting"""
yield from ()
Expand Down
52 changes: 50 additions & 2 deletions src/portable_python/cpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import datetime
import os
import re
import shutil

import runez
import yaml
from runez.pyenv import Version

from portable_python import LOG, patch_file, patch_folder, PPG, PythonBuilder
from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Mpdec, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd
Expand All @@ -20,6 +20,11 @@
test_struct test_threading test_time test_traceback test_unicode
"""

# Compiler commands that ./configure records in the Makefile end up in sysconfig, and are used to build C/C++ extensions
RX_MAKEFILE_COMPILER = re.compile(r"^(CC|CXX|LDSHARED|LDCXXSHARED)=[ \t]*(.*?)[ \t]*$", flags=re.MULTILINE)
# Compiler wrappers that may exist on the build host only, recording them in sysconfig is worth a warning
RX_COMPILER_WRAPPER = re.compile(r"\b(ccache|sccache|distcc)\b")


def represented_yaml(key_value_pairs):
"""
Expand Down Expand Up @@ -164,7 +169,7 @@ def c_configure_args(self):
tkinter = self.active_module(TkInter)
if tkinter:
# TODO: this doesn't seem to be enough, on macos cpython's ./configure still picks up the shared macos tcl/tk libs
version = Version(tkinter.version)
version = tkinter.version
yield f"--with-tcltk-includes=-I{self.deps}/include"

lib_dir_flags = " ".join(f"-L{lib_dir}" for lib_dir in self.deps_lib_dirs)
Expand Down Expand Up @@ -246,6 +251,7 @@ def _prepare(self):

def _do_linux_compile(self):
self.run_configure("./configure", self.c_configure_args(), prefix=self.c_configure_prefix)
self.groom_makefile_compilers()
make_args = []
if self.version < "3.8":
pgo_tests = runez.joined(runez.flattened(PGO_TESTS, split=True))
Expand All @@ -255,6 +261,48 @@ def _do_linux_compile(self):
# Don't parallelize `make install`, see https://github.com/python/cpython/issues/109796
self.run_make("install", f"DESTDIR={self.destdir}")

def groom_makefile_compilers(self):
"""
Keep the compiler commands that end up in sysconfig usable on hosts other than the build host.

./configure looks up the C++ compiler on PATH (so that a missing one is noticed at configure time),
and records it by the absolute path where it found it, a path that is specific to the build host.
For example `/usr/lib/ccache/g++`, when a compiler cache masquerade folder is first on PATH.
A portable python builds extensions on other hosts: refer to the compiler by name (as for the C compiler),
to be found on that host's PATH. The build is unchanged: on the build host, that name resolves to the same path.
A `CXX` explicitly provided by the user is left alone.
"""
makefile = "Makefile"
if not os.path.exists(makefile):
return # Not configured (dryrun mode)

with open(makefile) as fh:
compilers = dict(RX_MAKEFILE_COMPILER.findall(fh.read()))

cxx = compilers.get("CXX")
if cxx and not self._is_cxx_preset():
program, _, flags = cxx.partition(" ")
bare_name = os.path.basename(program)
if program != bare_name and shutil.which(bare_name) == program:
# Makefile.pre first: Makefile is generated from it, and must not end up older than it
for path in ("Makefile.pre", makefile):
patch_file(path, rf"^(CXX=[ \t]*){re.escape(program)}(?=[ \t]|$)", rf"\g<1>{bare_name}")

compilers["CXX"] = runez.joined(bare_name, flags)

for name, command in sorted(compilers.items()):
if RX_COMPILER_WRAPPER.search(command):
LOG.warning(
"sysconfig will record compiler wrapper '%s=%s', extensions won't build on hosts without it"
" (a wrapper masquerade folder on PATH applies to the build only)",
name,
command,
)

def _is_cxx_preset(self):
"""Did the user explicitly provide which C++ compiler to use? (via env var, or `CXX=` in `cpython-configure`)"""
return bool(os.environ.get("CXX")) or any(x.startswith("CXX=") for x in self.c_configure_args_from_config)

def _finalize(self):
is_shared = self.setup.prefix or self.has_configure_opt("--enable-shared", "yes")
if is_shared:
Expand Down
25 changes: 16 additions & 9 deletions src/portable_python/external/xcpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ def url(self):
@property
def version(self):
# python-build-standalone moved from 3.4.8 straight to 3.8.0 in Oct 2026 (their PR #1302), follow their lead
# 3.8.x patch releases carry security fixes (3.8.2: GHSA advisories), keep current within the line
# Check https://github.com/libffi/libffi/releases
return self.cfg_version("3.8.0")
return self.cfg_version("3.8.2")

def c_configure_args(self):
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
Expand Down Expand Up @@ -170,9 +171,9 @@ def auto_select_reason(self):

@property
def url(self):
if self.version and self.version.startswith("1.1.1"):
if self.version.text.startswith("1.1.1"):
# Not sure why URL suddenly changed for this on github...
vfolder = self.version.replace(".", "_")
vfolder = self.version.text.replace(".", "_")
return (
self.cfg_url(self.version)
or f"https://github.com/openssl/openssl/releases/download/OpenSSL_{vfolder}/openssl-{self.version}.tar.gz"
Expand All @@ -186,7 +187,7 @@ def version(self):
# Stay on the 3.5 LTS line: 3.6.x and 4.0.x have shipped but are not verified for cpython builds
# (python-build-standalone pins 3.5.x as well)
# Check https://github.com/openssl/openssl/releases and https://endoflife.date/openssl
return self.cfg_version("3.5.9")
return self.cfg_version("3.5.10")

def c_configure_args(self):
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
Expand Down Expand Up @@ -320,9 +321,10 @@ def url(self):

@property
def version(self):
# 3.53.x gets frequent fix-only releases, keep current within the line
# Fix-only releases are frequent within a line, keep current; move to a new line once its .1 is out
# (3.54.1, also used by python-build-standalone)
# Check https://sqlite.org/changes.html (avoid withdrawn releases like 3.52.0)
return self.cfg_version("3.53.4")
return self.cfg_version("3.54.1")

def c_configure_args(self):
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
Expand Down Expand Up @@ -389,8 +391,9 @@ def url(self):

@property
def version(self):
# 5.8.x patch releases carry security fixes (5.8.5), keep current within the line
# Check https://github.com/tukaani-project/xz/releases
return self.cfg_version("5.8.4")
return self.cfg_version("5.8.5")

def c_configure_args(self):
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
Expand Down Expand Up @@ -433,8 +436,10 @@ def url(self):

@property
def version(self):
# 1.4 fixes several CVEs, its breaking changes are CMake/MSVC/Cygwin only (we use ./configure)
# python-build-standalone moved to 1.4 as well
# Check https://zlib.net/ and https://github.com/madler/zlib/releases
return self.cfg_version("1.3.2")
return self.cfg_version("1.4")

def c_configure_args(self):
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
Expand Down Expand Up @@ -474,8 +479,10 @@ def url(self):

@property
def version(self):
# 1.6.0 was released early as a CVE fix (CVE-2026-124851), upstream "highly recommends" it
# python-build-standalone moved to 1.6.0 as well
# Check https://github.com/facebook/zstd/releases
return self.cfg_version("1.5.7")
return self.cfg_version("1.6.0")

def _do_linux_compile(self):
# Notably, this does not build when given a relative path.
Expand Down
Loading