Skip to content

Commit 11cd22a

Browse files
Add Support for Python 3.12 (#19)
1 parent d635013 commit 11cd22a

File tree

191 files changed

+74283
-90
lines changed

Some content is hidden

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

191 files changed

+74283
-90
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
# Explicit inclusions
3+
!shim-new-stuff.h
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
This is the public implementation of PEP 734.
1+
This is the public pure-Python implementation of PEP 734,
2+
along with several other backports.
3+
4+
For the implementation of the low-level modules, only on Python 3.12,
5+
see https://pypi.org/project/interpreters-3-12/.
26

37
Nearly all development for this project is done in the upstream CPython repo.
48

TODO

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Fixes
33
-----
44

55
* [x] missing interpreters._crossinterp module
6+
* [ ] use the correct dependencies in backports_3.12/pyproject.toml
67
* [ ] ...
78

89

@@ -11,19 +12,21 @@ Improvements
1112

1213
* [x] add interpreters_experimental module (start with interpreters.channels)
1314
* [x] add InterpreterPoolExecutor
14-
* [ ] support for 3.12 (and outdated 3.13, if ever necessary)
15+
* [x] support for 3.12 (and outdated 3.13, if ever necessary)
16+
* [x] add wheels
1517
* [ ] add tests (copy from upstream?)
1618
* [ ] add CI (GitHub actions)
17-
* [ ] add wheels
19+
* [ ] backport stdlib modules that are not cross-interp-compatible in 3.12 (e.g. datetime)
1820

1921

2022
Releases
2123
--------
2224

2325
* [ ] ...
2426
* [ ] 0.5.0
25-
* 3.12 support?
26-
* [ ] 0.4.1
27+
* add wheels
28+
* 3.12 support
29+
* [x] 0.4.1
2730
* drop the 3.14 restriction
2831
* [x] 0.4.0
2932
* improvement: add interpreters_experimental and move interpreters.channels

backport_3.12/MANIFEST.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include src/Include/*.h
2+
include src/Include/cpython/*.h
3+
include src/Include/internal/*.h
4+
include src/3.12/Include/internal/*.h
5+
include src/Python/*.c
6+
include src/Python/*.h
7+
include src/_interpreters_common.h
8+
9+
include src/shim-compatible-includes.h
10+
include src/shim-new-stuff.h
11+
include src/runtimebackports.c
12+
include src/3.12/Objects/typeobject.c

backport_3.12/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This is the public implementation of the low-level modules supporting PEP 734.
2+
3+
The modules provided by the package should mostly not be used directly.
4+
For the high-level modules, see https://pypi.org/project/interpreters-pep-734/.
5+
6+
On Python 3.13+, the low-level modules already ship with Python.
7+
8+
Nearly all development for this project is done in the upstream CPython repo.

backport_3.12/pyproject.toml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[build-system]
2+
# We use setuptools because hatchling doesn't build extension modules.
3+
requires = ["setuptools>=61.0"]
4+
build-backend = "setuptools.build_meta"
5+
6+
[project]
7+
name = "interpreters-3-12"
8+
version = "0.5.0"
9+
authors = [
10+
{ name="Eric Snow", email="[email protected]" },
11+
]
12+
description = "Do not use this directly. Install and use interpreters-pep-734 instead."
13+
readme = "README.md"
14+
requires-python = "==3.12.*"
15+
classifiers = [
16+
"Programming Language :: Python :: 3",
17+
"License :: OSI Approved :: BSD License",
18+
"Operating System :: OS Independent",
19+
]
20+
21+
[project.urls]
22+
"Homepage" = "https://github.com/ericsnowcurrently/interpreters"
23+
"Bug Tracker" = "https://github.com/ericsnowcurrently/interpreters/issues"
24+
25+
[tool.hatch.envs.default]
26+
extra-dependencies = [
27+
"black",
28+
"pytest",
29+
"ruff",
30+
"mypy",
31+
]
32+
33+
[tool.pytest.ini_options]
34+
minversion = "7.4.0"
35+
python_files = "*.py" # Discover tests in every python file
36+
addopts = "-rA"
37+
38+
[tool.mypy]
39+
ignore_missing_imports = true
40+
41+
[tool.ruff]
42+
select = [
43+
"A",
44+
"B",
45+
"C",
46+
"DTZ",
47+
"E",
48+
"EM",
49+
"F",
50+
"FBT",
51+
"I",
52+
"ICN",
53+
"ISC",
54+
"N",
55+
"PLC",
56+
"PLE",
57+
"PLR",
58+
"PLW",
59+
"Q",
60+
"RUF",
61+
"S",
62+
"SIM",
63+
"T",
64+
"TID",
65+
"UP",
66+
"W",
67+
"YTT",
68+
]
69+
ignore = [
70+
"T201", # "print" is OK
71+
"S101", # "assert" is OK
72+
"E702", # Statements on one line OK
73+
]

backport_3.12/setup.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import os.path
3+
import sys
4+
5+
from setuptools import Extension, setup
6+
7+
8+
#Py_DEBUG = (os.getenv('Py_DEBUG') is not None)
9+
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
10+
if Py_DEBUG:
11+
DEBUG = True
12+
else:
13+
DEBUG = (os.getenv('DEBUG') is not None)
14+
15+
EXT_COMMON = dict(
16+
language='c',
17+
include_dirs=[
18+
'src/3.12/Include/internal',
19+
'src/Include',
20+
'src/Include/internal',
21+
],
22+
define_macros=[
23+
('Py_BUILD_CORE_MODULE', '1'),
24+
# *([
25+
# ('Py_DEBUG', '1'),
26+
## ('Py_REF_DEBUG', '1'),
27+
# ] if DEBUG else []),
28+
],
29+
extra_compile_args=[
30+
'-include', 'src/shim-compatible-includes.h',
31+
'-include', 'src/shim-new-stuff.h',
32+
#*([ '-g', '-Og'] if DEBUG else [])
33+
],
34+
)
35+
36+
#DEPENDENCIES = [
37+
# 'src/Python/interpconfig',
38+
# 'src/Python/crossinterp',
39+
# 'src/Python/lock',
40+
# 'src/Python/parking_lot',
41+
# 'src/runtimebackports',
42+
# 'src/3.12/Objects/typeobject',
43+
#]
44+
#EXTRA_SOURCES = [f'{v}.c' for v in DEPENDENCIES]
45+
#EXTRA_OBJECTS = [f'{v}.o' for v in DEPENDENCIES]
46+
SOURCES_COMMON = [
47+
'src/Python/interpconfig.c',
48+
'src/Python/crossinterp.c',
49+
'src/Python/lock.c',
50+
'src/Python/parking_lot.c',
51+
'src/runtimebackports.c',
52+
'src/3.12/Objects/typeobject.c',
53+
]
54+
55+
setup(
56+
ext_modules=[
57+
Extension(
58+
name='_interpreters',
59+
sources=['src/_interpretersmodule.c',
60+
*SOURCES_COMMON],
61+
# *EXTRA_SOURCES],
62+
**EXT_COMMON,
63+
),
64+
Extension(
65+
name='_interpqueues',
66+
sources=['src/_interpqueuesmodule.c',
67+
*SOURCES_COMMON],
68+
# sources=['src/_interpqueuesmodule.c'],
69+
# extra_objects=EXTRA_OBJECTS,
70+
**EXT_COMMON,
71+
),
72+
Extension(
73+
name='_interpchannels',
74+
sources=['src/_interpchannelsmodule.c',
75+
*SOURCES_COMMON],
76+
# sources=['src/_interpchannelsmodule.c'],
77+
# extra_objects=EXTRA_OBJECTS,
78+
**EXT_COMMON,
79+
),
80+
],
81+
)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#ifndef Py_INTERNAL_ASDL_H
2+
#define Py_INTERNAL_ASDL_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
#include "pycore_pyarena.h" // _PyArena_Malloc()
12+
13+
typedef PyObject * identifier;
14+
typedef PyObject * string;
15+
typedef PyObject * object;
16+
typedef PyObject * constant;
17+
18+
/* It would be nice if the code generated by asdl_c.py was completely
19+
independent of Python, but it is a goal the requires too much work
20+
at this stage. So, for example, I'll represent identifiers as
21+
interned Python strings.
22+
*/
23+
24+
#define _ASDL_SEQ_HEAD \
25+
Py_ssize_t size; \
26+
void **elements;
27+
28+
typedef struct {
29+
_ASDL_SEQ_HEAD
30+
} asdl_seq;
31+
32+
typedef struct {
33+
_ASDL_SEQ_HEAD
34+
void *typed_elements[1];
35+
} asdl_generic_seq;
36+
37+
typedef struct {
38+
_ASDL_SEQ_HEAD
39+
PyObject *typed_elements[1];
40+
} asdl_identifier_seq;
41+
42+
typedef struct {
43+
_ASDL_SEQ_HEAD
44+
int typed_elements[1];
45+
} asdl_int_seq;
46+
47+
asdl_generic_seq *_Py_asdl_generic_seq_new(Py_ssize_t size, PyArena *arena);
48+
asdl_identifier_seq *_Py_asdl_identifier_seq_new(Py_ssize_t size, PyArena *arena);
49+
asdl_int_seq *_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
50+
51+
52+
#define GENERATE_ASDL_SEQ_CONSTRUCTOR(NAME, TYPE) \
53+
asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *arena) \
54+
{ \
55+
asdl_ ## NAME ## _seq *seq = NULL; \
56+
size_t n; \
57+
/* check size is sane */ \
58+
if (size < 0 || \
59+
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) { \
60+
PyErr_NoMemory(); \
61+
return NULL; \
62+
} \
63+
n = (size ? (sizeof(TYPE *) * (size - 1)) : 0); \
64+
/* check if size can be added safely */ \
65+
if (n > SIZE_MAX - sizeof(asdl_ ## NAME ## _seq)) { \
66+
PyErr_NoMemory(); \
67+
return NULL; \
68+
} \
69+
n += sizeof(asdl_ ## NAME ## _seq); \
70+
seq = (asdl_ ## NAME ## _seq *)_PyArena_Malloc(arena, n); \
71+
if (!seq) { \
72+
PyErr_NoMemory(); \
73+
return NULL; \
74+
} \
75+
memset(seq, 0, n); \
76+
seq->size = size; \
77+
seq->elements = (void**)seq->typed_elements; \
78+
return seq; \
79+
}
80+
81+
#define asdl_seq_GET_UNTYPED(S, I) _Py_RVALUE((S)->elements[(I)])
82+
#define asdl_seq_GET(S, I) _Py_RVALUE((S)->typed_elements[(I)])
83+
#define asdl_seq_LEN(S) _Py_RVALUE(((S) == NULL ? 0 : (S)->size))
84+
85+
#ifdef Py_DEBUG
86+
# define asdl_seq_SET(S, I, V) \
87+
do { \
88+
Py_ssize_t _asdl_i = (I); \
89+
assert((S) != NULL); \
90+
assert(0 <= _asdl_i && _asdl_i < (S)->size); \
91+
(S)->typed_elements[_asdl_i] = (V); \
92+
} while (0)
93+
#else
94+
# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[(I)] = (V))
95+
#endif
96+
97+
#ifdef Py_DEBUG
98+
# define asdl_seq_SET_UNTYPED(S, I, V) \
99+
do { \
100+
Py_ssize_t _asdl_i = (I); \
101+
assert((S) != NULL); \
102+
assert(0 <= _asdl_i && _asdl_i < (S)->size); \
103+
(S)->elements[_asdl_i] = (V); \
104+
} while (0)
105+
#else
106+
# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[(I)] = (V))
107+
#endif
108+
109+
#ifdef __cplusplus
110+
}
111+
#endif
112+
#endif /* !Py_INTERNAL_ASDL_H */

0 commit comments

Comments
 (0)