portable-python 2.0.1__py3-none-any.whl → 2.1.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.
- portable_python/__init__.py +96 -88
- portable_python/cli.py +7 -11
- portable_python/config.py +22 -36
- portable_python/cpython.py +23 -10
- portable_python/external/__init__.py +2 -1
- portable_python/external/xcpython.py +32 -27
- portable_python/external/xtkinter.py +3 -5
- portable_python/inspector.py +52 -64
- portable_python/tracking.py +45 -43
- portable_python/versions.py +70 -61
- {portable_python-2.0.1.dist-info → portable_python-2.1.0.dist-info}/METADATA +3 -3
- portable_python-2.1.0.dist-info/RECORD +18 -0
- {portable_python-2.0.1.dist-info → portable_python-2.1.0.dist-info}/WHEEL +1 -1
- portable_python-2.0.1.dist-info/RECORD +0 -20
- portable_python-2.0.1.dist-info/scm_file_list.json +0 -93
- portable_python-2.0.1.dist-info/scm_version.json +0 -8
- {portable_python-2.0.1.dist-info → portable_python-2.1.0.dist-info}/entry_points.txt +0 -0
- {portable_python-2.0.1.dist-info → portable_python-2.1.0.dist-info}/licenses/LICENSE +0 -0
- {portable_python-2.0.1.dist-info → portable_python-2.1.0.dist-info}/top_level.txt +0 -0
portable_python/__init__.py
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Designed to be used via portable-python CLI.
|
|
3
3
|
Can be used programmatically too, example usage:
|
|
4
4
|
|
|
5
|
-
from portable_python import BuildSetup
|
|
5
|
+
from portable_python import BuildSetup, required_python_spec
|
|
6
6
|
|
|
7
|
-
setup = BuildSetup("cpython:3.9.6")
|
|
7
|
+
setup = BuildSetup(required_python_spec("cpython:3.9.6"))
|
|
8
8
|
setup.compile()
|
|
9
9
|
"""
|
|
10
10
|
|
|
@@ -15,8 +15,9 @@ import multiprocessing
|
|
|
15
15
|
import os
|
|
16
16
|
import pathlib
|
|
17
17
|
import re
|
|
18
|
+
import shlex
|
|
19
|
+
from collections.abc import Iterable
|
|
18
20
|
from string import Template
|
|
19
|
-
from typing import ClassVar, List
|
|
20
21
|
|
|
21
22
|
import runez
|
|
22
23
|
from runez.http import RestClient
|
|
@@ -33,7 +34,7 @@ def is_binary_file(path):
|
|
|
33
34
|
return RX_BINARY.match(path.name)
|
|
34
35
|
|
|
35
36
|
|
|
36
|
-
def patch_folder(folder, regex, replacement, ignore=None):
|
|
37
|
+
def patch_folder(folder, regex, replacement, ignore=None, dryrun: runez.DryrunSpec = runez.UNSET):
|
|
37
38
|
"""Replace all occurrences of 'old_text' by 'new_text' in all files in 'folder'
|
|
38
39
|
|
|
39
40
|
Parameters
|
|
@@ -46,33 +47,53 @@ def patch_folder(folder, regex, replacement, ignore=None):
|
|
|
46
47
|
Replacement text
|
|
47
48
|
ignore : re.Pattern | None
|
|
48
49
|
Regex stating what to ignore
|
|
50
|
+
dryrun
|
|
51
|
+
Optionally override current dryrun setting
|
|
49
52
|
"""
|
|
50
53
|
for path in runez.ls_dir(folder):
|
|
51
54
|
if not path.is_symlink() and (not ignore or not ignore.match(path.name)):
|
|
52
55
|
if path.is_dir():
|
|
53
|
-
patch_folder(path, regex, replacement, ignore=ignore)
|
|
56
|
+
patch_folder(path, regex, replacement, ignore=ignore, dryrun=dryrun)
|
|
54
57
|
|
|
55
58
|
elif not is_binary_file(path):
|
|
56
|
-
patch_file(path, regex, replacement)
|
|
59
|
+
patch_file(path, regex, replacement, dryrun=dryrun)
|
|
57
60
|
|
|
58
61
|
|
|
59
|
-
def patch_file(path, regex, replacement):
|
|
62
|
+
def patch_file(path, regex, replacement, dryrun: runez.DryrunSpec = runez.UNSET):
|
|
63
|
+
"""Replace `regex` with `replacement` in file `path`, if it occurs there"""
|
|
64
|
+
if not os.path.exists(path):
|
|
65
|
+
if not runez.log.resolved_dryrun(dryrun): # Sources to patch are not downloaded in dryrun mode
|
|
66
|
+
LOG.warning("Can't patch %s: file not found", runez.short(path))
|
|
67
|
+
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
overview = f"{regex} -> {runez.short(replacement)} in {runez.short(path)}"
|
|
60
71
|
try:
|
|
61
72
|
with open(path) as fh:
|
|
62
73
|
text = fh.read()
|
|
63
74
|
|
|
64
75
|
new_text = re.sub(regex, replacement, text, flags=re.MULTILINE)
|
|
65
|
-
if text != new_text:
|
|
76
|
+
if text != new_text and not runez.log.hdry(f"apply patch: {overview}", dryrun=dryrun):
|
|
66
77
|
with open(path, "w") as fh:
|
|
67
78
|
fh.write(new_text)
|
|
68
79
|
|
|
69
|
-
LOG.info("Patched
|
|
80
|
+
LOG.info("Patched %s", overview)
|
|
70
81
|
|
|
71
82
|
except Exception as e:
|
|
72
83
|
with open(path, errors="ignore") as fh:
|
|
73
84
|
text = fh.read()
|
|
74
85
|
if re.search(regex, text):
|
|
75
|
-
LOG.warning("Can't patch
|
|
86
|
+
LOG.warning("Can't patch %s: %s", overview, e)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def correct_permissions(path: pathlib.Path, expected: int, dryrun: runez.DryrunSpec = runez.UNSET):
|
|
90
|
+
"""Ensure that `path` has `expected` permissions"""
|
|
91
|
+
current = path.stat().st_mode & 0o777
|
|
92
|
+
if current != expected:
|
|
93
|
+
overview = f"permissions for {runez.short(path)} to {oct(expected)} (was {oct(current)})"
|
|
94
|
+
if not runez.log.hdry(f"correct {overview}", dryrun=dryrun):
|
|
95
|
+
LOG.info("Corrected %s", overview)
|
|
96
|
+
path.chmod(expected)
|
|
76
97
|
|
|
77
98
|
|
|
78
99
|
class FolderMask:
|
|
@@ -147,9 +168,6 @@ class BuildContext:
|
|
|
147
168
|
|
|
148
169
|
return v
|
|
149
170
|
|
|
150
|
-
def __repr__(self):
|
|
151
|
-
return self.isolate_usr_local or "none"
|
|
152
|
-
|
|
153
171
|
def __enter__(self):
|
|
154
172
|
runez.Anchored.add(self.setup.folders.base_folder)
|
|
155
173
|
if self.isolate_usr_local == "mount-shadow":
|
|
@@ -166,7 +184,7 @@ class BuildContext:
|
|
|
166
184
|
self.masked_folders.append(mask)
|
|
167
185
|
mask.mount()
|
|
168
186
|
|
|
169
|
-
except BaseException: #
|
|
187
|
+
except BaseException: # Ensure cleanup if any folder couldn't be masked
|
|
170
188
|
self.cleanup()
|
|
171
189
|
raise
|
|
172
190
|
|
|
@@ -189,6 +207,18 @@ class BuildContext:
|
|
|
189
207
|
runez.Anchored.pop(self.setup.folders.base_folder)
|
|
190
208
|
|
|
191
209
|
|
|
210
|
+
def required_python_spec(text: str | None) -> PythonSpec:
|
|
211
|
+
"""Python to build, with a full version (aborts with a clear message otherwise), default: latest cpython"""
|
|
212
|
+
spec = PythonSpec.from_object(PPG.cpython.latest if not text or text == "latest" else text)
|
|
213
|
+
if not spec:
|
|
214
|
+
runez.abort("Invalid python spec: %s" % runez.red(text))
|
|
215
|
+
|
|
216
|
+
if spec.version.given_components_count < 3:
|
|
217
|
+
runez.abort("Please provide full desired version: %s is not good enough" % runez.red(spec))
|
|
218
|
+
|
|
219
|
+
return spec
|
|
220
|
+
|
|
221
|
+
|
|
192
222
|
class BuildSetup:
|
|
193
223
|
"""
|
|
194
224
|
Drives the compilation, external modules first, then the target python itself.
|
|
@@ -198,33 +228,22 @@ class BuildSetup:
|
|
|
198
228
|
# Internal, used to ensure files under {logs}/ folder sort alphabetically in the same order they were compiled
|
|
199
229
|
log_counter = 0
|
|
200
230
|
|
|
201
|
-
def __init__(self, python_spec
|
|
231
|
+
def __init__(self, python_spec: PythonSpec, modules: str | None = None, prefix: str | None = None):
|
|
202
232
|
"""
|
|
203
233
|
Parameters
|
|
204
234
|
----------
|
|
205
|
-
python_spec
|
|
206
|
-
Python to build (family and version)
|
|
207
|
-
modules
|
|
235
|
+
python_spec
|
|
236
|
+
Python to build (family and full version), see `required_python_spec()`
|
|
237
|
+
modules
|
|
208
238
|
Modules to build (default: from config)
|
|
209
|
-
prefix
|
|
239
|
+
prefix
|
|
210
240
|
--prefix to use
|
|
211
241
|
"""
|
|
212
|
-
if not python_spec or python_spec == "latest":
|
|
213
|
-
python_spec = PPG.cpython.latest
|
|
214
|
-
|
|
215
|
-
if not isinstance(python_spec, PythonSpec):
|
|
216
|
-
ps = PythonSpec.from_object(python_spec)
|
|
217
|
-
runez.abort_if(not ps, "Invalid python spec: %s" % runez.red(python_spec))
|
|
218
|
-
python_spec = ps
|
|
219
|
-
|
|
220
|
-
runez.abort_if(not python_spec.version or not python_spec.version.is_valid, "Invalid python spec: %s" % runez.red(python_spec))
|
|
221
|
-
if len(python_spec.version.given_components) < 3:
|
|
222
|
-
runez.abort("Please provide full desired version: %s is not good enough" % runez.red(python_spec))
|
|
223
|
-
|
|
224
242
|
self.python_spec = python_spec
|
|
225
243
|
self.folders = PPG.get_folders(
|
|
226
244
|
base=os.getcwd(), family=python_spec.family, version=python_spec.version, abi_suffix=python_spec.abi_suffix
|
|
227
245
|
)
|
|
246
|
+
self.build_context: BuildContext | None = None # Set during compile()
|
|
228
247
|
self.desired_modules = modules
|
|
229
248
|
prefix = self.folders.formatted(prefix)
|
|
230
249
|
self.prefix = prefix
|
|
@@ -244,7 +263,7 @@ class BuildSetup:
|
|
|
244
263
|
)
|
|
245
264
|
|
|
246
265
|
builder = PPG.family(python_spec.family).get_builder()
|
|
247
|
-
self.python_builder = builder(self)
|
|
266
|
+
self.python_builder = builder(self)
|
|
248
267
|
|
|
249
268
|
def __repr__(self):
|
|
250
269
|
return str(self.folders)
|
|
@@ -301,41 +320,35 @@ class BuildSetup:
|
|
|
301
320
|
class ModuleCollection:
|
|
302
321
|
"""Models a collection of sub-modules, with auto-detection and reporting as to what is active and why"""
|
|
303
322
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
def __init__(self, parent_module: "ModuleBuilder", desired=None):
|
|
309
|
-
self.selected = []
|
|
310
|
-
self.auto_selected = {}
|
|
311
|
-
self.candidates = []
|
|
323
|
+
def __init__(self, parent_module: "ModuleBuilder", desired: str | None = None):
|
|
324
|
+
self.selected: list[ModuleBuilder] = []
|
|
325
|
+
self.auto_selected: dict[str, str] = {}
|
|
326
|
+
self.candidates: list[ModuleBuilder] = []
|
|
312
327
|
self.desired = desired
|
|
313
|
-
self.module_by_name
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
self.candidates.append(module)
|
|
319
|
-
self.module_by_name[module.m_name] = module
|
|
328
|
+
self.module_by_name: dict[str, ModuleBuilder] = {}
|
|
329
|
+
for module_class in parent_module.candidate_modules():
|
|
330
|
+
module = module_class(parent_module)
|
|
331
|
+
self.candidates.append(module)
|
|
332
|
+
self.module_by_name[module.m_name] = module
|
|
320
333
|
|
|
321
334
|
if desired == "all":
|
|
322
335
|
self.selected = self.candidates
|
|
323
336
|
return
|
|
324
337
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
unknown = [x for x in
|
|
338
|
+
names = [] if desired == "none" else runez.flattened(desired, split=True)
|
|
339
|
+
names = runez.flattened(names, split=",")
|
|
340
|
+
unknown = [x for x in names if x not in self.module_by_name]
|
|
328
341
|
if unknown:
|
|
329
342
|
runez.abort("Unknown modules: %s" % runez.joined(unknown, delimiter=", ", stringify=runez.red))
|
|
330
343
|
|
|
331
344
|
for candidate in self.candidates:
|
|
332
|
-
if candidate.m_name not in
|
|
345
|
+
if candidate.m_name not in names:
|
|
333
346
|
reason = candidate.auto_select_reason()
|
|
334
347
|
if reason:
|
|
335
348
|
self.auto_selected[candidate.m_name] = reason
|
|
336
349
|
|
|
337
|
-
|
|
338
|
-
self.selected = [self.module_by_name[x] for x in
|
|
350
|
+
names.extend(self.auto_selected.keys())
|
|
351
|
+
self.selected = [self.module_by_name[x] for x in names]
|
|
339
352
|
|
|
340
353
|
def __repr__(self):
|
|
341
354
|
return "selected: %s (%s)" % (self.desired, runez.plural(self.selected, "module"))
|
|
@@ -402,13 +415,13 @@ class LinkerOutcome(enum.Enum):
|
|
|
402
415
|
class ModuleBuilder:
|
|
403
416
|
"""Common behavior for all external (typically C) modules to be compiled"""
|
|
404
417
|
|
|
405
|
-
m_build_cwd: str = None # Optional: relative (to unpacked source) folder where to run configure/make from
|
|
406
|
-
m_debian = None
|
|
407
|
-
m_include: str = None # Optional: subfolder to automatically list in CPATH when this module is active
|
|
408
|
-
m_telltale:
|
|
418
|
+
m_build_cwd: str | None = None # Optional: relative (to unpacked source) folder where to run configure/make from
|
|
419
|
+
m_debian: str | None = None # Optional: debian package, prefixed with "!": required, "+": required if selected, "-": prevents static
|
|
420
|
+
m_include: str | None = None # Optional: subfolder to automatically list in CPATH when this module is active
|
|
421
|
+
m_telltale: str = "" # Optional: file(s) that, if present, indicate this module is installed (space separated)
|
|
409
422
|
|
|
410
423
|
setup: BuildSetup
|
|
411
|
-
parent_module: "ModuleBuilder" = None
|
|
424
|
+
parent_module: "ModuleBuilder | None" = None
|
|
412
425
|
_log_handler = None
|
|
413
426
|
|
|
414
427
|
def __init__(self, parent_module):
|
|
@@ -434,13 +447,14 @@ class ModuleBuilder:
|
|
|
434
447
|
return "%s:%s" % (self.m_name, self.version)
|
|
435
448
|
|
|
436
449
|
@classmethod
|
|
437
|
-
def candidate_modules(cls) ->
|
|
450
|
+
def candidate_modules(cls) -> Iterable[type["ModuleBuilder"]]:
|
|
438
451
|
"""All possible candidate external modules for this builder"""
|
|
452
|
+
return []
|
|
439
453
|
|
|
440
454
|
def selected_modules(self):
|
|
441
455
|
return ModuleCollection(self, desired="all")
|
|
442
456
|
|
|
443
|
-
def auto_select_reason(self):
|
|
457
|
+
def auto_select_reason(self) -> str | None:
|
|
444
458
|
"""
|
|
445
459
|
If this module must be selected (build can't succeed without), descendant should return short explanation why
|
|
446
460
|
"""
|
|
@@ -480,11 +494,10 @@ class ModuleBuilder:
|
|
|
480
494
|
return "no %s" % self.m_telltale
|
|
481
495
|
|
|
482
496
|
def _find_telltale(self):
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return telltales
|
|
497
|
+
if not self.m_telltale:
|
|
498
|
+
return runez.UNSET # Sub-modules don't have a telltale
|
|
486
499
|
|
|
487
|
-
return PPG.find_telltale(
|
|
500
|
+
return PPG.find_telltale(self.m_telltale)
|
|
488
501
|
|
|
489
502
|
def active_module(self, name):
|
|
490
503
|
return self.modules.active_module(name)
|
|
@@ -514,16 +527,19 @@ class ModuleBuilder:
|
|
|
514
527
|
def cfg_src_suffix(self):
|
|
515
528
|
return PPG.config.get_value("%s-src-suffix" % self.m_name)
|
|
516
529
|
|
|
517
|
-
def cfg_configure(self, deps_lib_dir, deps_lib64_dir):
|
|
530
|
+
def cfg_configure(self, deps_lib_dir, deps_lib64_dir) -> list[str] | None:
|
|
531
|
+
"""Configure args from config (`$lib_dir` and `$lib64_dir` substituted), shell-style split into separate args"""
|
|
518
532
|
if configure := PPG.config.get_value("%s-configure" % self.m_name):
|
|
519
|
-
|
|
520
|
-
return
|
|
533
|
+
configure = Template(configure).substitute(lib_dir=deps_lib_dir, lib64_dir=deps_lib64_dir)
|
|
534
|
+
return shlex.split(configure)
|
|
535
|
+
|
|
536
|
+
return None
|
|
521
537
|
|
|
522
538
|
def cfg_patches(self):
|
|
523
539
|
return PPG.config.get_value("%s-patches" % self.m_name)
|
|
524
540
|
|
|
525
541
|
@property
|
|
526
|
-
def url(self):
|
|
542
|
+
def url(self) -> str:
|
|
527
543
|
"""Url of source tarball, if any"""
|
|
528
544
|
return ""
|
|
529
545
|
|
|
@@ -607,7 +623,7 @@ class ModuleBuilder:
|
|
|
607
623
|
cmd = runez.flattened(*program, prefix, *args)
|
|
608
624
|
return self._do_run(*cmd)
|
|
609
625
|
|
|
610
|
-
def run_make(self, *args, program="make", cpu_count=None):
|
|
626
|
+
def run_make(self, *args, program: str = "make", cpu_count: int | None = None):
|
|
611
627
|
cmd = program.split()
|
|
612
628
|
if cpu_count is None:
|
|
613
629
|
available = multiprocessing.cpu_count()
|
|
@@ -729,11 +745,7 @@ class ModuleBuilder:
|
|
|
729
745
|
def _apply_patches(self):
|
|
730
746
|
if patches := self.cfg_patches():
|
|
731
747
|
for patch in patches:
|
|
732
|
-
|
|
733
|
-
print(f"Would apply patch: {patch}")
|
|
734
|
-
else:
|
|
735
|
-
print(f"Applying patch: {patch}")
|
|
736
|
-
patch_file(patch["file"], patch["regex"], patch["replacement"])
|
|
748
|
+
patch_file(patch["file"], patch["regex"], patch["replacement"])
|
|
737
749
|
|
|
738
750
|
def _get_env_vars(self):
|
|
739
751
|
"""Yield all found env vars, first found wins"""
|
|
@@ -782,7 +794,7 @@ class ModuleBuilder:
|
|
|
782
794
|
|
|
783
795
|
|
|
784
796
|
class PythonBuilder(ModuleBuilder):
|
|
785
|
-
_bin_python: pathlib.Path = None
|
|
797
|
+
_bin_python: pathlib.Path | None = None
|
|
786
798
|
|
|
787
799
|
def __init__(self, parent_module):
|
|
788
800
|
super().__init__(parent_module)
|
|
@@ -799,15 +811,14 @@ class PythonBuilder(ModuleBuilder):
|
|
|
799
811
|
return ModuleCollection(self, desired=desired)
|
|
800
812
|
|
|
801
813
|
@property
|
|
802
|
-
def bin_python(self):
|
|
803
|
-
"""
|
|
804
|
-
Returns
|
|
805
|
-
-------
|
|
806
|
-
pathlib.Path | None
|
|
807
|
-
Path to freshly compiled bin/python, real file (not symlink)
|
|
808
|
-
"""
|
|
814
|
+
def bin_python(self) -> pathlib.Path:
|
|
815
|
+
"""Path to freshly compiled bin/python, real file (not symlink)"""
|
|
809
816
|
if self._bin_python is None:
|
|
810
|
-
|
|
817
|
+
bin_python = PPG.config.find_main_file(self.bin_folder / "python", self.version)
|
|
818
|
+
if not bin_python:
|
|
819
|
+
runez.abort(f"Can't find bin/python in {self.bin_folder}")
|
|
820
|
+
|
|
821
|
+
self._bin_python = bin_python
|
|
811
822
|
|
|
812
823
|
return self._bin_python
|
|
813
824
|
|
|
@@ -817,6 +828,7 @@ class PythonBuilder(ModuleBuilder):
|
|
|
817
828
|
|
|
818
829
|
def xenv_LDFLAGS(self):
|
|
819
830
|
"""Python builder does not reuse the common setting"""
|
|
831
|
+
yield from ()
|
|
820
832
|
|
|
821
833
|
def run_python(self, *args):
|
|
822
834
|
"""Run python command, using the freshly compiled python binary"""
|
|
@@ -834,8 +846,4 @@ class PythonBuilder(ModuleBuilder):
|
|
|
834
846
|
for lib_dir in self.deps_lib_dirs:
|
|
835
847
|
for path in runez.ls_dir(lib_dir):
|
|
836
848
|
if not path.name.endswith(".la"):
|
|
837
|
-
|
|
838
|
-
current = path.stat().st_mode & 0o777
|
|
839
|
-
if current != expected:
|
|
840
|
-
LOG.info("Corrected permissions for %s (was %s)", runez.short(path), oct(current))
|
|
841
|
-
path.chmod(expected)
|
|
849
|
+
correct_permissions(path, 0o755 if path.is_dir() else 0o644)
|
portable_python/cli.py
CHANGED
|
@@ -5,7 +5,7 @@ import runez
|
|
|
5
5
|
from runez.pyenv import PythonSpec
|
|
6
6
|
from runez.render import PrettyTable
|
|
7
7
|
|
|
8
|
-
from portable_python import BuildSetup, PPG
|
|
8
|
+
from portable_python import BuildSetup, PPG, required_python_spec
|
|
9
9
|
from portable_python.inspector import LibAutoCorrect, PythonInspector
|
|
10
10
|
|
|
11
11
|
LOG = logging.getLogger(__name__)
|
|
@@ -41,7 +41,7 @@ def main(config, quiet, target):
|
|
|
41
41
|
@click.argument("python_spec")
|
|
42
42
|
def build(modules, prefix, python_spec):
|
|
43
43
|
"""Build a portable python binary"""
|
|
44
|
-
setup = BuildSetup(python_spec, modules=modules, prefix=prefix)
|
|
44
|
+
setup = BuildSetup(required_python_spec(python_spec), modules=modules, prefix=prefix)
|
|
45
45
|
setup.compile()
|
|
46
46
|
|
|
47
47
|
|
|
@@ -50,7 +50,7 @@ def build(modules, prefix, python_spec):
|
|
|
50
50
|
@click.argument("python_spec", required=False)
|
|
51
51
|
def build_report(modules, python_spec):
|
|
52
52
|
"""Show status of buildable modules, which will be auto-compiled"""
|
|
53
|
-
setup = BuildSetup(python_spec, modules=modules)
|
|
53
|
+
setup = BuildSetup(required_python_spec(python_spec), modules=modules)
|
|
54
54
|
print(runez.bold(setup.python_spec))
|
|
55
55
|
report = setup.python_builder.modules.report()
|
|
56
56
|
print(report)
|
|
@@ -90,10 +90,7 @@ def inspect(modules, verbose, prefix, skip_so, path):
|
|
|
90
90
|
@click.argument("family", default="cpython")
|
|
91
91
|
def list_cmd(json, family):
|
|
92
92
|
"""List latest versions"""
|
|
93
|
-
fam = PPG.family(family
|
|
94
|
-
if not fam:
|
|
95
|
-
runez.abort("Python family '%s' is not yet supported" % runez.red(family))
|
|
96
|
-
|
|
93
|
+
fam = PPG.family(family)
|
|
97
94
|
if json:
|
|
98
95
|
print(runez.represented_json(fam.available_versions))
|
|
99
96
|
return
|
|
@@ -116,6 +113,7 @@ def _find_recompress_source(folders, path):
|
|
|
116
113
|
candidates = [folders.base_folder, folders.build_folder, folders.dist, folders.destdir]
|
|
117
114
|
for candidate in candidates:
|
|
118
115
|
if candidate:
|
|
116
|
+
# TODO: `runez.to_path()` can be simplified away when all `folders.` attributes become of type Path
|
|
119
117
|
candidate = runez.to_path(candidate) / path
|
|
120
118
|
if candidate.exists():
|
|
121
119
|
return candidate.absolute()
|
|
@@ -162,8 +160,8 @@ def recompress(path, ext):
|
|
|
162
160
|
Mildly useful for comparing sizes from different compressions
|
|
163
161
|
""" # noqa: D301
|
|
164
162
|
extension = runez.SYS_INFO.platform_id.canonical_compress_extension(ext)
|
|
165
|
-
pspec = PythonSpec.from_text(path)
|
|
166
|
-
folders = PPG.get_folders(base=".", family=pspec
|
|
163
|
+
pspec = PythonSpec.from_text(path) # Best effort: a build folder like `3.9.7` yields a spec, archive names don't
|
|
164
|
+
folders = PPG.get_folders(base=".", family=pspec.family if pspec else "cpython", version=pspec.version if pspec else None)
|
|
167
165
|
with runez.Anchored(folders.base_folder):
|
|
168
166
|
actual_path = _find_recompress_source(folders, path)
|
|
169
167
|
if not actual_path:
|
|
@@ -205,6 +203,4 @@ def lib_auto_correct(commit, prefix, path):
|
|
|
205
203
|
|
|
206
204
|
|
|
207
205
|
if __name__ == "__main__":
|
|
208
|
-
from portable_python.cli import main
|
|
209
|
-
|
|
210
206
|
main()
|
portable_python/config.py
CHANGED
|
@@ -90,8 +90,8 @@ class Config:
|
|
|
90
90
|
|
|
91
91
|
self.target = target
|
|
92
92
|
self.default = ConfigSource("default config", self.parsed_yaml(DEFAULT_CONFIG, "default config"))
|
|
93
|
-
self._sources
|
|
94
|
-
self.by_path = {}
|
|
93
|
+
self._sources: list[ConfigSource] = []
|
|
94
|
+
self.by_path: dict[str, ConfigSource] = {}
|
|
95
95
|
for path in self.paths:
|
|
96
96
|
self.load(path)
|
|
97
97
|
|
|
@@ -228,9 +228,9 @@ class Config:
|
|
|
228
228
|
matcher = FileMatcher(spec)
|
|
229
229
|
LOG.info("Applying clean-up spec: %s", matcher)
|
|
230
230
|
cleaned = []
|
|
231
|
-
for
|
|
231
|
+
for root, dirnames, filenames in os.walk(module.install_folder):
|
|
232
232
|
removed = []
|
|
233
|
-
dirpath =
|
|
233
|
+
dirpath = pathlib.Path(root)
|
|
234
234
|
for name in dirnames:
|
|
235
235
|
full_path = dirpath / name
|
|
236
236
|
if matcher.is_match(full_path):
|
|
@@ -270,7 +270,7 @@ class Config:
|
|
|
270
270
|
def real_path(path: pathlib.Path):
|
|
271
271
|
if path and path.exists():
|
|
272
272
|
if path.is_symlink():
|
|
273
|
-
path =
|
|
273
|
+
path = path.resolve()
|
|
274
274
|
|
|
275
275
|
return path
|
|
276
276
|
|
|
@@ -325,8 +325,7 @@ class Config:
|
|
|
325
325
|
front = True
|
|
326
326
|
path = path[1:]
|
|
327
327
|
|
|
328
|
-
path = runez.resolved_path(path, base=base)
|
|
329
|
-
path = runez.to_path(path)
|
|
328
|
+
path = pathlib.Path(runez.resolved_path(path, base=base))
|
|
330
329
|
if path.exists():
|
|
331
330
|
with open(path) as fh:
|
|
332
331
|
data = self.parsed_yaml(fh, path)
|
|
@@ -368,22 +367,14 @@ class ConfigSource:
|
|
|
368
367
|
str | int | float | bool | dict | list | None
|
|
369
368
|
Associated value, if any
|
|
370
369
|
"""
|
|
371
|
-
|
|
370
|
+
value = self.data
|
|
371
|
+
for k in key if isinstance(key, tuple) else (key,):
|
|
372
|
+
if not isinstance(value, dict):
|
|
373
|
+
return None
|
|
372
374
|
|
|
373
|
-
|
|
374
|
-
if not key or not isinstance(data, dict):
|
|
375
|
-
return None
|
|
375
|
+
value = value.get(k)
|
|
376
376
|
|
|
377
|
-
|
|
378
|
-
if len(key) > 1:
|
|
379
|
-
value = self._deep_get(data, key[0])
|
|
380
|
-
return self._deep_get(value, key[1:])
|
|
381
|
-
|
|
382
|
-
key = key[0]
|
|
383
|
-
|
|
384
|
-
value = data.get(key)
|
|
385
|
-
if value is not None:
|
|
386
|
-
return value
|
|
377
|
+
return value
|
|
387
378
|
|
|
388
379
|
|
|
389
380
|
class FileMatcher:
|
|
@@ -395,42 +386,37 @@ class FileMatcher:
|
|
|
395
386
|
def __repr__(self):
|
|
396
387
|
return runez.joined(self.matches)
|
|
397
388
|
|
|
398
|
-
def is_match(self, path: pathlib.Path):
|
|
399
|
-
for m in self.matches
|
|
400
|
-
if m.is_match(path):
|
|
401
|
-
return path
|
|
389
|
+
def is_match(self, path: pathlib.Path) -> bool:
|
|
390
|
+
return any(m.is_match(path) for m in self.matches)
|
|
402
391
|
|
|
403
392
|
|
|
404
393
|
class SingleFileMatch:
|
|
405
|
-
_on_folder = False
|
|
406
|
-
_rx_basename = None
|
|
407
|
-
_rx_path = None
|
|
408
|
-
|
|
409
394
|
def __init__(self, spec: str):
|
|
410
395
|
self.spec = spec
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
396
|
+
self._on_folder = spec.endswith("/")
|
|
397
|
+
spec = spec.removesuffix("/")
|
|
398
|
+
self._rx_path: re.Pattern[str] | None = None
|
|
415
399
|
if "/" in spec:
|
|
416
400
|
# lib/*/config-{python_mm}-\w+/
|
|
417
401
|
path = ".*/%s$" % os.path.dirname(spec).replace("*", ".*").strip("/")
|
|
418
402
|
spec = os.path.basename(spec)
|
|
419
403
|
self._rx_path = re.compile(path)
|
|
420
404
|
|
|
421
|
-
self.
|
|
405
|
+
self._basename_glob = spec
|
|
422
406
|
|
|
423
407
|
def __repr__(self):
|
|
424
408
|
return self.spec
|
|
425
409
|
|
|
426
|
-
def is_match(self, path: pathlib.Path):
|
|
410
|
+
def is_match(self, path: pathlib.Path) -> bool:
|
|
427
411
|
if self._on_folder == path.is_dir():
|
|
428
412
|
if self._rx_path:
|
|
429
413
|
m = self._rx_path.match(str(path.parent))
|
|
430
414
|
if not m:
|
|
431
415
|
return False
|
|
432
416
|
|
|
433
|
-
return fnmatch.fnmatch(path.name, self.
|
|
417
|
+
return fnmatch.fnmatch(path.name, self._basename_glob)
|
|
418
|
+
|
|
419
|
+
return False
|
|
434
420
|
|
|
435
421
|
|
|
436
422
|
def _find_file_duplicates(seen, folder):
|
portable_python/cpython.py
CHANGED
|
@@ -79,7 +79,7 @@ class Cpython(PythonBuilder):
|
|
|
79
79
|
"host-platform": runez.SYS_INFO.platform_info,
|
|
80
80
|
"ldd-version": PythonInspector.tool_version("ldd"),
|
|
81
81
|
"portable-python-version": runez.get_version(__package__),
|
|
82
|
-
"special-context": bc.isolate_usr_local
|
|
82
|
+
"special-context": bc.isolate_usr_local if bc else None,
|
|
83
83
|
},
|
|
84
84
|
)
|
|
85
85
|
additional = PPG.config.get_value("manifest", "additional-info")
|
|
@@ -188,7 +188,7 @@ class Cpython(PythonBuilder):
|
|
|
188
188
|
yield f"{self.deps_lib_dir}/libzstd.a"
|
|
189
189
|
|
|
190
190
|
def xenv_LIBMPDEC_CFLAGS(self):
|
|
191
|
-
if self.version >= "3.14" and PPG.target.is_macos:
|
|
191
|
+
if self.version >= "3.14" and PPG.target.is_macos and self.active_module(Mpdec):
|
|
192
192
|
# Normally ./configure will autodetect using pkg-config, but
|
|
193
193
|
# this doesn't typically work on Mac (the pkg-config binary is
|
|
194
194
|
# in homebrew, which we omit from path) so we have to provide
|
|
@@ -196,9 +196,24 @@ class Cpython(PythonBuilder):
|
|
|
196
196
|
yield f"-I{self.deps}/include"
|
|
197
197
|
|
|
198
198
|
def xenv_LIBMPDEC_LIBS(self):
|
|
199
|
-
if self.version >= "3.14" and PPG.target.is_macos:
|
|
199
|
+
if self.version >= "3.14" and PPG.target.is_macos and self.active_module(Mpdec):
|
|
200
200
|
yield f"{self.deps_lib_dir}/libmpdec.a"
|
|
201
201
|
|
|
202
|
+
def xenv_LIBREADLINE_LIBS(self):
|
|
203
|
+
if self.version >= "3.12" and self.active_module(Readline):
|
|
204
|
+
# Since 3.12 (gh-90005), ./configure asks pkg-config how to link the readline module,
|
|
205
|
+
# and no longer probes for the termcap library that readline needs. It states:
|
|
206
|
+
# "We now assume that libreadline or readline.pc provide correct linker information".
|
|
207
|
+
# Our readline is static, and its readline.pc mentions ncurses in 'Requires.private',
|
|
208
|
+
# which `pkg-config --libs` does not report (only `--libs --static` does). readline
|
|
209
|
+
# then gets linked without ncurses: it compiles, but fails to import at the end of
|
|
210
|
+
# the build with "undefined symbol: UP". So state the full static link line ourselves
|
|
211
|
+
# (same as `pkg-config --static --libs readline`), ./configure honors <LIB>_LIBS for
|
|
212
|
+
# exactly this purpose (gh-94801).
|
|
213
|
+
yield f"-L{self.deps_lib_dir}"
|
|
214
|
+
yield "-lreadline"
|
|
215
|
+
yield "-lncursesw"
|
|
216
|
+
|
|
202
217
|
@runez.cached_property
|
|
203
218
|
def prefix_lib_folder(self):
|
|
204
219
|
"""Path to <prefix>/lib/pythonM.m folder"""
|
|
@@ -265,7 +280,6 @@ class Cpython(PythonBuilder):
|
|
|
265
280
|
|
|
266
281
|
self.run_python("-mpip", "install", "--no-cache-dir", "--upgrade", *runez.flattened(additional))
|
|
267
282
|
|
|
268
|
-
runez.abort_if(not runez.DRYRUN and not self.bin_python, f"Can't find bin/python in {self.bin_folder}")
|
|
269
283
|
PPG.config.ensure_main_file_symlinks(self)
|
|
270
284
|
if not self.setup.prefix:
|
|
271
285
|
self._relativize_sysconfig()
|
|
@@ -290,7 +304,7 @@ class Cpython(PythonBuilder):
|
|
|
290
304
|
|
|
291
305
|
info_path = PPG.config.get_value("manifest", "inspection-report")
|
|
292
306
|
if info_path:
|
|
293
|
-
with runez.
|
|
307
|
+
with runez.ActivateColors(enable=False):
|
|
294
308
|
py_inspector = PythonInspector(self.install_folder, modules="all")
|
|
295
309
|
contents = "%s\n" % py_inspector.represented(verbose=True)
|
|
296
310
|
runez.write(self.install_folder / info_path, contents)
|
|
@@ -325,7 +339,7 @@ class Cpython(PythonBuilder):
|
|
|
325
339
|
|
|
326
340
|
def _relativize_shebangs(self):
|
|
327
341
|
"""Autocorrect shebangs in bin/ folder, making them relative to the location of the python executable"""
|
|
328
|
-
for folder in (self.bin_folder, self.prefix_config_folder):
|
|
342
|
+
for folder in filter(None, (self.bin_folder, self.prefix_config_folder)):
|
|
329
343
|
for path in runez.ls_dir(folder):
|
|
330
344
|
if path != self.bin_python and runez.is_executable(path) and not path.is_symlink():
|
|
331
345
|
self._relativize_shebang_file(path)
|
|
@@ -390,11 +404,10 @@ class Cpython(PythonBuilder):
|
|
|
390
404
|
except UnicodeError:
|
|
391
405
|
return
|
|
392
406
|
|
|
393
|
-
if lines:
|
|
394
|
-
LOG.info("Auto-corrected shebang for %s"
|
|
407
|
+
if lines and not runez.log.hdry(f"auto-correct shebang for {runez.short(path)}"):
|
|
408
|
+
LOG.info("Auto-corrected shebang for %s", runez.short(path))
|
|
395
409
|
with open(path, "w") as fh:
|
|
396
|
-
|
|
397
|
-
fh.write(line)
|
|
410
|
+
fh.writelines(lines)
|
|
398
411
|
|
|
399
412
|
|
|
400
413
|
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.
|
|
15
|
+
return self.cfg_version("0.3.3")
|
|
15
16
|
|
|
16
17
|
def _do_linux_compile(self):
|
|
17
18
|
self.run_make("LIBINTL=NOOP")
|