portable-python 2.0.2__py3-none-any.whl → 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,10 @@ import configparser
2
2
  import datetime
3
3
  import os
4
4
  import re
5
+ import shutil
5
6
 
6
7
  import runez
7
8
  import yaml
8
- from runez.pyenv import Version
9
9
 
10
10
  from portable_python import LOG, patch_file, patch_folder, PPG, PythonBuilder
11
11
  from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Mpdec, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd
@@ -20,6 +20,11 @@ test_hashlib test_io test_iter test_json test_long test_math test_memoryview tes
20
20
  test_struct test_threading test_time test_traceback test_unicode
21
21
  """
22
22
 
23
+ # Compiler commands that ./configure records in the Makefile end up in sysconfig, and are used to build C/C++ extensions
24
+ RX_MAKEFILE_COMPILER = re.compile(r"^(CC|CXX|LDSHARED|LDCXXSHARED)=[ \t]*(.*?)[ \t]*$", flags=re.MULTILINE)
25
+ # Compiler wrappers that may exist on the build host only, recording them in sysconfig is worth a warning
26
+ RX_COMPILER_WRAPPER = re.compile(r"\b(ccache|sccache|distcc)\b")
27
+
23
28
 
24
29
  def represented_yaml(key_value_pairs):
25
30
  """
@@ -79,7 +84,7 @@ class Cpython(PythonBuilder):
79
84
  "host-platform": runez.SYS_INFO.platform_info,
80
85
  "ldd-version": PythonInspector.tool_version("ldd"),
81
86
  "portable-python-version": runez.get_version(__package__),
82
- "special-context": bc.isolate_usr_local and bc,
87
+ "special-context": bc.isolate_usr_local if bc else None,
83
88
  },
84
89
  )
85
90
  additional = PPG.config.get_value("manifest", "additional-info")
@@ -164,7 +169,7 @@ class Cpython(PythonBuilder):
164
169
  tkinter = self.active_module(TkInter)
165
170
  if tkinter:
166
171
  # TODO: this doesn't seem to be enough, on macos cpython's ./configure still picks up the shared macos tcl/tk libs
167
- version = Version(tkinter.version)
172
+ version = tkinter.version
168
173
  yield f"--with-tcltk-includes=-I{self.deps}/include"
169
174
 
170
175
  lib_dir_flags = " ".join(f"-L{lib_dir}" for lib_dir in self.deps_lib_dirs)
@@ -188,7 +193,7 @@ class Cpython(PythonBuilder):
188
193
  yield f"{self.deps_lib_dir}/libzstd.a"
189
194
 
190
195
  def xenv_LIBMPDEC_CFLAGS(self):
191
- if self.version >= "3.14" and PPG.target.is_macos:
196
+ if self.version >= "3.14" and PPG.target.is_macos and self.active_module(Mpdec):
192
197
  # Normally ./configure will autodetect using pkg-config, but
193
198
  # this doesn't typically work on Mac (the pkg-config binary is
194
199
  # in homebrew, which we omit from path) so we have to provide
@@ -196,7 +201,7 @@ class Cpython(PythonBuilder):
196
201
  yield f"-I{self.deps}/include"
197
202
 
198
203
  def xenv_LIBMPDEC_LIBS(self):
199
- if self.version >= "3.14" and PPG.target.is_macos:
204
+ if self.version >= "3.14" and PPG.target.is_macos and self.active_module(Mpdec):
200
205
  yield f"{self.deps_lib_dir}/libmpdec.a"
201
206
 
202
207
  def xenv_LIBREADLINE_LIBS(self):
@@ -246,6 +251,7 @@ class Cpython(PythonBuilder):
246
251
 
247
252
  def _do_linux_compile(self):
248
253
  self.run_configure("./configure", self.c_configure_args(), prefix=self.c_configure_prefix)
254
+ self.groom_makefile_compilers()
249
255
  make_args = []
250
256
  if self.version < "3.8":
251
257
  pgo_tests = runez.joined(runez.flattened(PGO_TESTS, split=True))
@@ -255,6 +261,48 @@ class Cpython(PythonBuilder):
255
261
  # Don't parallelize `make install`, see https://github.com/python/cpython/issues/109796
256
262
  self.run_make("install", f"DESTDIR={self.destdir}")
257
263
 
264
+ def groom_makefile_compilers(self):
265
+ """
266
+ Keep the compiler commands that end up in sysconfig usable on hosts other than the build host.
267
+
268
+ ./configure looks up the C++ compiler on PATH (so that a missing one is noticed at configure time),
269
+ and records it by the absolute path where it found it, a path that is specific to the build host.
270
+ For example `/usr/lib/ccache/g++`, when a compiler cache masquerade folder is first on PATH.
271
+ A portable python builds extensions on other hosts: refer to the compiler by name (as for the C compiler),
272
+ to be found on that host's PATH. The build is unchanged: on the build host, that name resolves to the same path.
273
+ A `CXX` explicitly provided by the user is left alone.
274
+ """
275
+ makefile = "Makefile"
276
+ if not os.path.exists(makefile):
277
+ return # Not configured (dryrun mode)
278
+
279
+ with open(makefile) as fh:
280
+ compilers = dict(RX_MAKEFILE_COMPILER.findall(fh.read()))
281
+
282
+ cxx = compilers.get("CXX")
283
+ if cxx and not self._is_cxx_preset():
284
+ program, _, flags = cxx.partition(" ")
285
+ bare_name = os.path.basename(program)
286
+ if program != bare_name and shutil.which(bare_name) == program:
287
+ # Makefile.pre first: Makefile is generated from it, and must not end up older than it
288
+ for path in ("Makefile.pre", makefile):
289
+ patch_file(path, rf"^(CXX=[ \t]*){re.escape(program)}(?=[ \t]|$)", rf"\g<1>{bare_name}")
290
+
291
+ compilers["CXX"] = runez.joined(bare_name, flags)
292
+
293
+ for name, command in sorted(compilers.items()):
294
+ if RX_COMPILER_WRAPPER.search(command):
295
+ LOG.warning(
296
+ "sysconfig will record compiler wrapper '%s=%s', extensions won't build on hosts without it"
297
+ " (a wrapper masquerade folder on PATH applies to the build only)",
298
+ name,
299
+ command,
300
+ )
301
+
302
+ def _is_cxx_preset(self):
303
+ """Did the user explicitly provide which C++ compiler to use? (via env var, or `CXX=` in `cpython-configure`)"""
304
+ return bool(os.environ.get("CXX")) or any(x.startswith("CXX=") for x in self.c_configure_args_from_config)
305
+
258
306
  def _finalize(self):
259
307
  is_shared = self.setup.prefix or self.has_configure_opt("--enable-shared", "yes")
260
308
  if is_shared:
@@ -280,7 +328,6 @@ class Cpython(PythonBuilder):
280
328
 
281
329
  self.run_python("-mpip", "install", "--no-cache-dir", "--upgrade", *runez.flattened(additional))
282
330
 
283
- runez.abort_if(not runez.DRYRUN and not self.bin_python, f"Can't find bin/python in {self.bin_folder}")
284
331
  PPG.config.ensure_main_file_symlinks(self)
285
332
  if not self.setup.prefix:
286
333
  self._relativize_sysconfig()
@@ -305,7 +352,7 @@ class Cpython(PythonBuilder):
305
352
 
306
353
  info_path = PPG.config.get_value("manifest", "inspection-report")
307
354
  if info_path:
308
- with runez.colors.ActivateColors(enable=False):
355
+ with runez.ActivateColors(enable=False):
309
356
  py_inspector = PythonInspector(self.install_folder, modules="all")
310
357
  contents = "%s\n" % py_inspector.represented(verbose=True)
311
358
  runez.write(self.install_folder / info_path, contents)
@@ -340,7 +387,7 @@ class Cpython(PythonBuilder):
340
387
 
341
388
  def _relativize_shebangs(self):
342
389
  """Autocorrect shebangs in bin/ folder, making them relative to the location of the python executable"""
343
- for folder in (self.bin_folder, self.prefix_config_folder):
390
+ for folder in filter(None, (self.bin_folder, self.prefix_config_folder)):
344
391
  for path in runez.ls_dir(folder):
345
392
  if path != self.bin_python and runez.is_executable(path) and not path.is_symlink():
346
393
  self._relativize_shebang_file(path)
@@ -405,11 +452,10 @@ class Cpython(PythonBuilder):
405
452
  except UnicodeError:
406
453
  return
407
454
 
408
- if lines:
409
- LOG.info("Auto-corrected shebang for %s" % runez.short(path))
455
+ if lines and not runez.log.hdry(f"auto-correct shebang for {runez.short(path)}"):
456
+ LOG.info("Auto-corrected shebang for %s", runez.short(path))
410
457
  with open(path, "w") as fh:
411
- for line in lines:
412
- fh.write(line)
458
+ fh.writelines(lines)
413
459
 
414
460
 
415
461
  class RelSysConf:
@@ -10,8 +10,9 @@ class GettextTiny(ModuleBuilder):
10
10
 
11
11
  @property
12
12
  def version(self):
13
+ # Small, dormant project (0.3.3 released Jan 2026), bump freely within the 0.3 line
13
14
  # Check https://github.com/sabotage-linux/gettext-tiny/releases
14
- return self.cfg_version("0.3.2")
15
+ return self.cfg_version("0.3.3")
15
16
 
16
17
  def _do_linux_compile(self):
17
18
  self.run_make("LIBINTL=NOOP")
@@ -1,5 +1,4 @@
1
1
  import os.path
2
- from typing import ClassVar
3
2
 
4
3
  import runez
5
4
 
@@ -32,7 +31,7 @@ class Bdb(ModuleBuilder):
32
31
 
33
32
  def c_configure_args(self):
34
33
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
35
- yield config_args
34
+ yield from config_args
36
35
 
37
36
  else:
38
37
  yield "--enable-shared=no"
@@ -81,7 +80,7 @@ class Gdbm(ModuleBuilder):
81
80
  """
82
81
 
83
82
  m_debian = "libgdbm-dev"
84
- m_telltale: ClassVar[list] = ["{include}/gdbm.h"]
83
+ m_telltale = "{include}/gdbm.h"
85
84
 
86
85
  @property
87
86
  def url(self):
@@ -94,7 +93,7 @@ class Gdbm(ModuleBuilder):
94
93
 
95
94
  def c_configure_args(self):
96
95
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
97
- yield config_args
96
+ yield from config_args
98
97
 
99
98
  else:
100
99
  yield "--enable-shared=no"
@@ -124,7 +123,7 @@ class LibFFI(ModuleBuilder):
124
123
  """
125
124
 
126
125
  m_debian = "!libffi-dev"
127
- m_telltale: ClassVar[list] = ["{include}/ffi.h", "{include}/ffi/ffi.h"]
126
+ m_telltale = "{include}/ffi.h {include}/ffi/ffi.h"
128
127
 
129
128
  xenv_CFLAGS = "-fPIC"
130
129
 
@@ -136,12 +135,14 @@ class LibFFI(ModuleBuilder):
136
135
 
137
136
  @property
138
137
  def version(self):
138
+ # python-build-standalone moved from 3.4.8 straight to 3.8.0 in Oct 2026 (their PR #1302), follow their lead
139
+ # 3.8.x patch releases carry security fixes (3.8.2: GHSA advisories), keep current within the line
139
140
  # Check https://github.com/libffi/libffi/releases
140
- return self.cfg_version("3.5.2")
141
+ return self.cfg_version("3.8.2")
141
142
 
142
143
  def c_configure_args(self):
143
144
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
144
- yield config_args
145
+ yield from config_args
145
146
 
146
147
  else:
147
148
  yield "--enable-shared=no"
@@ -170,9 +171,9 @@ class Openssl(ModuleBuilder):
170
171
 
171
172
  @property
172
173
  def url(self):
173
- if self.version and self.version.startswith("1.1.1"):
174
+ if self.version.text.startswith("1.1.1"):
174
175
  # Not sure why URL suddenly changed for this on github...
175
- vfolder = self.version.replace(".", "_")
176
+ vfolder = self.version.text.replace(".", "_")
176
177
  return (
177
178
  self.cfg_url(self.version)
178
179
  or f"https://github.com/openssl/openssl/releases/download/OpenSSL_{vfolder}/openssl-{self.version}.tar.gz"
@@ -183,13 +184,14 @@ class Openssl(ModuleBuilder):
183
184
  @property
184
185
  def version(self):
185
186
  # 3.5 is LTS, supported until Apr 2030 (3.0 EOL Sept 2026)
186
- # Stay on the 3.5 LTS line for now: 3.6 / 4.0 not yet verified for cpython builds
187
+ # Stay on the 3.5 LTS line: 3.6.x and 4.0.x have shipped but are not verified for cpython builds
188
+ # (python-build-standalone pins 3.5.x as well)
187
189
  # Check https://github.com/openssl/openssl/releases and https://endoflife.date/openssl
188
- return self.cfg_version("3.5.7")
190
+ return self.cfg_version("3.5.10")
189
191
 
190
192
  def c_configure_args(self):
191
193
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
192
- yield config_args
194
+ yield from config_args
193
195
 
194
196
  else:
195
197
  yield "-v"
@@ -219,7 +221,7 @@ class Ncurses(ModuleBuilder):
219
221
 
220
222
  def c_configure_args(self):
221
223
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
222
- yield config_args
224
+ yield from config_args
223
225
 
224
226
  else:
225
227
  yield "--disable-shared"
@@ -273,12 +275,13 @@ class Readline(ModuleBuilder):
273
275
  @property
274
276
  def version(self):
275
277
  # Patched tarballs (e.g. "8.2.13") are available on the GNU FTP when patches accumulate
278
+ # 8.3 has official patches 001-003 pending, not rolled up yet: watch for a readline-8.3.x tarball
276
279
  # Check https://ftpmirror.gnu.org/gnu/readline/ for available tarballs
277
280
  return self.cfg_version("8.3")
278
281
 
279
282
  def c_configure_args(self):
280
283
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
281
- yield config_args
284
+ yield from config_args
282
285
 
283
286
  else:
284
287
  yield "--enable-shared=no"
@@ -302,7 +305,7 @@ class Sqlite(ModuleBuilder):
302
305
  """
303
306
 
304
307
  m_debian = "+libsqlite3-dev"
305
- m_telltale: ClassVar[list] = ["{include}/sqlite3.h"]
308
+ m_telltale = "{include}/sqlite3.h"
306
309
 
307
310
  xenv_CFLAGS = "-fPIC"
308
311
 
@@ -318,12 +321,14 @@ class Sqlite(ModuleBuilder):
318
321
 
319
322
  @property
320
323
  def version(self):
321
- # Keep current; check https://sqlite.org/changes.html (avoid withdrawn releases like 3.52.0)
322
- return self.cfg_version("3.53.2")
324
+ # Fix-only releases are frequent within a line, keep current; move to a new line once its .1 is out
325
+ # (3.54.1, also used by python-build-standalone)
326
+ # Check https://sqlite.org/changes.html (avoid withdrawn releases like 3.52.0)
327
+ return self.cfg_version("3.54.1")
323
328
 
324
329
  def c_configure_args(self):
325
330
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
326
- yield config_args
331
+ yield from config_args
327
332
 
328
333
  else:
329
334
  yield "--disable-shared"
@@ -344,7 +349,7 @@ class Uuid(ModuleBuilder):
344
349
 
345
350
  m_debian = "+uuid-dev"
346
351
  m_include = "uuid"
347
- m_telltale: ClassVar[list] = ["{include}/uuid/uuid.h"]
352
+ m_telltale = "{include}/uuid/uuid.h"
348
353
 
349
354
  xenv_CFLAGS = "-fPIC"
350
355
 
@@ -360,7 +365,7 @@ class Uuid(ModuleBuilder):
360
365
 
361
366
  def c_configure_args(self):
362
367
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
363
- yield config_args
368
+ yield from config_args
364
369
 
365
370
  else:
366
371
  yield "--enable-shared=no"
@@ -386,12 +391,13 @@ class Xz(ModuleBuilder):
386
391
 
387
392
  @property
388
393
  def version(self):
394
+ # 5.8.x patch releases carry security fixes (5.8.5), keep current within the line
389
395
  # Check https://github.com/tukaani-project/xz/releases
390
- return self.cfg_version("5.8.3")
396
+ return self.cfg_version("5.8.5")
391
397
 
392
398
  def c_configure_args(self):
393
399
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
394
- yield config_args
400
+ yield from config_args
395
401
 
396
402
  else:
397
403
  yield "--enable-shared=no"
@@ -430,12 +436,14 @@ class Zlib(ModuleBuilder):
430
436
 
431
437
  @property
432
438
  def version(self):
439
+ # 1.4 fixes several CVEs, its breaking changes are CMake/MSVC/Cygwin only (we use ./configure)
440
+ # python-build-standalone moved to 1.4 as well
433
441
  # Check https://zlib.net/ and https://github.com/madler/zlib/releases
434
- return self.cfg_version("1.3.2")
442
+ return self.cfg_version("1.4")
435
443
 
436
444
  def c_configure_args(self):
437
445
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
438
- yield config_args
446
+ yield from config_args
439
447
 
440
448
  else:
441
449
  yield "--static"
@@ -471,8 +479,10 @@ class Zstd(ModuleBuilder):
471
479
 
472
480
  @property
473
481
  def version(self):
482
+ # 1.6.0 was released early as a CVE fix (CVE-2026-124851), upstream "highly recommends" it
483
+ # python-build-standalone moved to 1.6.0 as well
474
484
  # Check https://github.com/facebook/zstd/releases
475
- return self.cfg_version("1.5.7")
485
+ return self.cfg_version("1.6.0")
476
486
 
477
487
  def _do_linux_compile(self):
478
488
  # Notably, this does not build when given a relative path.
@@ -485,7 +495,8 @@ class Zstd(ModuleBuilder):
485
495
 
486
496
  class Mpdec(ModuleBuilder):
487
497
  """
488
- Prevent falling back to bundled libmpdec (deprecated and scheduled for removal in Python 3.16)
498
+ Since 3.15 (gh-115119), cpython no longer falls back to its bundled libmpdec: without one, `_decimal` is silently skipped
499
+ 3.14 still falls back, but to a deprecated (and older) bundled copy, so we build it there too
489
500
  """
490
501
 
491
502
  m_debian = "!libmpdec-dev"
@@ -494,11 +505,11 @@ class Mpdec(ModuleBuilder):
494
505
  xenv_CFLAGS = "-fPIC"
495
506
 
496
507
  def auto_select_reason(self):
497
- if self.setup.python_spec.version >= "3.16":
508
+ if self.setup.python_spec.version >= "3.14":
498
509
  if PPG.target.is_macos:
499
- return "Required for 3.16 and up"
510
+ return "Required for 3.14 and up"
500
511
  if not self.resolved_telltale:
501
- return "Required for 3.16 and up"
512
+ return "Required for 3.14 and up"
502
513
 
503
514
  @property
504
515
  def url(self):
@@ -511,10 +522,11 @@ class Mpdec(ModuleBuilder):
511
522
 
512
523
  def c_configure_args(self):
513
524
  if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
514
- yield config_args
525
+ yield from config_args
515
526
 
516
527
  else:
517
- pass # yield "--static"
528
+ yield "--disable-shared"
529
+
518
530
  yield "--disable-cxx"
519
531
 
520
532
  def _do_linux_compile(self):
@@ -5,8 +5,6 @@ It is also unclear what version to use, which build docs to follow etc.
5
5
  Contributions are welcome!
6
6
  """
7
7
 
8
- from typing import ClassVar
9
-
10
8
  import runez
11
9
 
12
10
  from portable_python import ModuleBuilder, PPG
@@ -27,7 +25,7 @@ class Tcl(ModuleBuilder):
27
25
 
28
26
  def _prepare(self):
29
27
  for path in runez.ls_dir(self.m_src_build / "pkgs"):
30
- if path.name.startswith(("sqlite", "tdbc")): # pragma: no cover, tcl/tk is "best effort"
28
+ if path.name.startswith(("sqlite", "tdbc")):
31
29
  # Remove packages we don't care about and can pull in unwanted symbols
32
30
  runez.delete(path)
33
31
 
@@ -55,7 +53,7 @@ class Tk(ModuleBuilder):
55
53
  yield "--enable-threads"
56
54
  yield f"--with-tcl={self.deps_lib_dir}"
57
55
  yield "--without-x"
58
- if PPG.target.is_macos: # pragma: no cover, tcl/tk is "best effort"
56
+ if PPG.target.is_macos:
59
57
  yield "--enable-aqua=yes"
60
58
 
61
59
  def _do_linux_compile(self):
@@ -110,7 +108,7 @@ class TkInter(ModuleBuilder):
110
108
  """
111
109
 
112
110
  m_debian = "-tk-dev"
113
- m_telltale: ClassVar[list] = ["{include}/tk", "{include}/tk.h"]
111
+ m_telltale = "{include}/tk {include}/tk.h"
114
112
 
115
113
  @classmethod
116
114
  def candidate_modules(cls):