bundleup 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {bundleup-0.2.0 → bundleup-0.2.1}/PKG-INFO +1 -1
- {bundleup-0.2.0 → bundleup-0.2.1}/pyproject.toml +1 -1
- {bundleup-0.2.0 → bundleup-0.2.1}/pyproject.toml.orig +1 -1
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/__init__.py +1 -1
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_build.py +145 -57
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_bytecode.py +52 -13
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_cache.py +81 -12
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_check.py +129 -35
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_cli.py +192 -21
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_config.py +129 -30
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_coverage.py +95 -21
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_exe.py +153 -45
- bundleup-0.2.1/src/bundleup/_imports.py +493 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_loader.py +457 -104
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_outputs.py +34 -26
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_payload.py +135 -46
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_platforms.py +79 -16
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_python.py +175 -59
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_runtime.py +178 -20
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_sitecustomize.py +13 -2
- bundleup-0.2.1/src/bundleup/_smoke.py +291 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_source.py +157 -26
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_uv.py +509 -84
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_verify.py +294 -40
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_zipwriter.py +5 -1
- bundleup-0.2.0/src/bundleup/_imports.py +0 -248
- bundleup-0.2.0/src/bundleup/_smoke.py +0 -158
- {bundleup-0.2.0 → bundleup-0.2.1}/LICENSE +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/README.md +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/__main__.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_errors.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_formats.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_steps.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_term.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_text.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/_toml.py +0 -0
- {bundleup-0.2.0 → bundleup-0.2.1}/src/bundleup/py.typed +0 -0
|
@@ -119,12 +119,14 @@ class BuildOptions:
|
|
|
119
119
|
object.__setattr__(self, "output", Path(self.output))
|
|
120
120
|
if self.python is not None:
|
|
121
121
|
py_raw = [self.python] if isinstance(self.python, str) else list(self.python)
|
|
122
|
-
py_items = _split_items([*py_raw, *self.more_pythons], check_path=True)
|
|
122
|
+
py_items = _split_items([*py_raw, *self.more_pythons], check_path=True, dedup=True)
|
|
123
123
|
object.__setattr__(self, "python", py_items[0] if py_items else None)
|
|
124
124
|
object.__setattr__(self, "more_pythons", tuple(py_items[1:]))
|
|
125
125
|
elif self.more_pythons:
|
|
126
126
|
object.__setattr__(
|
|
127
|
-
self,
|
|
127
|
+
self,
|
|
128
|
+
"more_pythons",
|
|
129
|
+
tuple(_split_items(self.more_pythons, check_path=True, dedup=True)),
|
|
128
130
|
)
|
|
129
131
|
if self.python_platform is not None:
|
|
130
132
|
plat_raw = (
|
|
@@ -132,12 +134,14 @@ class BuildOptions:
|
|
|
132
134
|
if isinstance(self.python_platform, str)
|
|
133
135
|
else list(self.python_platform)
|
|
134
136
|
)
|
|
135
|
-
plat_items = _split_items([*plat_raw, *self.more_python_platforms])
|
|
137
|
+
plat_items = _split_items([*plat_raw, *self.more_python_platforms], dedup=True)
|
|
136
138
|
object.__setattr__(self, "python_platform", plat_items[0] if plat_items else None)
|
|
137
139
|
object.__setattr__(self, "more_python_platforms", tuple(plat_items[1:]))
|
|
138
140
|
elif self.more_python_platforms:
|
|
139
141
|
object.__setattr__(
|
|
140
|
-
self,
|
|
142
|
+
self,
|
|
143
|
+
"more_python_platforms",
|
|
144
|
+
tuple(_split_items(self.more_python_platforms, dedup=True)),
|
|
141
145
|
)
|
|
142
146
|
ext_raw = [self.external] if isinstance(self.external, str) else list(self.external)
|
|
143
147
|
object.__setattr__(self, "external", tuple(_split_items(ext_raw, dedup=True)))
|
|
@@ -236,7 +240,7 @@ def build(
|
|
|
236
240
|
"""
|
|
237
241
|
options, fmt = _settle(options)
|
|
238
242
|
if options.output is not None:
|
|
239
|
-
if not options.output.absolute().name:
|
|
243
|
+
if not str(options.output).strip() or not options.output.absolute().name.strip():
|
|
240
244
|
raise UsageError(f"-o {options.output} has no file name")
|
|
241
245
|
_validate_output_path(options.output, fmt, "app.pyz")
|
|
242
246
|
report = progress or ignore
|
|
@@ -273,6 +277,15 @@ def build(
|
|
|
273
277
|
)
|
|
274
278
|
p = prepared[0]
|
|
275
279
|
p_diagnostics = _merged_diagnostics(prepared)
|
|
280
|
+
if options.smoke is not None and fmt in LOADED:
|
|
281
|
+
smoke_p = _smoke_target(prepared, exe=fmt == "exe")
|
|
282
|
+
if smoke_p is None:
|
|
283
|
+
p_diagnostics.append(_SMOKE_SKIPPED)
|
|
284
|
+
elif smoke_p.entry is not None and smoke_p.entry.kind == "python" and not options.smoke:
|
|
285
|
+
raise UsageError(
|
|
286
|
+
"--smoke needs a script to run for --entry python",
|
|
287
|
+
hint="for example: --smoke 'scripts/tool.py --help'",
|
|
288
|
+
)
|
|
276
289
|
failing = [d for d in p_diagnostics if d.level == "error" or options.strict]
|
|
277
290
|
if failing:
|
|
278
291
|
raise CheckFailedError(
|
|
@@ -335,7 +348,9 @@ def build(
|
|
|
335
348
|
reach=Portability(any_os=False, any_cpu=False),
|
|
336
349
|
)
|
|
337
350
|
prepared = [p]
|
|
338
|
-
if options.smoke is not None
|
|
351
|
+
if options.smoke is not None and not any(
|
|
352
|
+
d.code == "smoke-skipped" for d in diagnostics
|
|
353
|
+
):
|
|
339
354
|
steps.start("smoke")
|
|
340
355
|
smoked, skipped = _smoke_run(prepared, output, options.smoke, exe=fmt == "exe")
|
|
341
356
|
diagnostics += skipped
|
|
@@ -395,48 +410,58 @@ def _combinations(options: BuildOptions) -> list[BuildOptions]:
|
|
|
395
410
|
|
|
396
411
|
|
|
397
412
|
# CPU names as Python reports them -> as targets name them.
|
|
398
|
-
CPUS = {"arm64": "aarch64", "amd64": "x86_64", "x64": "x86_64"}
|
|
413
|
+
CPUS = {"arm64": "aarch64", "amd64": "x86_64", "x64": "x86_64", "x86": "i686", "i386": "i686"}
|
|
399
414
|
|
|
415
|
+
_SMOKE_SKIPPED = Diagnostic(
|
|
416
|
+
"smoke-skipped",
|
|
417
|
+
"warning",
|
|
418
|
+
"--smoke: the bundle is only for other platforms, so it can't run here",
|
|
419
|
+
hint="run the smoke test on a machine it's built for (CI, say)",
|
|
420
|
+
)
|
|
400
421
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
) -> tuple[SmokeResult | None, list[Diagnostic]]:
|
|
404
|
-
"""`--smoke`: run the bundle with the interpreter of a payload that fits this machine (the
|
|
405
|
-
one the build used); a bundle only for other platforms can't run here: a warning."""
|
|
422
|
+
|
|
423
|
+
def _smoke_target(prepared: list[Prepared], *, exe: bool = False) -> Prepared | None:
|
|
406
424
|
import platform
|
|
407
425
|
|
|
408
426
|
here = CPUS.get(platform.machine().lower(), platform.machine().lower())
|
|
409
427
|
for p in prepared:
|
|
410
428
|
machine = CPUS.get(p.target.machine.lower(), p.target.machine.lower())
|
|
411
|
-
same_os = p.reach.any_os or p.target.platform == sys.platform
|
|
412
|
-
|
|
429
|
+
same_os = (not exe and p.reach.any_os) or p.target.platform == sys.platform
|
|
430
|
+
any_cpu = not exe and (p.reach.any_cpu or not p.native)
|
|
431
|
+
needs = runtime_needs(p.site, p.target)
|
|
413
432
|
libc = needs.libc
|
|
414
433
|
plat = p.target.python_platform
|
|
415
434
|
if exe and plat and plat.sys_platform == "linux" and libc is None:
|
|
416
435
|
libc = ("musl", (1, 2)) if plat.musl else ("glibc", (2, 17))
|
|
417
436
|
fits_system = _loader._libc_fits(libc) and _loader._macos_fits(needs.macos)
|
|
418
|
-
if same_os and (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
437
|
+
if same_os and (any_cpu or machine == here) and fits_system:
|
|
438
|
+
return p
|
|
439
|
+
return None
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def _smoke_run(
|
|
443
|
+
prepared: list[Prepared], output: Path, args: tuple[str, ...], *, exe: bool = False
|
|
444
|
+
) -> tuple[SmokeResult | None, list[Diagnostic]]:
|
|
445
|
+
"""`--smoke`: run the bundle with the interpreter of a payload that fits this machine (the
|
|
446
|
+
one the build used); a bundle only for other platforms can't run here: a warning."""
|
|
447
|
+
p = _smoke_target(prepared, exe=exe)
|
|
448
|
+
if p is not None:
|
|
449
|
+
if p.entry is not None and p.entry.kind == "python" and not args:
|
|
450
|
+
raise UsageError(
|
|
451
|
+
"--smoke needs a script to run for --entry python",
|
|
452
|
+
hint="for example: --smoke 'scripts/tool.py --help'",
|
|
453
|
+
)
|
|
454
|
+
python = None if exe else p.target.executable # an executable runs itself
|
|
455
|
+
return _smoke.run(output, python, args or ("--help",)), []
|
|
456
|
+
return None, [_SMOKE_SKIPPED]
|
|
434
457
|
|
|
435
458
|
|
|
436
459
|
def _lowest(combinations: list[BuildOptions]) -> tuple[int, int] | None:
|
|
437
460
|
"""The lowest Python version asked for: input without a lock is resolved from it for every
|
|
438
461
|
payload, so they all bundle the same versions (fourth review: each resolved from its own)."""
|
|
439
|
-
asked = [
|
|
462
|
+
asked = [
|
|
463
|
+
c.python for c in combinations if c.python and re.fullmatch(r"\d+\.\d+(?:\.\d+)?", c.python)
|
|
464
|
+
]
|
|
440
465
|
found = [(int(v.split(".")[0]), int(v.split(".")[1])) for v in asked]
|
|
441
466
|
return min(found) if len(found) > 1 else None
|
|
442
467
|
|
|
@@ -445,17 +470,26 @@ def _served(prepared: list[Prepared], options: BuildOptions) -> bool:
|
|
|
445
470
|
"""Whether an already prepared pure-Python payload runs on this combination too, so it needs
|
|
446
471
|
no payload of its own: its Python range covers the version and it runs on any OS (or on this
|
|
447
472
|
one, any CPU)."""
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
473
|
+
import platform as host_plat
|
|
474
|
+
|
|
475
|
+
if options.python is None and prepared:
|
|
476
|
+
wanted = prepared[0].target.version
|
|
477
|
+
else:
|
|
478
|
+
version = re.fullmatch(r"(\d+)\.(\d+)(?:\.\d+)?", options.python or "")
|
|
479
|
+
if version is None:
|
|
480
|
+
return False # uv's choice or an interpreter path: can't tell before building
|
|
481
|
+
wanted = (int(version[1]), int(version[2]))
|
|
452
482
|
platform = _platforms.parse(options.python_platform) if options.python_platform else None
|
|
483
|
+
wanted_os = platform.sys_platform if platform else sys.platform
|
|
484
|
+
raw_cpu = platform.arch if platform else host_plat.machine().lower()
|
|
485
|
+
wanted_cpu = CPUS.get(raw_cpu, raw_cpu)
|
|
453
486
|
for p in prepared:
|
|
454
487
|
if p.native or not p.pythons.contains(wanted):
|
|
455
488
|
continue
|
|
456
489
|
if p.reach.any_os:
|
|
457
490
|
return True
|
|
458
|
-
|
|
491
|
+
p_cpu = CPUS.get(p.target.machine.lower(), p.target.machine.lower())
|
|
492
|
+
if wanted_os == p.target.platform and (p.reach.any_cpu or wanted_cpu == p_cpu):
|
|
459
493
|
return True
|
|
460
494
|
return False
|
|
461
495
|
|
|
@@ -506,14 +540,21 @@ def _validate_output_path(
|
|
|
506
540
|
source: Source | None = None,
|
|
507
541
|
own: Sequence[str] = (),
|
|
508
542
|
) -> None:
|
|
543
|
+
try:
|
|
544
|
+
is_dir = output.is_dir()
|
|
545
|
+
resolved_out = output.resolve() if source is not None else None
|
|
546
|
+
except (OSError, RuntimeError) as e:
|
|
547
|
+
raise UsageError(
|
|
548
|
+
f"-o {output} cannot be accessed: {getattr(e, 'strerror', None) or e}"
|
|
549
|
+
) from None
|
|
509
550
|
if fmt == "dir":
|
|
510
551
|
check_dir_output(Path(os.path.abspath(output)))
|
|
511
|
-
elif
|
|
552
|
+
elif is_dir:
|
|
512
553
|
raise UsageError(
|
|
513
554
|
f"{output} is a directory",
|
|
514
555
|
hint=f"give a file path (for example: -o {output / default_name}), or use --format dir",
|
|
515
556
|
)
|
|
516
|
-
if source is not None and
|
|
557
|
+
if source is not None and resolved_out in _input_files(source, own):
|
|
517
558
|
what = "the input script" if source.is_script else "the project's own files"
|
|
518
559
|
raise UsageError(
|
|
519
560
|
f"-o {output.name} would overwrite {what}",
|
|
@@ -527,14 +568,19 @@ def _settle(options: BuildOptions, *, for_check: bool = False) -> tuple[BuildOpt
|
|
|
527
568
|
options, _configured = _config.apply(options, for_check=for_check)
|
|
528
569
|
if options.smoke is not None and (options.format or "pyz") not in LOADED:
|
|
529
570
|
raise UsageError(
|
|
530
|
-
"--smoke runs a .pyz or
|
|
571
|
+
"--smoke runs a .pyz, .py or executable",
|
|
531
572
|
hint=f"drop --smoke: a {options.format} output's host runs it",
|
|
532
573
|
)
|
|
533
574
|
if options.entry == "python" and (options.format or "pyz") not in LOADED:
|
|
534
575
|
raise UsageError(
|
|
535
|
-
"--entry python makes a .pyz
|
|
576
|
+
"--entry python makes a .pyz, .py or executable that runs the scripts it's given",
|
|
536
577
|
hint=f"drop --entry: a {options.format} output's host decides what runs",
|
|
537
578
|
)
|
|
579
|
+
if not for_check and options.smoke == () and options.entry == "python":
|
|
580
|
+
raise UsageError(
|
|
581
|
+
"--smoke needs a script to run for --entry python",
|
|
582
|
+
hint="for example: --smoke 'scripts/tool.py --help'",
|
|
583
|
+
)
|
|
538
584
|
if options.split is not None and (options.format or "pyz") != "pyz":
|
|
539
585
|
raise UsageError(
|
|
540
586
|
"--split cuts a .pyz into parts",
|
|
@@ -591,7 +637,13 @@ def _wheel_coverage(pylock: Path, target: Target) -> list[Diagnostic]:
|
|
|
591
637
|
if platform is None:
|
|
592
638
|
return []
|
|
593
639
|
lock = pylock.read_text(encoding="utf-8")
|
|
594
|
-
|
|
640
|
+
abiflags = target.abiflags or ""
|
|
641
|
+
found = _coverage.diagnostics(
|
|
642
|
+
_coverage.gaps(lock, platform, target.version, abiflags=abiflags),
|
|
643
|
+
platform,
|
|
644
|
+
lock,
|
|
645
|
+
abiflags=abiflags,
|
|
646
|
+
)
|
|
595
647
|
errors = [d for d in found if d.level == "error"]
|
|
596
648
|
if errors:
|
|
597
649
|
raise NoCompatibleWheelError(
|
|
@@ -606,11 +658,15 @@ def _wheel_coverage(pylock: Path, target: Target) -> list[Diagnostic]:
|
|
|
606
658
|
def _also_platforms(pylock: Path, target: Target, names: Sequence[str]) -> list[Diagnostic]:
|
|
607
659
|
"""`bundleup check` with more `--python-platform` targets: the lock-only coverage check."""
|
|
608
660
|
lock = pylock.read_text(encoding="utf-8")
|
|
661
|
+
abiflags = target.abiflags or ""
|
|
609
662
|
found: list[Diagnostic] = []
|
|
610
663
|
for name in names:
|
|
611
664
|
platform = _platforms.parse(name)
|
|
612
665
|
found += _coverage.diagnostics(
|
|
613
|
-
_coverage.gaps(lock, platform, target.version
|
|
666
|
+
_coverage.gaps(lock, platform, target.version, abiflags=abiflags),
|
|
667
|
+
platform,
|
|
668
|
+
lock,
|
|
669
|
+
abiflags=abiflags,
|
|
614
670
|
)
|
|
615
671
|
return found
|
|
616
672
|
|
|
@@ -620,7 +676,13 @@ NOT_RUN = {"tests", "test", "docs", "doc", "examples"}
|
|
|
620
676
|
|
|
621
677
|
|
|
622
678
|
def _own_code(
|
|
623
|
-
source: Source,
|
|
679
|
+
source: Source,
|
|
680
|
+
site: Path,
|
|
681
|
+
*,
|
|
682
|
+
script: str | None,
|
|
683
|
+
own: list[str],
|
|
684
|
+
entry: Entry | None,
|
|
685
|
+
owner: dict[str, _check._Owner] | None = None,
|
|
624
686
|
) -> list[tuple[str, Path, bool]]:
|
|
625
687
|
"""The code bundled from the input itself, whose imports the undeclared-import check reads:
|
|
626
688
|
the script, a folder app's modules, or the project's own installed files; with `--entry
|
|
@@ -628,17 +690,26 @@ def _own_code(
|
|
|
628
690
|
neighbours import too, as when python runs a script)."""
|
|
629
691
|
is_py_entry = entry is not None and entry.kind == "python"
|
|
630
692
|
script_target = entry.target if entry is not None and entry.kind == "script" else None
|
|
631
|
-
|
|
693
|
+
script_dir = script_target.rpartition("/")[0] if script_target and "/" in script_target else ""
|
|
694
|
+
code = [(source.path.name, source.path, False)] if script else []
|
|
632
695
|
code += [
|
|
633
|
-
(
|
|
696
|
+
(
|
|
697
|
+
rel,
|
|
698
|
+
site / rel,
|
|
699
|
+
is_py_entry
|
|
700
|
+
or rel == script_target
|
|
701
|
+
or (bool(script_dir) and rel.rpartition("/")[0] == script_dir),
|
|
702
|
+
)
|
|
703
|
+
for rel in own
|
|
704
|
+
if rel.endswith(".py")
|
|
634
705
|
]
|
|
635
706
|
if not source.is_script and not source.app:
|
|
636
707
|
project = canonicalize_name(source.name)
|
|
637
|
-
owned = _check.owners(site, project=project)
|
|
708
|
+
owned = owner if owner is not None else _check.owners(site, project=project)
|
|
638
709
|
code += [
|
|
639
710
|
(rel, site / rel, False)
|
|
640
|
-
for rel,
|
|
641
|
-
if
|
|
711
|
+
for rel, who in sorted(owned.items())
|
|
712
|
+
if who.name == project and rel.endswith(".py") and (site / rel).is_file()
|
|
642
713
|
]
|
|
643
714
|
if is_py_entry and not source.app:
|
|
644
715
|
# A project's scripts anywhere under it (as git sees them); a script's neighbours only:
|
|
@@ -650,7 +721,10 @@ def _own_code(
|
|
|
650
721
|
folders = set(parts[:-1])
|
|
651
722
|
# Skip tests and docs, and the project's own packages anywhere (src/pkg/...): those
|
|
652
723
|
# are read from the payload. (`src` itself isn't skipped; sixth review.)
|
|
653
|
-
|
|
724
|
+
top_mods = {parts[0].removesuffix(".py")}
|
|
725
|
+
if parts[:1] == ["src"] and len(parts) == 2:
|
|
726
|
+
top_mods.add(parts[1].removesuffix(".py"))
|
|
727
|
+
mine = (folders | top_mods) & bundled
|
|
654
728
|
if file == source.path or folders & NOT_RUN or mine:
|
|
655
729
|
continue
|
|
656
730
|
code.append((rel, file, True))
|
|
@@ -738,7 +812,7 @@ def _prepare(
|
|
|
738
812
|
if options.external:
|
|
739
813
|
me = canonicalize_name(source.name)
|
|
740
814
|
for ext in options.external:
|
|
741
|
-
if canonicalize_name(
|
|
815
|
+
if canonicalize_name(re.split(r"[<>=!~;\[\s]", ext, maxsplit=1)[0].strip()) == me:
|
|
742
816
|
raise UsageError(
|
|
743
817
|
f"--external {ext}: can't exclude {source.name} itself from the bundle",
|
|
744
818
|
hint="--external is for dependencies that the host Python already provides",
|
|
@@ -762,6 +836,7 @@ def _prepare(
|
|
|
762
836
|
stage=stage,
|
|
763
837
|
progress=progress,
|
|
764
838
|
external=options.external,
|
|
839
|
+
markers=target.markers,
|
|
765
840
|
)
|
|
766
841
|
pylock = exported.pylock
|
|
767
842
|
coverage = _wheel_coverage(pylock, target) # before installing: a precise error, early
|
|
@@ -801,13 +876,16 @@ def _prepare(
|
|
|
801
876
|
def run_python(cmd: list[str]) -> str:
|
|
802
877
|
return run(cmd, what="checking the code", progress=progress, error=BundleupError)
|
|
803
878
|
|
|
879
|
+
project_name = canonicalize_name(source.name)
|
|
880
|
+
site_owners = _check.owners(site, project=project_name, script=script, own=own)
|
|
804
881
|
diagnostics, sizes = _check.analyze(
|
|
805
882
|
site,
|
|
806
|
-
project=
|
|
883
|
+
project=project_name,
|
|
807
884
|
target=target,
|
|
808
885
|
run=run_python,
|
|
809
886
|
script=script,
|
|
810
887
|
own=own,
|
|
888
|
+
owner=site_owners,
|
|
811
889
|
)
|
|
812
890
|
secrets = [rel for rel in own if looks_secret(rel)]
|
|
813
891
|
if secrets:
|
|
@@ -822,13 +900,16 @@ def _prepare(
|
|
|
822
900
|
file=secrets[0],
|
|
823
901
|
)
|
|
824
902
|
)
|
|
825
|
-
code = _own_code(source, site, script=script, own=own, entry=entry)
|
|
903
|
+
code = _own_code(source, site, script=script, own=own, entry=entry, owner=site_owners)
|
|
826
904
|
provided = _imports.provided_by(site) | _imports.external_modules(options.external)
|
|
905
|
+
beside_cache: dict[Path, set[str]] = {}
|
|
827
906
|
imported = [
|
|
828
907
|
(
|
|
829
908
|
shown,
|
|
830
909
|
_imports.imports_with_lines(path),
|
|
831
|
-
_imports.top_level_modules(path.parent)
|
|
910
|
+
beside_cache.setdefault(path.parent, _imports.top_level_modules(path.parent))
|
|
911
|
+
if beside
|
|
912
|
+
else set(),
|
|
832
913
|
)
|
|
833
914
|
for shown, path, beside in code
|
|
834
915
|
]
|
|
@@ -842,15 +923,16 @@ def _prepare(
|
|
|
842
923
|
pythons = python_range(site, pylock=pylock, target=target, source=source, native=native)
|
|
843
924
|
pythons, narrowed = _check.oldest_python(
|
|
844
925
|
site,
|
|
845
|
-
project=
|
|
926
|
+
project=project_name,
|
|
846
927
|
script=script,
|
|
847
928
|
own=own,
|
|
848
929
|
pythons=pythons,
|
|
849
930
|
target=target,
|
|
850
931
|
run=run_python,
|
|
932
|
+
owner=site_owners,
|
|
851
933
|
)
|
|
852
934
|
diagnostics += narrowed
|
|
853
|
-
every_import: set[str] = set().union(*(set(names) for _shown, names,
|
|
935
|
+
every_import: set[str] = set().union(*(set(names) - local for _shown, names, local in imported))
|
|
854
936
|
pythons, by_stdlib = _check.stdlib_range(pythons, target.version, every_import, provided)
|
|
855
937
|
diagnostics += by_stdlib
|
|
856
938
|
reach = portability(pylock, target=target, pythons=pythons, native=native)
|
|
@@ -935,9 +1017,15 @@ def check(
|
|
|
935
1017
|
def _matrix(pylock: Path, source: Source) -> list[_coverage.MatrixCell]:
|
|
936
1018
|
"""`check --matrix`: wheel coverage for every platform and every Python the project allows
|
|
937
1019
|
(and the lock covers: one resolved at build time starts at the target's version)."""
|
|
1020
|
+
from packaging.specifiers import InvalidSpecifier
|
|
1021
|
+
|
|
938
1022
|
text = pylock.read_text(encoding="utf-8")
|
|
939
|
-
|
|
940
|
-
|
|
1023
|
+
raw_covered = tomllib.loads(text).get("requires-python")
|
|
1024
|
+
covered = raw_covered if isinstance(raw_covered, str) else ""
|
|
1025
|
+
try:
|
|
1026
|
+
spec = SpecifierSet(source.requires_python or "") & SpecifierSet(covered)
|
|
1027
|
+
except (InvalidSpecifier, TypeError):
|
|
1028
|
+
spec = SpecifierSet()
|
|
941
1029
|
pythons = [
|
|
942
1030
|
v
|
|
943
1031
|
for v in _coverage.MATRIX_PYTHONS
|
|
@@ -35,7 +35,7 @@ args = [
|
|
|
35
35
|
[os.path.dirname(f) for f in files],
|
|
36
36
|
]
|
|
37
37
|
n = len(files)
|
|
38
|
-
rest = [[
|
|
38
|
+
rest = [[True] * n, [None] * n, [2] * n, [False] * n, [-1] * n, [mode] * n]
|
|
39
39
|
if workers == 1:
|
|
40
40
|
list(map(compileall.compile_file, *args, *rest))
|
|
41
41
|
else:
|
|
@@ -76,9 +76,12 @@ class Distribution:
|
|
|
76
76
|
|
|
77
77
|
def cache_dir() -> Path:
|
|
78
78
|
"""Where compiled bytecode is kept between builds (BUNDLEUP_BUILD_CACHE overrides it)."""
|
|
79
|
-
override = os.environ.get("BUNDLEUP_BUILD_CACHE")
|
|
79
|
+
override = os.environ.get("BUNDLEUP_BUILD_CACHE", "").strip()
|
|
80
80
|
if override:
|
|
81
81
|
return Path(override) / "bytecode"
|
|
82
|
+
cache_override = os.environ.get("BUNDLEUP_CACHE", "").strip()
|
|
83
|
+
if cache_override:
|
|
84
|
+
return Path(cache_override) / "build" / "bytecode"
|
|
82
85
|
if sys.platform == "darwin":
|
|
83
86
|
base = Path.home() / "Library" / "Caches"
|
|
84
87
|
elif sys.platform == "win32":
|
|
@@ -128,27 +131,50 @@ def _extra_distribution(
|
|
|
128
131
|
def _restore(dist: Distribution, cache: Path, site: Path) -> bool:
|
|
129
132
|
"""Copy a distribution's cached bytecode into `site`. False if there's none."""
|
|
130
133
|
cached = cache / dist.key
|
|
131
|
-
if not cached.is_dir():
|
|
134
|
+
if cached.is_symlink() or not cached.is_dir():
|
|
135
|
+
return False
|
|
136
|
+
files = walk_files(cached)
|
|
137
|
+
if dist.sources and not files:
|
|
132
138
|
return False
|
|
133
139
|
made: set[str] = set()
|
|
134
|
-
for rel, source in
|
|
140
|
+
for rel, source in files:
|
|
141
|
+
if os.path.islink(source):
|
|
142
|
+
return False
|
|
135
143
|
target = os.path.join(site, rel)
|
|
136
144
|
parent = os.path.dirname(target)
|
|
137
145
|
if parent not in made:
|
|
138
|
-
|
|
146
|
+
try:
|
|
147
|
+
os.makedirs(parent, exist_ok=True)
|
|
148
|
+
except PermissionError:
|
|
149
|
+
p_parent = os.path.dirname(parent)
|
|
150
|
+
if os.path.isdir(p_parent):
|
|
151
|
+
os.chmod(p_parent, os.stat(p_parent).st_mode | 0o700)
|
|
152
|
+
os.makedirs(parent, exist_ok=True)
|
|
139
153
|
made.add(parent)
|
|
140
|
-
|
|
141
|
-
|
|
154
|
+
try:
|
|
155
|
+
shutil.copyfile(source, target)
|
|
156
|
+
except PermissionError:
|
|
157
|
+
try:
|
|
158
|
+
os.chmod(parent, os.stat(parent).st_mode | 0o700)
|
|
159
|
+
if os.path.exists(target):
|
|
160
|
+
os.chmod(target, os.stat(target).st_mode | 0o200)
|
|
161
|
+
shutil.copyfile(source, target)
|
|
162
|
+
except OSError:
|
|
163
|
+
return False
|
|
164
|
+
except OSError:
|
|
165
|
+
return False
|
|
166
|
+
return cached.is_dir() and not cached.is_symlink()
|
|
142
167
|
|
|
143
168
|
|
|
144
169
|
def _store(dist: Distribution, cache: Path, site: Path, cache_tag: str) -> None:
|
|
145
170
|
"""Keep a distribution's freshly compiled bytecode, atomically (parallel builds may race)."""
|
|
146
171
|
final = cache / dist.key
|
|
147
|
-
if final.exists():
|
|
172
|
+
if not dist.sources or final.exists():
|
|
148
173
|
return
|
|
149
|
-
|
|
150
|
-
tmp = Path(tempfile.mkdtemp(prefix=f".{dist.key}-", dir=cache))
|
|
174
|
+
tmp: Path | None = None
|
|
151
175
|
try:
|
|
176
|
+
cache.mkdir(parents=True, exist_ok=True)
|
|
177
|
+
tmp = Path(tempfile.mkdtemp(prefix=f".{dist.key}-", dir=cache))
|
|
152
178
|
for source in dist.sources:
|
|
153
179
|
pyc = pyc_path(source, cache_tag)
|
|
154
180
|
if (site / pyc).is_file():
|
|
@@ -156,7 +182,10 @@ def _store(dist: Distribution, cache: Path, site: Path, cache_tag: str) -> None:
|
|
|
156
182
|
shutil.copyfile(site / pyc, tmp / pyc)
|
|
157
183
|
tmp.rename(final)
|
|
158
184
|
except OSError:
|
|
159
|
-
|
|
185
|
+
pass # someone else stored it first, or no space
|
|
186
|
+
finally:
|
|
187
|
+
if tmp is not None and tmp.exists():
|
|
188
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
160
189
|
|
|
161
190
|
|
|
162
191
|
def precompile(
|
|
@@ -182,10 +211,20 @@ def precompile(
|
|
|
182
211
|
covered = {source for dist in dists for source in dist.sources}
|
|
183
212
|
extra = _extra_distribution(site, covered, python_identity=python_identity)
|
|
184
213
|
all_dists = [*dists, extra] if extra is not None else dists
|
|
185
|
-
restored = [
|
|
186
|
-
fresh = [
|
|
214
|
+
restored: list[Distribution] = []
|
|
215
|
+
fresh: list[Distribution] = []
|
|
216
|
+
for dist in all_dists:
|
|
217
|
+
(restored if _restore(dist, cache, site) else fresh).append(dist)
|
|
187
218
|
todo = [source for dist in fresh for source in dist.sources]
|
|
188
219
|
if todo:
|
|
220
|
+
for rel_dir in {os.path.dirname(s) for s in todo}:
|
|
221
|
+
d = os.path.join(site, rel_dir) if rel_dir else str(site)
|
|
222
|
+
for p in (d, os.path.join(d, "__pycache__")):
|
|
223
|
+
try:
|
|
224
|
+
if os.path.isdir(p) and (os.stat(p).st_mode & 0o700) != 0o700:
|
|
225
|
+
os.chmod(p, os.stat(p).st_mode | 0o700)
|
|
226
|
+
except OSError:
|
|
227
|
+
pass
|
|
189
228
|
listing = site.parent / "compile-list.txt"
|
|
190
229
|
listing.write_text("\n".join(todo), encoding="utf-8")
|
|
191
230
|
workers = 0 if len(todo) >= PARALLEL_FROM else 1
|