Skip to content

Commit e23e167

Browse files
committed
Merge branch 'main' into ios-linkable-dylib
2 parents e209bee + 17636ba commit e23e167

59 files changed

Lines changed: 4927 additions & 4114 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/jit.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ jobs:
5757
fail-fast: false
5858
matrix:
5959
target:
60-
# To re-enable later when we support these.
61-
# - i686-pc-windows-msvc/msvc
62-
# - x86_64-pc-windows-msvc/msvc
63-
# - aarch64-pc-windows-msvc/msvc
60+
- i686-pc-windows-msvc/msvc
61+
- x86_64-pc-windows-msvc/msvc
62+
- aarch64-pc-windows-msvc/msvc
6463
- x86_64-apple-darwin/clang
6564
- aarch64-apple-darwin/clang
6665
- x86_64-unknown-linux-gnu/gcc
@@ -71,16 +70,15 @@ jobs:
7170
llvm:
7271
- 21
7372
include:
74-
# To re-enable later when we support these.
75-
# - target: i686-pc-windows-msvc/msvc
76-
# architecture: Win32
77-
# runner: windows-2022
78-
# - target: x86_64-pc-windows-msvc/msvc
79-
# architecture: x64
80-
# runner: windows-2022
81-
# - target: aarch64-pc-windows-msvc/msvc
82-
# architecture: ARM64
83-
# runner: windows-11-arm
73+
- target: i686-pc-windows-msvc/msvc
74+
architecture: Win32
75+
runner: windows-2022
76+
- target: x86_64-pc-windows-msvc/msvc
77+
architecture: x64
78+
runner: windows-2022
79+
- target: aarch64-pc-windows-msvc/msvc
80+
architecture: ARM64
81+
runner: windows-11-arm
8482
- target: x86_64-apple-darwin/clang
8583
architecture: x86_64
8684
runner: macos-15-intel

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
rev: v0.13.2
44
hooks:
5+
- id: ruff-check
6+
name: Run Ruff (lint) on Apple/
7+
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
8+
files: ^Apple/
59
- id: ruff-check
610
name: Run Ruff (lint) on Doc/
711
args: [--exit-non-zero-on-fix]
@@ -30,6 +34,10 @@ repos:
3034
name: Run Ruff (lint) on Tools/wasm/
3135
args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml]
3236
files: ^Tools/wasm/
37+
- id: ruff-format
38+
name: Run Ruff (format) on Apple/
39+
args: [--exit-non-zero-on-fix, --config=Apple/.ruff.toml]
40+
files: ^Apple
3341
- id: ruff-format
3442
name: Run Ruff (format) on Doc/
3543
args: [--check]

Apple/.ruff.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extend = "../.ruff.toml" # Inherit the project-wide settings
2+
3+
[format]
4+
preview = true
5+
docstring-code-format = true
6+
7+
[lint]
8+
select = [
9+
"C4", # flake8-comprehensions
10+
"E", # pycodestyle
11+
"F", # pyflakes
12+
"I", # isort
13+
"ISC", # flake8-implicit-str-concat
14+
"LOG", # flake8-logging
15+
"PGH", # pygrep-hooks
16+
"PT", # flake8-pytest-style
17+
"PYI", # flake8-pyi
18+
"RUF100", # Ban unused `# noqa` comments
19+
"UP", # pyupgrade
20+
"W", # pycodestyle
21+
"YTT", # flake8-2020
22+
]

Apple/__main__.py

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@
4646
import sys
4747
import sysconfig
4848
import time
49-
from collections.abc import Sequence
49+
from collections.abc import Callable, Sequence
5050
from contextlib import contextmanager
5151
from datetime import datetime, timezone
5252
from os.path import basename, relpath
5353
from pathlib import Path
5454
from subprocess import CalledProcessError
55-
from typing import Callable
5655

5756
EnvironmentT = dict[str, str]
5857
ArgsT = Sequence[str | Path]
@@ -140,17 +139,15 @@ def print_env(env: EnvironmentT) -> None:
140139
def apple_env(host: str) -> EnvironmentT:
141140
"""Construct an Apple development environment for the given host."""
142141
env = {
143-
"PATH": ":".join(
144-
[
145-
str(PYTHON_DIR / "Apple/iOS/Resources/bin"),
146-
str(subdir(host) / "prefix"),
147-
"/usr/bin",
148-
"/bin",
149-
"/usr/sbin",
150-
"/sbin",
151-
"/Library/Apple/usr/bin",
152-
]
153-
),
142+
"PATH": ":".join([
143+
str(PYTHON_DIR / "Apple/iOS/Resources/bin"),
144+
str(subdir(host) / "prefix"),
145+
"/usr/bin",
146+
"/bin",
147+
"/usr/sbin",
148+
"/sbin",
149+
"/Library/Apple/usr/bin",
150+
]),
154151
}
155152

156153
return env
@@ -196,14 +193,10 @@ def clean(context: argparse.Namespace, target: str = "all") -> None:
196193
paths.append(target)
197194

198195
if target in {"all", "hosts", "test"}:
199-
paths.extend(
200-
[
201-
path.name
202-
for path in CROSS_BUILD_DIR.glob(
203-
f"{context.platform}-testbed.*"
204-
)
205-
]
206-
)
196+
paths.extend([
197+
path.name
198+
for path in CROSS_BUILD_DIR.glob(f"{context.platform}-testbed.*")
199+
])
207200

208201
for path in paths:
209202
delete_path(path)
@@ -352,18 +345,16 @@ def download(url: str, target_dir: Path) -> Path:
352345

353346
out_path = target_path / basename(url)
354347
if not Path(out_path).is_file():
355-
run(
356-
[
357-
"curl",
358-
"-Lf",
359-
"--retry",
360-
"5",
361-
"--retry-all-errors",
362-
"-o",
363-
out_path,
364-
url,
365-
]
366-
)
348+
run([
349+
"curl",
350+
"-Lf",
351+
"--retry",
352+
"5",
353+
"--retry-all-errors",
354+
"-o",
355+
out_path,
356+
url,
357+
])
367358
else:
368359
print(f"Using cached version of {basename(url)}")
369360
return out_path
@@ -468,8 +459,7 @@ def package_version(prefix_path: Path) -> str:
468459

469460

470461
def lib_platform_files(dirname, names):
471-
"""A file filter that ignores platform-specific files in the lib directory.
472-
"""
462+
"""A file filter that ignores platform-specific files in lib."""
473463
path = Path(dirname)
474464
if (
475465
path.parts[-3] == "lib"
@@ -478,15 +468,15 @@ def lib_platform_files(dirname, names):
478468
):
479469
return names
480470
elif path.parts[-2] == "lib" and path.parts[-1].startswith("python"):
481-
ignored_names = set(
471+
ignored_names = {
482472
name
483473
for name in names
484474
if (
485475
name.startswith("_sysconfigdata_")
486476
or name.startswith("_sysconfig_vars_")
487477
or name == "build-details.json"
488478
)
489-
)
479+
}
490480
elif path.parts[-1] == "lib":
491481
ignored_names = {
492482
name
@@ -505,7 +495,9 @@ def lib_non_platform_files(dirname, names):
505495
"""
506496
path = Path(dirname)
507497
if path.parts[-2] == "lib" and path.parts[-1].startswith("python"):
508-
return set(names) - lib_platform_files(dirname, names) - {"lib-dynload"}
498+
return (
499+
set(names) - lib_platform_files(dirname, names) - {"lib-dynload"}
500+
)
509501
else:
510502
return set()
511503

@@ -520,7 +512,8 @@ def create_xcframework(platform: str) -> str:
520512
package_path.mkdir()
521513
except FileExistsError:
522514
raise RuntimeError(
523-
f"{platform} XCframework already exists; do you need to run with --clean?"
515+
f"{platform} XCframework already exists; do you need to run "
516+
"with --clean?"
524517
) from None
525518

526519
frameworks = []
@@ -613,7 +606,7 @@ def create_xcframework(platform: str) -> str:
613606
print(f" - {slice_name} binaries")
614607
shutil.copytree(first_path / "bin", slice_path / "bin")
615608

616-
# Copy the include path (this will be a symlink to the framework headers)
609+
# Copy the include path (a symlink to the framework headers)
617610
print(f" - {slice_name} include files")
618611
shutil.copytree(
619612
first_path / "include",
@@ -673,7 +666,8 @@ def create_xcframework(platform: str) -> str:
673666
# statically link those libraries into a Framework, you become
674667
# responsible for providing a privacy manifest for that framework.
675668
xcprivacy_file = {
676-
"OpenSSL": subdir(host_triple) / "prefix/share/OpenSSL.xcprivacy"
669+
"OpenSSL": subdir(host_triple)
670+
/ "prefix/share/OpenSSL.xcprivacy"
677671
}
678672
print(f" - {multiarch} xcprivacy files")
679673
for module, lib in [
@@ -683,7 +677,8 @@ def create_xcframework(platform: str) -> str:
683677
shutil.copy(
684678
xcprivacy_file[lib],
685679
slice_path
686-
/ f"lib-{arch}/python{version_tag}/lib-dynload/{module}.xcprivacy",
680+
/ f"lib-{arch}/python{version_tag}"
681+
/ f"lib-dynload/{module}.xcprivacy",
687682
)
688683

689684
print(" - build tools")
@@ -706,18 +701,16 @@ def package(context: argparse.Namespace) -> None:
706701

707702
# Clone testbed
708703
print()
709-
run(
710-
[
711-
sys.executable,
712-
"Apple/testbed",
713-
"clone",
714-
"--platform",
715-
context.platform,
716-
"--framework",
717-
CROSS_BUILD_DIR / context.platform / "Python.xcframework",
718-
CROSS_BUILD_DIR / context.platform / "testbed",
719-
]
720-
)
704+
run([
705+
sys.executable,
706+
"Apple/testbed",
707+
"clone",
708+
"--platform",
709+
context.platform,
710+
"--framework",
711+
CROSS_BUILD_DIR / context.platform / "Python.xcframework",
712+
CROSS_BUILD_DIR / context.platform / "testbed",
713+
])
721714

722715
# Build the final archive
723716
archive_name = (
@@ -771,7 +764,7 @@ def build(context: argparse.Namespace, host: str | None = None) -> None:
771764
package(context)
772765

773766

774-
def test(context: argparse.Namespace, host: str | None = None) -> None:
767+
def test(context: argparse.Namespace, host: str | None = None) -> None: # noqa: PT028
775768
"""The implementation of the "test" command."""
776769
if host is None:
777770
host = context.host
@@ -809,18 +802,16 @@ def test(context: argparse.Namespace, host: str | None = None) -> None:
809802
/ f"Frameworks/{apple_multiarch(host)}"
810803
)
811804

812-
run(
813-
[
814-
sys.executable,
815-
"Apple/testbed",
816-
"clone",
817-
"--platform",
818-
context.platform,
819-
"--framework",
820-
framework_path,
821-
testbed_dir,
822-
]
823-
)
805+
run([
806+
sys.executable,
807+
"Apple/testbed",
808+
"clone",
809+
"--platform",
810+
context.platform,
811+
"--framework",
812+
framework_path,
813+
testbed_dir,
814+
])
824815

825816
run(
826817
[
@@ -854,7 +845,7 @@ def apple_sim_host(platform_name: str) -> str:
854845
"""Determine the native simulator target for this platform."""
855846
for _, slice_parts in HOSTS[platform_name].items():
856847
for host_triple in slice_parts:
857-
parts = host_triple.split('-')
848+
parts = host_triple.split("-")
858849
if parts[0] == platform.machine() and parts[-1] == "simulator":
859850
return host_triple
860851

@@ -982,20 +973,29 @@ def parse_args() -> argparse.Namespace:
982973
cmd.add_argument(
983974
"--simulator",
984975
help=(
985-
"The name of the simulator to use (eg: 'iPhone 16e'). Defaults to "
986-
"the most recently released 'entry level' iPhone device. Device "
987-
"architecture and OS version can also be specified; e.g., "
988-
"`--simulator 'iPhone 16 Pro,arch=arm64,OS=26.0'` would run on "
989-
"an ARM64 iPhone 16 Pro simulator running iOS 26.0."
976+
"The name of the simulator to use (eg: 'iPhone 16e'). "
977+
"Defaults to the most recently released 'entry level' "
978+
"iPhone device. Device architecture and OS version can also "
979+
"be specified; e.g., "
980+
"`--simulator 'iPhone 16 Pro,arch=arm64,OS=26.0'` would "
981+
"run on an ARM64 iPhone 16 Pro simulator running iOS 26.0."
990982
),
991983
)
992984
group = cmd.add_mutually_exclusive_group()
993985
group.add_argument(
994-
"--fast-ci", action="store_const", dest="ci_mode", const="fast",
995-
help="Add test arguments for GitHub Actions")
986+
"--fast-ci",
987+
action="store_const",
988+
dest="ci_mode",
989+
const="fast",
990+
help="Add test arguments for GitHub Actions",
991+
)
996992
group.add_argument(
997-
"--slow-ci", action="store_const", dest="ci_mode", const="slow",
998-
help="Add test arguments for buildbots")
993+
"--slow-ci",
994+
action="store_const",
995+
dest="ci_mode",
996+
const="slow",
997+
help="Add test arguments for buildbots",
998+
)
999999

10001000
for subcommand in [configure_build, configure_host, build, ci]:
10011001
subcommand.add_argument(

0 commit comments

Comments
 (0)