portable-python 2.0.2__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 +8 -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 +51 -62
- portable_python/tracking.py +45 -43
- portable_python/versions.py +70 -61
- {portable_python-2.0.2.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.2.dist-info → portable_python-2.1.0.dist-info}/WHEEL +1 -1
- portable_python-2.0.2.dist-info/RECORD +0 -18
- {portable_python-2.0.2.dist-info → portable_python-2.1.0.dist-info}/entry_points.txt +0 -0
- {portable_python-2.0.2.dist-info → portable_python-2.1.0.dist-info}/licenses/LICENSE +0 -0
- {portable_python-2.0.2.dist-info → portable_python-2.1.0.dist-info}/top_level.txt +0 -0
|
@@ -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
|
|
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
|
|
126
|
+
m_telltale = "{include}/ffi.h {include}/ffi/ffi.h"
|
|
128
127
|
|
|
129
128
|
xenv_CFLAGS = "-fPIC"
|
|
130
129
|
|
|
@@ -136,12 +135,13 @@ 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
139
|
# Check https://github.com/libffi/libffi/releases
|
|
140
|
-
return self.cfg_version("3.
|
|
140
|
+
return self.cfg_version("3.8.0")
|
|
141
141
|
|
|
142
142
|
def c_configure_args(self):
|
|
143
143
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
144
|
-
yield config_args
|
|
144
|
+
yield from config_args
|
|
145
145
|
|
|
146
146
|
else:
|
|
147
147
|
yield "--enable-shared=no"
|
|
@@ -183,13 +183,14 @@ class Openssl(ModuleBuilder):
|
|
|
183
183
|
@property
|
|
184
184
|
def version(self):
|
|
185
185
|
# 3.5 is LTS, supported until Apr 2030 (3.0 EOL Sept 2026)
|
|
186
|
-
# Stay on the 3.5 LTS line
|
|
186
|
+
# Stay on the 3.5 LTS line: 3.6.x and 4.0.x have shipped but are not verified for cpython builds
|
|
187
|
+
# (python-build-standalone pins 3.5.x as well)
|
|
187
188
|
# Check https://github.com/openssl/openssl/releases and https://endoflife.date/openssl
|
|
188
|
-
return self.cfg_version("3.5.
|
|
189
|
+
return self.cfg_version("3.5.9")
|
|
189
190
|
|
|
190
191
|
def c_configure_args(self):
|
|
191
192
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
192
|
-
yield config_args
|
|
193
|
+
yield from config_args
|
|
193
194
|
|
|
194
195
|
else:
|
|
195
196
|
yield "-v"
|
|
@@ -219,7 +220,7 @@ class Ncurses(ModuleBuilder):
|
|
|
219
220
|
|
|
220
221
|
def c_configure_args(self):
|
|
221
222
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
222
|
-
yield config_args
|
|
223
|
+
yield from config_args
|
|
223
224
|
|
|
224
225
|
else:
|
|
225
226
|
yield "--disable-shared"
|
|
@@ -273,12 +274,13 @@ class Readline(ModuleBuilder):
|
|
|
273
274
|
@property
|
|
274
275
|
def version(self):
|
|
275
276
|
# Patched tarballs (e.g. "8.2.13") are available on the GNU FTP when patches accumulate
|
|
277
|
+
# 8.3 has official patches 001-003 pending, not rolled up yet: watch for a readline-8.3.x tarball
|
|
276
278
|
# Check https://ftpmirror.gnu.org/gnu/readline/ for available tarballs
|
|
277
279
|
return self.cfg_version("8.3")
|
|
278
280
|
|
|
279
281
|
def c_configure_args(self):
|
|
280
282
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
281
|
-
yield config_args
|
|
283
|
+
yield from config_args
|
|
282
284
|
|
|
283
285
|
else:
|
|
284
286
|
yield "--enable-shared=no"
|
|
@@ -302,7 +304,7 @@ class Sqlite(ModuleBuilder):
|
|
|
302
304
|
"""
|
|
303
305
|
|
|
304
306
|
m_debian = "+libsqlite3-dev"
|
|
305
|
-
m_telltale
|
|
307
|
+
m_telltale = "{include}/sqlite3.h"
|
|
306
308
|
|
|
307
309
|
xenv_CFLAGS = "-fPIC"
|
|
308
310
|
|
|
@@ -318,12 +320,13 @@ class Sqlite(ModuleBuilder):
|
|
|
318
320
|
|
|
319
321
|
@property
|
|
320
322
|
def version(self):
|
|
321
|
-
#
|
|
322
|
-
|
|
323
|
+
# 3.53.x gets frequent fix-only releases, keep current within the line
|
|
324
|
+
# Check https://sqlite.org/changes.html (avoid withdrawn releases like 3.52.0)
|
|
325
|
+
return self.cfg_version("3.53.4")
|
|
323
326
|
|
|
324
327
|
def c_configure_args(self):
|
|
325
328
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
326
|
-
yield config_args
|
|
329
|
+
yield from config_args
|
|
327
330
|
|
|
328
331
|
else:
|
|
329
332
|
yield "--disable-shared"
|
|
@@ -344,7 +347,7 @@ class Uuid(ModuleBuilder):
|
|
|
344
347
|
|
|
345
348
|
m_debian = "+uuid-dev"
|
|
346
349
|
m_include = "uuid"
|
|
347
|
-
m_telltale
|
|
350
|
+
m_telltale = "{include}/uuid/uuid.h"
|
|
348
351
|
|
|
349
352
|
xenv_CFLAGS = "-fPIC"
|
|
350
353
|
|
|
@@ -360,7 +363,7 @@ class Uuid(ModuleBuilder):
|
|
|
360
363
|
|
|
361
364
|
def c_configure_args(self):
|
|
362
365
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
363
|
-
yield config_args
|
|
366
|
+
yield from config_args
|
|
364
367
|
|
|
365
368
|
else:
|
|
366
369
|
yield "--enable-shared=no"
|
|
@@ -387,11 +390,11 @@ class Xz(ModuleBuilder):
|
|
|
387
390
|
@property
|
|
388
391
|
def version(self):
|
|
389
392
|
# Check https://github.com/tukaani-project/xz/releases
|
|
390
|
-
return self.cfg_version("5.8.
|
|
393
|
+
return self.cfg_version("5.8.4")
|
|
391
394
|
|
|
392
395
|
def c_configure_args(self):
|
|
393
396
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
394
|
-
yield config_args
|
|
397
|
+
yield from config_args
|
|
395
398
|
|
|
396
399
|
else:
|
|
397
400
|
yield "--enable-shared=no"
|
|
@@ -435,7 +438,7 @@ class Zlib(ModuleBuilder):
|
|
|
435
438
|
|
|
436
439
|
def c_configure_args(self):
|
|
437
440
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
438
|
-
yield config_args
|
|
441
|
+
yield from config_args
|
|
439
442
|
|
|
440
443
|
else:
|
|
441
444
|
yield "--static"
|
|
@@ -485,7 +488,8 @@ class Zstd(ModuleBuilder):
|
|
|
485
488
|
|
|
486
489
|
class Mpdec(ModuleBuilder):
|
|
487
490
|
"""
|
|
488
|
-
|
|
491
|
+
Since 3.15 (gh-115119), cpython no longer falls back to its bundled libmpdec: without one, `_decimal` is silently skipped
|
|
492
|
+
3.14 still falls back, but to a deprecated (and older) bundled copy, so we build it there too
|
|
489
493
|
"""
|
|
490
494
|
|
|
491
495
|
m_debian = "!libmpdec-dev"
|
|
@@ -494,11 +498,11 @@ class Mpdec(ModuleBuilder):
|
|
|
494
498
|
xenv_CFLAGS = "-fPIC"
|
|
495
499
|
|
|
496
500
|
def auto_select_reason(self):
|
|
497
|
-
if self.setup.python_spec.version >= "3.
|
|
501
|
+
if self.setup.python_spec.version >= "3.14":
|
|
498
502
|
if PPG.target.is_macos:
|
|
499
|
-
return "Required for 3.
|
|
503
|
+
return "Required for 3.14 and up"
|
|
500
504
|
if not self.resolved_telltale:
|
|
501
|
-
return "Required for 3.
|
|
505
|
+
return "Required for 3.14 and up"
|
|
502
506
|
|
|
503
507
|
@property
|
|
504
508
|
def url(self):
|
|
@@ -511,10 +515,11 @@ class Mpdec(ModuleBuilder):
|
|
|
511
515
|
|
|
512
516
|
def c_configure_args(self):
|
|
513
517
|
if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir):
|
|
514
|
-
yield config_args
|
|
518
|
+
yield from config_args
|
|
515
519
|
|
|
516
520
|
else:
|
|
517
|
-
|
|
521
|
+
yield "--disable-shared"
|
|
522
|
+
|
|
518
523
|
yield "--disable-cxx"
|
|
519
524
|
|
|
520
525
|
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")):
|
|
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:
|
|
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
|
|
111
|
+
m_telltale = "{include}/tk {include}/tk.h"
|
|
114
112
|
|
|
115
113
|
@classmethod
|
|
116
114
|
def candidate_modules(cls):
|
portable_python/inspector.py
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
import collections
|
|
2
|
-
import enum
|
|
3
2
|
import json
|
|
4
3
|
import logging
|
|
5
4
|
import os
|
|
6
5
|
import re
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
7
8
|
|
|
8
9
|
import runez
|
|
9
10
|
from runez.render import PrettyTable
|
|
10
11
|
|
|
11
|
-
from portable_python.tracking import Trackable, Tracker
|
|
12
|
+
from portable_python.tracking import LibType, Trackable, Tracker
|
|
12
13
|
from portable_python.versions import PPG
|
|
13
14
|
|
|
14
15
|
LOG = logging.getLogger(__name__)
|
|
15
16
|
RX_DYNLIB = re.compile(r"^.*\.(so(\.[0-9.]+)?|dylib)$")
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
class LibType(enum.Enum):
|
|
19
|
-
"""Categorization for dynamic libs, value being the color we want to show them as"""
|
|
20
|
-
|
|
21
|
-
base = ""
|
|
22
|
-
lib_static = "static"
|
|
23
|
-
libpython_so = "dynamic"
|
|
24
|
-
missing = "red"
|
|
25
|
-
other = "brown"
|
|
26
|
-
system = "blue"
|
|
27
|
-
|
|
28
|
-
|
|
29
19
|
class TempChmod:
|
|
30
20
|
"""
|
|
31
21
|
Temporarily chmod a given file.
|
|
@@ -140,23 +130,21 @@ class LibAutoCorrect:
|
|
|
140
130
|
|
|
141
131
|
@staticmethod
|
|
142
132
|
def _shared_ref_top_level(relative_path):
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
yield part
|
|
148
|
-
if part != "..":
|
|
149
|
-
return
|
|
133
|
+
for part in runez.to_path(relative_path).parts[:-1]: # Excluding basename
|
|
134
|
+
yield part
|
|
135
|
+
if part != "..":
|
|
136
|
+
return
|
|
150
137
|
|
|
151
138
|
|
|
152
139
|
class ModuleInfo:
|
|
153
140
|
_regex = re.compile(r"^(.*?)\s*(\S+/(lib(64)?/.*))$")
|
|
154
141
|
|
|
155
|
-
def __init__(self, inspector: "PythonInspector", name: str, payload: dict):
|
|
142
|
+
def __init__(self, inspector: "PythonInspector", name: str, payload: dict[str, Any]):
|
|
156
143
|
self.inspector = inspector
|
|
157
144
|
self.name = name
|
|
158
145
|
self.payload = payload
|
|
159
|
-
|
|
146
|
+
path = payload.get("path")
|
|
147
|
+
self.filepath = runez.to_path(path) if path else None
|
|
160
148
|
self.note = payload.get("note")
|
|
161
149
|
self.version = payload.get("version")
|
|
162
150
|
self.version_field = payload.get("version_field")
|
|
@@ -165,7 +153,7 @@ class ModuleInfo:
|
|
|
165
153
|
return runez.short(self.filepath)
|
|
166
154
|
|
|
167
155
|
@runez.cached_property
|
|
168
|
-
def additional_info(self):
|
|
156
|
+
def additional_info(self) -> "SoInfo | str | None":
|
|
169
157
|
path = self.filepath
|
|
170
158
|
if path:
|
|
171
159
|
if is_dyn_lib(path):
|
|
@@ -192,7 +180,7 @@ class ModuleInfo:
|
|
|
192
180
|
version = runez.bold(version)
|
|
193
181
|
|
|
194
182
|
info = self.additional_info
|
|
195
|
-
if
|
|
183
|
+
if isinstance(info, SoInfo):
|
|
196
184
|
info = info.represented()
|
|
197
185
|
|
|
198
186
|
else:
|
|
@@ -202,7 +190,7 @@ class ModuleInfo:
|
|
|
202
190
|
|
|
203
191
|
|
|
204
192
|
class CLibInfo(Trackable):
|
|
205
|
-
def __init__(self, inspector: "PythonInspector", path: str, version: str, basename: str):
|
|
193
|
+
def __init__(self, inspector: "PythonInspector", path: str, version: str | None, basename: str | None):
|
|
206
194
|
self.inspector = inspector
|
|
207
195
|
if not basename:
|
|
208
196
|
basename = os.path.basename(path)
|
|
@@ -242,10 +230,9 @@ class CLibInfo(Trackable):
|
|
|
242
230
|
def represented(self, verbose=False):
|
|
243
231
|
tc = self.tracked_category
|
|
244
232
|
if verbose:
|
|
245
|
-
|
|
233
|
+
return runez.joined("[%s]" % runez.colored(tc.name, color=tc.value), self.relative_path, self.version, delimiter=" ")
|
|
246
234
|
|
|
247
|
-
|
|
248
|
-
yield runez.colored(runez.joined(self.short_name, self.version, delimiter=":"), color=tc.value)
|
|
235
|
+
return runez.colored(runez.joined(self.short_name, self.version, delimiter=":"), color=tc.value)
|
|
249
236
|
|
|
250
237
|
|
|
251
238
|
class SoInfo(Trackable):
|
|
@@ -254,12 +241,12 @@ class SoInfo(Trackable):
|
|
|
254
241
|
self.path = runez.to_path(path)
|
|
255
242
|
self.relative_path = inspector.relative_path(self.path)
|
|
256
243
|
self.extension = self.path.name.rpartition(".")[2]
|
|
257
|
-
self.lib_tracker = Tracker(
|
|
244
|
+
self.lib_tracker = Tracker(".so")
|
|
258
245
|
program, output = self._dot_so_listing(self.path)
|
|
259
246
|
self.is_failed = "_failed" in self.path.name
|
|
260
247
|
self.short_name = "%s*" % self.path.name.partition(".")[0]
|
|
261
248
|
if self.is_failed:
|
|
262
|
-
self.short_name += "_failed"
|
|
249
|
+
self.short_name += "_failed"
|
|
263
250
|
|
|
264
251
|
if program and output:
|
|
265
252
|
func = getattr(self, "parse_%s" % program)
|
|
@@ -336,7 +323,7 @@ class SoInfo(Trackable):
|
|
|
336
323
|
info = CLibInfo(self.inspector, path, version, basename)
|
|
337
324
|
self.lib_tracker.add(info)
|
|
338
325
|
|
|
339
|
-
def represented(self, verbose=
|
|
326
|
+
def represented(self, verbose=False):
|
|
340
327
|
report = []
|
|
341
328
|
if verbose:
|
|
342
329
|
path = self.inspector.relative_path(self.path)
|
|
@@ -354,14 +341,14 @@ class SoInfo(Trackable):
|
|
|
354
341
|
for tp in types:
|
|
355
342
|
c = self.lib_tracker.category[tp]
|
|
356
343
|
if c.items:
|
|
357
|
-
|
|
344
|
+
text = runez.joined(c.represented(verbose), delimiter="\n " if verbose else delimiter)
|
|
358
345
|
if verbose:
|
|
359
|
-
|
|
346
|
+
text = f" {text}"
|
|
360
347
|
|
|
361
348
|
elif tp is LibType.missing:
|
|
362
|
-
|
|
349
|
+
text = f"{runez.red('missing')}: {text}"
|
|
363
350
|
|
|
364
|
-
report.append(
|
|
351
|
+
report.append(text)
|
|
365
352
|
|
|
366
353
|
return runez.joined(report, delimiter=delimiter)
|
|
367
354
|
|
|
@@ -379,7 +366,7 @@ def find_libs(folder):
|
|
|
379
366
|
yield from find_libs(path)
|
|
380
367
|
|
|
381
368
|
|
|
382
|
-
def get_lib_type(install_folder, path, basename):
|
|
369
|
+
def get_lib_type(install_folder, path, basename) -> LibType:
|
|
383
370
|
if basename.startswith("libpython") and path.startswith(install_folder):
|
|
384
371
|
return LibType.libpython_so
|
|
385
372
|
|
|
@@ -408,14 +395,15 @@ class PythonInspector:
|
|
|
408
395
|
script = os.path.join(os.path.dirname(__file__), "external/_inspect.py")
|
|
409
396
|
r = runez.run(self.python.executable, script, arg, fatal=False, logger=print if runez.DRYRUN else logging.debug)
|
|
410
397
|
self.output = r.output if r.succeeded else "exit code: %s\n%s" % (r.exit_code, r.full_output)
|
|
411
|
-
self.payload = None
|
|
398
|
+
self.payload: dict[str, Any] | None = None
|
|
412
399
|
if self.output and self.output.startswith("{"):
|
|
413
400
|
self.payload = json.loads(self.output)
|
|
414
401
|
|
|
415
|
-
|
|
416
|
-
self.
|
|
402
|
+
payload = self.payload or {}
|
|
403
|
+
self.reported_prefix = payload.get("prefix")
|
|
404
|
+
self.srcdir = runez.to_path(payload.get("srcdir"))
|
|
417
405
|
self.lib_folder = _find_parent_subfolder(self.srcdir, "lib")
|
|
418
|
-
self.install_folder = self.lib_folder
|
|
406
|
+
self.install_folder = str(self.lib_folder.parent) if self.lib_folder else None
|
|
419
407
|
|
|
420
408
|
def __repr__(self):
|
|
421
409
|
return str(self.python)
|
|
@@ -441,7 +429,7 @@ class PythonInspector:
|
|
|
441
429
|
if self.payload:
|
|
442
430
|
return {k: ModuleInfo(self, k, v) for k, v in self.payload.get("report", {}).items()}
|
|
443
431
|
|
|
444
|
-
def relative_path(self, path):
|
|
432
|
+
def relative_path(self, path) -> str:
|
|
445
433
|
with runez.Anchored(self.install_folder):
|
|
446
434
|
p = runez.short(path, size=4096)
|
|
447
435
|
m = re.match(r"^.*\.\.\./(.*)$", p)
|
|
@@ -451,7 +439,7 @@ class PythonInspector:
|
|
|
451
439
|
return p
|
|
452
440
|
|
|
453
441
|
def libpython_report(self, items):
|
|
454
|
-
if not items:
|
|
442
|
+
if not items or not self.install_folder: # install_folder is known when there are items (they're found in it)
|
|
455
443
|
return runez.green("-not used-")
|
|
456
444
|
|
|
457
445
|
rel_paths = [getattr(x, "relative_path", x) for x in items]
|
|
@@ -476,12 +464,11 @@ class PythonInspector:
|
|
|
476
464
|
table.add_row("lib", runez.short(self.lib_folder))
|
|
477
465
|
table.add_row("srcdir", runez.short(self.srcdir))
|
|
478
466
|
|
|
479
|
-
report.append(table)
|
|
467
|
+
report.append(str(table))
|
|
480
468
|
if verbose:
|
|
481
|
-
report.append(self.full_so_report)
|
|
482
|
-
if self.full_so_report.problematic:
|
|
483
|
-
|
|
484
|
-
report.append(runez.joined(pb, delimiter="\n"))
|
|
469
|
+
report.append(str(self.full_so_report))
|
|
470
|
+
if self.full_so_report.problematic:
|
|
471
|
+
report.append(self.full_so_report.problematic.report(verbose=verbose))
|
|
485
472
|
report.append("\n-- Library users:")
|
|
486
473
|
for what, users in self.full_so_report.lib_tracker.users.items():
|
|
487
474
|
color = what.tracked_category.value or "green"
|
|
@@ -489,8 +476,7 @@ class PythonInspector:
|
|
|
489
476
|
report.append(runez.short(overview))
|
|
490
477
|
|
|
491
478
|
if verbose:
|
|
492
|
-
|
|
493
|
-
report.append(runez.joined(pb, delimiter="\n"))
|
|
479
|
+
report.append(self.full_so_report.ok.report(verbose=True))
|
|
494
480
|
|
|
495
481
|
report = runez.joined(report or self.output, delimiter="\n")
|
|
496
482
|
return runez.joined(report, delimiter="\n")
|
|
@@ -530,30 +516,32 @@ class PythonInspector:
|
|
|
530
516
|
return PythonInspector.parsed_version(output.output or output.error)
|
|
531
517
|
|
|
532
518
|
|
|
533
|
-
def _find_parent_subfolder(folder, basename):
|
|
519
|
+
def _find_parent_subfolder(folder: Path | None, basename: str) -> Path | None:
|
|
534
520
|
while folder and len(folder.parts) > 1:
|
|
535
521
|
if folder.name == basename:
|
|
536
522
|
return folder
|
|
537
523
|
|
|
538
524
|
folder = folder.parent
|
|
539
525
|
|
|
526
|
+
return None
|
|
527
|
+
|
|
540
528
|
|
|
541
529
|
class FullSoReport:
|
|
542
530
|
def __init__(self, inspector: PythonInspector):
|
|
543
531
|
self.inspector = inspector
|
|
544
532
|
self.size = 0
|
|
545
|
-
self.lib_tracker = Tracker(
|
|
546
|
-
self.ok = Tracker(
|
|
547
|
-
self.problematic = Tracker(
|
|
533
|
+
self.lib_tracker = Tracker()
|
|
534
|
+
self.ok = Tracker("OK")
|
|
535
|
+
self.problematic = Tracker("problematic")
|
|
548
536
|
self.libpython_so = []
|
|
549
537
|
self.lib_static = []
|
|
550
538
|
for path in find_libs(self.inspector.lib_folder):
|
|
551
|
-
if path.name.endswith(".a"):
|
|
539
|
+
if path.name.endswith(".a"):
|
|
552
540
|
self.lib_static.append(self.inspector.relative_path(path))
|
|
553
541
|
continue
|
|
554
542
|
|
|
555
543
|
info = SoInfo(inspector, path)
|
|
556
|
-
if path.name.startswith("libpython"):
|
|
544
|
+
if path.name.startswith("libpython"):
|
|
557
545
|
self.libpython_so.append(info)
|
|
558
546
|
|
|
559
547
|
self.lib_tracker.add(info)
|
|
@@ -564,21 +552,22 @@ class FullSoReport:
|
|
|
564
552
|
def __repr__(self):
|
|
565
553
|
return runez.joined(".so files: %s" % runez.represented_bytesize(self.size), self.problematic, self.ok, delimiter=", ")
|
|
566
554
|
|
|
567
|
-
def get_problem(self, portable) -> str:
|
|
555
|
+
def get_problem(self, portable) -> str | None:
|
|
568
556
|
if portable:
|
|
569
|
-
allowed = PPG.config.get_value("allowed-system-libs")
|
|
557
|
+
allowed: str | None = PPG.config.get_value("allowed-system-libs")
|
|
570
558
|
if allowed:
|
|
571
559
|
# allowed-system-libs needs to be defined for the check to occur (opt-in)
|
|
572
|
-
|
|
560
|
+
rx_allowed = re.compile(allowed)
|
|
573
561
|
uses_system = [x.relative_path for x in self.lib_tracker.category[LibType.system].items]
|
|
574
|
-
if
|
|
575
|
-
uses_system = [x for x in uses_system if not allowed.match(x)]
|
|
562
|
+
uses_system = [x for x in uses_system if not rx_allowed.match(x)]
|
|
576
563
|
|
|
577
564
|
if uses_system:
|
|
578
565
|
return "Uses system libs: %s" % runez.red(runez.joined(uses_system))
|
|
579
566
|
|
|
580
|
-
if self.problematic:
|
|
581
|
-
return
|
|
567
|
+
if self.problematic:
|
|
568
|
+
return self.problematic.report()
|
|
582
569
|
|
|
583
570
|
if not runez.DRYRUN and not self.ok:
|
|
584
571
|
return "Internal error: %s" % runez.red("no OK libs found")
|
|
572
|
+
|
|
573
|
+
return None
|
portable_python/tracking.py
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
+
import abc
|
|
2
|
+
import enum
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
|
|
1
5
|
import runez
|
|
2
6
|
|
|
3
7
|
|
|
4
|
-
class
|
|
5
|
-
|
|
8
|
+
class LibType(enum.Enum):
|
|
9
|
+
"""Categorization for dynamic libs, value being the color we want to show them as"""
|
|
10
|
+
|
|
11
|
+
base = ""
|
|
12
|
+
lib_static = "static"
|
|
13
|
+
libpython_so = "dynamic"
|
|
14
|
+
missing = "red"
|
|
15
|
+
other = "brown"
|
|
16
|
+
system = "blue"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Trackable(abc.ABC):
|
|
20
|
+
"""A file (dynamic lib, .so, ...) that can be tracked by a `Tracker`"""
|
|
21
|
+
|
|
22
|
+
relative_path: str
|
|
23
|
+
tracked_category: LibType # Set by leaf trackables only, the ones yielded by `__iter__()`
|
|
6
24
|
|
|
7
|
-
def __eq__(self, other):
|
|
25
|
+
def __eq__(self, other: object) -> bool:
|
|
8
26
|
return str(self) == str(other)
|
|
9
27
|
|
|
10
|
-
def __hash__(self):
|
|
28
|
+
def __hash__(self) -> int:
|
|
11
29
|
return hash(str(self))
|
|
12
30
|
|
|
13
|
-
def __iter__(self):
|
|
31
|
+
def __iter__(self) -> Iterator["Trackable"]:
|
|
14
32
|
yield self
|
|
15
33
|
|
|
34
|
+
@abc.abstractmethod
|
|
35
|
+
def represented(self, verbose: bool = False) -> str:
|
|
36
|
+
"""Textual representation, for reports"""
|
|
37
|
+
|
|
16
38
|
|
|
17
39
|
class TrackedCollection:
|
|
18
|
-
def __init__(self, name):
|
|
40
|
+
def __init__(self, name: str):
|
|
19
41
|
self.name = name
|
|
20
|
-
self.items = []
|
|
42
|
+
self.items: list[Trackable] = []
|
|
21
43
|
|
|
22
44
|
def __repr__(self):
|
|
23
45
|
return "%s %s" % (len(self.items), self.name)
|
|
@@ -25,50 +47,30 @@ class TrackedCollection:
|
|
|
25
47
|
def __bool__(self):
|
|
26
48
|
return bool(self.items)
|
|
27
49
|
|
|
28
|
-
def add(self, item):
|
|
50
|
+
def add(self, item: Trackable):
|
|
29
51
|
if item not in self.items:
|
|
30
52
|
self.items.append(item)
|
|
31
53
|
|
|
32
|
-
def represented(self, verbose=False):
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
yield item.represented(verbose=verbose)
|
|
54
|
+
def represented(self, verbose: bool = False) -> Iterator[str]:
|
|
55
|
+
for item in self.items:
|
|
56
|
+
yield item.represented(verbose=verbose)
|
|
36
57
|
|
|
37
58
|
|
|
38
59
|
class Tracker(TrackedCollection):
|
|
39
|
-
def __init__(self,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self.
|
|
43
|
-
self.category = {}
|
|
44
|
-
self.users = {}
|
|
45
|
-
for x in enum:
|
|
46
|
-
c = TrackedCollection("%s %s" % (x.name, self.kind))
|
|
47
|
-
self.category[x] = c
|
|
48
|
-
|
|
49
|
-
def add(self, item):
|
|
50
|
-
if item not in self.items:
|
|
51
|
-
self.items.append(item)
|
|
60
|
+
def __init__(self, name: str = "lib"):
|
|
61
|
+
super().__init__(name)
|
|
62
|
+
self.category = {x: TrackedCollection(f"{x.name} lib") for x in LibType}
|
|
63
|
+
self.users: dict[Trackable, set[Trackable]] = {}
|
|
52
64
|
|
|
65
|
+
def add(self, item: Trackable):
|
|
66
|
+
super().add(item)
|
|
53
67
|
for trackable in item:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
u = set()
|
|
61
|
-
self.users[trackable] = u
|
|
62
|
-
|
|
63
|
-
u.add(item)
|
|
64
|
-
|
|
65
|
-
def represented(self, verbose=False):
|
|
66
|
-
report = []
|
|
67
|
-
if self.items:
|
|
68
|
-
for item in self.items:
|
|
69
|
-
report.append(item.represented(verbose))
|
|
70
|
-
|
|
71
|
-
report = runez.joined(report, delimiter="\n")
|
|
68
|
+
self.category[trackable.tracked_category].add(trackable)
|
|
69
|
+
if trackable is not item:
|
|
70
|
+
self.users.setdefault(trackable, set()).add(item)
|
|
71
|
+
|
|
72
|
+
def report(self, verbose: bool = False) -> str:
|
|
73
|
+
report = runez.joined(self.represented(verbose), delimiter="\n")
|
|
72
74
|
if verbose or report:
|
|
73
75
|
report = "\n-- %s\n%s" % (runez.colored(self, "bold"), report)
|
|
74
76
|
|