Skip to content

Commit 235d922

Browse files
committed
Import Upstream version 3.13.2
0 parents  commit 235d922

File tree

4,781 files changed

+2615376
-0
lines changed

Some content is hidden

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

4,781 files changed

+2615376
-0
lines changed

.coveragerc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
# Regexes for lines to exclude from consideration
6+
exclude_lines =
7+
# Don't complain if non-runnable code isn't run:
8+
if 0:
9+
if __name__ == .__main__.:
10+
raise AssertionError\(
11+
12+
# Empty bodies in protocols or abstract methods
13+
^\s*def [a-zA-Z0-9_]+\(.*\)(\s*->.*)?:\s*\.\.\.(\s*#.*)?$
14+
^\s*\.\.\.(\s*#.*)?$
15+
16+
.*# pragma: no cover
17+
.*# pragma: no branch
18+
19+
# Additions for IDLE:
20+
.*# htest #
21+
if not (_htest or _utest):
22+
if not .*_utest:
23+
if .*_htest:
24+

.devcontainer/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM docker.io/library/fedora:40
2+
3+
ENV CC=clang
4+
5+
ENV WASI_SDK_VERSION=24
6+
ENV WASI_SDK_PATH=/opt/wasi-sdk
7+
8+
ENV WASMTIME_HOME=/opt/wasmtime
9+
ENV WASMTIME_VERSION=22.0.0
10+
ENV WASMTIME_CPU_ARCH=x86_64
11+
12+
RUN dnf -y --nodocs --setopt=install_weak_deps=False install /usr/bin/{blurb,clang,curl,git,ln,tar,xz} 'dnf-command(builddep)' && \
13+
dnf -y --nodocs --setopt=install_weak_deps=False builddep python3 && \
14+
dnf -y clean all
15+
16+
RUN mkdir ${WASI_SDK_PATH} && \
17+
curl --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-x86_64-linux.tar.gz | \
18+
tar --strip-components 1 --directory ${WASI_SDK_PATH} --extract --gunzip
19+
20+
RUN mkdir --parents ${WASMTIME_HOME} && \
21+
curl --location "https://github.com/bytecodealliance/wasmtime/releases/download/v${WASMTIME_VERSION}/wasmtime-v${WASMTIME_VERSION}-${WASMTIME_CPU_ARCH}-linux.tar.xz" | \
22+
xz --decompress | \
23+
tar --strip-components 1 --directory ${WASMTIME_HOME} -x && \
24+
ln -s ${WASMTIME_HOME}/wasmtime /usr/local/bin

.devcontainer/devcontainer.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile"
4+
},
5+
"onCreateCommand": [
6+
// Install common tooling.
7+
"dnf",
8+
"install",
9+
"-y",
10+
"which",
11+
"zsh",
12+
"fish",
13+
// For umask fix below.
14+
"/usr/bin/setfacl"
15+
],
16+
"updateContentCommand": {
17+
// Using the shell for `nproc` usage.
18+
"python": "./configure --config-cache --with-pydebug && make -s -j `nproc`",
19+
"docs": [
20+
"make",
21+
"--directory",
22+
"Doc",
23+
"venv",
24+
"html"
25+
]
26+
},
27+
"postCreateCommand": {
28+
// https://github.com/orgs/community/discussions/26026
29+
"umask fix: workspace": ["sudo", "setfacl", "-bnR", "."],
30+
"umask fix: /tmp": ["sudo", "setfacl", "-bnR", "/tmp"]
31+
},
32+
"customizations": {
33+
"vscode": {
34+
"extensions": [
35+
// Highlighting for Parser/Python.asdl.
36+
"brettcannon.zephyr-asdl",
37+
// Highlighting for configure.ac.
38+
"maelvalais.autoconf",
39+
// C auto-complete.
40+
"ms-vscode.cpptools",
41+
// To view HTML build of docs.
42+
"ms-vscode.live-server",
43+
// Python auto-complete.
44+
"ms-python.python"
45+
],
46+
"settings": {
47+
"C_Cpp.default.compilerPath": "/usr/bin/clang",
48+
"C_Cpp.default.cStandard": "c11",
49+
"C_Cpp.default.defines": [
50+
"CONFIG_64",
51+
"Py_BUILD_CORE"
52+
],
53+
"C_Cpp.default.includePath": [
54+
"${workspaceFolder}/*",
55+
"${workspaceFolder}/Include/**"
56+
],
57+
// https://github.com/microsoft/vscode-cpptools/issues/10732
58+
"C_Cpp.errorSquiggles": "disabled",
59+
"editor.insertSpaces": true,
60+
"editor.rulers": [
61+
80
62+
],
63+
"editor.tabSize": 4,
64+
"editor.trimAutoWhitespace": true,
65+
"files.associations": {
66+
"*.h": "c"
67+
},
68+
"files.encoding": "utf8",
69+
"files.eol": "\n",
70+
"files.insertFinalNewline": true,
71+
"files.trimTrailingWhitespace": true,
72+
"python.analysis.diagnosticSeverityOverrides": {
73+
// Complains about shadowing the stdlib w/ the stdlib.
74+
"reportShadowedImports": "none",
75+
// Doesn't like _frozen_importlib.
76+
"reportMissingImports": "none"
77+
},
78+
"python.analysis.extraPaths": [
79+
"Lib"
80+
],
81+
"python.defaultInterpreterPath": "./python",
82+
"[restructuredtext]": {
83+
"editor.tabSize": 3
84+
}
85+
}
86+
}
87+
}
88+
}

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*.{py,c,cpp,h,js,rst,md,yml}]
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
indent_style = space
7+
8+
[*.{py,c,cpp,h}]
9+
indent_size = 4
10+
11+
[*.rst]
12+
indent_size = 3
13+
14+
[*.{js,yml}]
15+
indent_size = 2

.mailmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file sets the canonical name for contributors to the repository.
2+
# Documentation: https://git-scm.com/docs/gitmailmap
3+

.pre-commit-config.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.1
4+
hooks:
5+
- id: ruff
6+
name: Run Ruff (lint) on Doc/
7+
args: [--exit-non-zero-on-fix]
8+
files: ^Doc/
9+
- id: ruff
10+
name: Run Ruff (lint) on Lib/test/
11+
args: [--exit-non-zero-on-fix]
12+
files: ^Lib/test/
13+
- id: ruff
14+
name: Run Ruff (lint) on Argument Clinic
15+
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
16+
files: ^Tools/clinic/|Lib/test/test_clinic.py
17+
- id: ruff-format
18+
name: Run Ruff (format) on Doc/
19+
args: [--check]
20+
files: ^Doc/
21+
22+
- repo: https://github.com/psf/black-pre-commit-mirror
23+
rev: 24.10.0
24+
hooks:
25+
- id: black
26+
name: Run Black on Tools/jit/
27+
files: ^Tools/jit/
28+
29+
- repo: https://github.com/pre-commit/pre-commit-hooks
30+
rev: v5.0.0
31+
hooks:
32+
- id: check-case-conflict
33+
- id: check-merge-conflict
34+
- id: check-toml
35+
exclude: ^Lib/test/test_tomllib/
36+
- id: check-yaml
37+
- id: end-of-file-fixer
38+
types: [python]
39+
exclude: Lib/test/tokenizedata/coding20731.py
40+
- id: trailing-whitespace
41+
types_or: [c, inc, python, rst]
42+
43+
- repo: https://github.com/woodruffw/zizmor-pre-commit
44+
rev: v1.1.1
45+
hooks:
46+
- id: zizmor
47+
48+
- repo: https://github.com/sphinx-contrib/sphinx-lint
49+
rev: v1.0.0
50+
hooks:
51+
- id: sphinx-lint
52+
args: [--enable=default-role]
53+
files: ^Doc/|^Misc/NEWS.d/
54+
55+
- repo: meta
56+
hooks:
57+
- id: check-hooks-apply
58+
- id: check-useless-excludes

.readthedocs.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
# Project page: https://readthedocs.org/projects/cpython-previews/
4+
5+
version: 2
6+
7+
sphinx:
8+
configuration: Doc/conf.py
9+
10+
build:
11+
os: ubuntu-24.04
12+
tools:
13+
python: "3"
14+
15+
commands:
16+
# https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition
17+
#
18+
# Cancel building pull requests when there aren't changes in the Doc directory.
19+
#
20+
# If there are no changes (git diff exits with 0) we force the command to return with 183.
21+
# This is a special exit code on Read the Docs that will cancel the build immediately.
22+
- |
23+
if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && [ "$(git diff --quiet origin/main -- Doc/ .readthedocs.yml; echo $?)" -eq 0 ];
24+
then
25+
echo "No changes to Doc/ - exiting the build.";
26+
exit 183;
27+
fi
28+
29+
- asdf plugin add uv
30+
- asdf install uv latest
31+
- asdf global uv latest
32+
- make -C Doc venv html
33+
- mkdir _readthedocs
34+
- mv Doc/build/html _readthedocs/html
35+

Android/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Python for Android
2+
3+
These instructions are only needed if you're planning to compile Python for
4+
Android yourself. Most users should *not* need to do this. Instead, use one of
5+
the tools listed in `Doc/using/android.rst`, which will provide a much easier
6+
experience.
7+
8+
9+
## Prerequisites
10+
11+
First, make sure you have all the usual tools and libraries needed to build
12+
Python for your development machine.
13+
14+
Second, you'll need an Android SDK. If you already have the SDK installed,
15+
export the `ANDROID_HOME` environment variable to point at its location.
16+
Otherwise, here's how to install it:
17+
18+
* Download the "Command line tools" from <https://developer.android.com/studio>.
19+
* Create a directory `android-sdk/cmdline-tools`, and unzip the command line
20+
tools package into it.
21+
* Rename `android-sdk/cmdline-tools/cmdline-tools` to
22+
`android-sdk/cmdline-tools/latest`.
23+
* `export ANDROID_HOME=/path/to/android-sdk`
24+
25+
The `android.py` script also requires the following commands to be on the `PATH`:
26+
27+
* `curl`
28+
* `java` (or set the `JAVA_HOME` environment variable)
29+
* `tar`
30+
* `unzip`
31+
32+
33+
## Building
34+
35+
Python can be built for Android on any POSIX platform supported by the Android
36+
development tools, which currently means Linux or macOS. This involves doing a
37+
cross-build where you use a "build" Python (for your development machine) to
38+
help produce a "host" Python for Android.
39+
40+
The easiest way to do a build is to use the `android.py` script. You can either
41+
have it perform the entire build process from start to finish in one step, or
42+
you can do it in discrete steps that mirror running `configure` and `make` for
43+
each of the two builds of Python you end up producing.
44+
45+
The discrete steps for building via `android.py` are:
46+
47+
```sh
48+
./android.py configure-build
49+
./android.py make-build
50+
./android.py configure-host HOST
51+
./android.py make-host HOST
52+
```
53+
54+
`HOST` identifies which architecture to build. To see the possible values, run
55+
`./android.py configure-host --help`.
56+
57+
To do all steps in a single command, run:
58+
59+
```sh
60+
./android.py build HOST
61+
```
62+
63+
In the end you should have a build Python in `cross-build/build`, and an Android
64+
build in `cross-build/HOST`.
65+
66+
You can use `--` as a separator for any of the `configure`-related commands –
67+
including `build` itself – to pass arguments to the underlying `configure`
68+
call. For example, if you want a pydebug build that also caches the results from
69+
`configure`, you can do:
70+
71+
```sh
72+
./android.py build HOST -- -C --with-pydebug
73+
```
74+
75+
76+
## Testing
77+
78+
The test suite can be run on Linux, macOS, or Windows:
79+
80+
* On Linux, the emulator needs access to the KVM virtualization interface, and
81+
a DISPLAY environment variable pointing at an X server.
82+
* On Windows, you won't be able to do the build on the same machine, so you'll
83+
have to copy the `cross-build/HOST` directory from somewhere else.
84+
85+
The test suite can usually be run on a device with 2 GB of RAM, but this is
86+
borderline, so you may need to increase it to 4 GB. As of Android
87+
Studio Koala, 2 GB is the default for all emulators, although the user interface
88+
may indicate otherwise. Locate the emulator's directory under `~/.android/avd`,
89+
and find `hw.ramSize` in both config.ini and hardware-qemu.ini. Either set these
90+
manually to the same value, or use the Android Studio Device Manager, which will
91+
update both files.
92+
93+
Before running the test suite, follow the instructions in the previous section
94+
to build the architecture you want to test. Then run the test script in one of
95+
the following modes:
96+
97+
* In `--connected` mode, it runs on a device or emulator you have already
98+
connected to the build machine. List the available devices with
99+
`$ANDROID_HOME/platform-tools/adb devices -l`, then pass a device ID to the
100+
script like this:
101+
102+
```sh
103+
./android.py test --connected emulator-5554
104+
```
105+
106+
* In `--managed` mode, it uses a temporary headless emulator defined in the
107+
`managedDevices` section of testbed/app/build.gradle.kts. This mode is slower,
108+
but more reproducible.
109+
110+
We currently define two devices: `minVersion` and `maxVersion`, corresponding
111+
to our minimum and maximum supported Android versions. For example:
112+
113+
```sh
114+
./android.py test --managed maxVersion
115+
```
116+
117+
By default, the only messages the script will show are Python's own stdout and
118+
stderr. Add the `-v` option to also show Gradle output, and non-Python logcat
119+
messages.
120+
121+
Any other arguments on the `android.py test` command line will be passed through
122+
to `python -m test` – use `--` to separate them from android.py's own options.
123+
See the [Python Developer's
124+
Guide](https://devguide.python.org/testing/run-write-tests/) for common options
125+
– most of them will work on Android, except for those that involve subprocesses,
126+
such as `-j`.
127+
128+
Every time you run `android.py test`, changes in pure-Python files in the
129+
repository's `Lib` directory will be picked up immediately. Changes in C files,
130+
and architecture-specific files such as sysconfigdata, will not take effect
131+
until you re-run `android.py make-host` or `build`.
132+
133+
134+
## Using in your own app
135+
136+
See `Doc/using/android.rst`.

0 commit comments

Comments
 (0)