Skip to content

Commit f1d2aba

Browse files
authored
Python 3.12 changes (#44)
* use importlib.machinery instead of imp * python 3.12 changes * update build matrix * build on pull_request, not push * add to_filename helper * open pyproject.toml as bniary * redirect "tomllib or tomli" through enscons.toml * update workflow * add pypy3.10 * edit CHANGES * note packaging normalizers * syntax * require successful SCons exit code * add python 3.8+ to workflow
1 parent 4fa7342 commit f1d2aba

File tree

18 files changed

+127
-71
lines changed

18 files changed

+127
-71
lines changed

.github/workflows/sphinx.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Sphinx
22
on:
3-
- push
43
- pull_request
54

65
jobs:

.github/workflows/upload-pypi-source.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: Build
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
jobs:
66
build:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.8", "3.9", "3.10", pypy3.9]
10+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
1111

1212
steps:
1313
- uses: actions/checkout@v3
@@ -20,7 +20,7 @@ jobs:
2020
run: python -c "import sys; print(sys.version)"
2121
- name: Build
2222
run: |
23-
python -m pip install scons pytoml packaging
23+
python -m pip install scons tomli packaging
2424
scons -c
2525
scons
2626
python -m pip install dist/enscons*.whl

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.30.0
2+
------
3+
- Support Python 3.12 with removed distutils, imp.
4+
- Use setuptools for enscons.cpyext, only required for enscons projects with extensions.
5+
- Use tomllib (Python 3.11+) or tomli.
6+
17
0.28.0
28
------
39
- Update editables for approved PEP 660

SConstruct

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
# OTHER DEALINGS IN THE SOFTWARE.
2424

25-
import pytoml as toml
25+
import enscons.toml as toml
2626
import enscons
27-
import sys
2827

29-
metadata = toml.load(open("pyproject.toml"))["project"]
28+
metadata = toml.load(open("pyproject.toml", "rb"))["project"]
3029

3130
full_tag = "py2.py3-none-any"
3231

docs/conf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

9-
project = 'enscons'
10-
copyright = '2023, Daniel Holth & enscons developers'
11-
author = 'Daniel Holth & enscons developers'
12-
release = '0.28.0'
9+
project = "enscons"
10+
copyright = "2023, Daniel Holth & enscons developers"
11+
author = "Daniel Holth & enscons developers"
12+
release = "0.30.0"
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
@@ -18,17 +18,16 @@
1818
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1919
# ones.
2020
extensions = [
21-
'sphinx.ext.autodoc',
22-
'myst_parser',
21+
"sphinx.ext.autodoc",
22+
"myst_parser",
2323
]
2424

25-
templates_path = ['_templates']
26-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
27-
25+
templates_path = ["_templates"]
26+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
2827

2928

3029
# -- Options for HTML output -------------------------------------------------
3130
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
3231

33-
html_theme = 'furo'
34-
html_static_path = ['_static']
32+
html_theme = "furo"
33+
html_static_path = ["_static"]

docs/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ builder, a `WhlFile` builder, and an `SDist` builder.
8080
Here's a simple and complete example. The following sections will go over each part in more detail.
8181

8282
```python
83-
import pytoml as toml
83+
import tomllib
8484
import enscons
8585

86-
metadata = toml.load(open("pyproject.toml"))["project"]
86+
metadata = tomllib.load(open("pyproject.toml", "rb"))["project"]
8787
tag = "py3-none-any"
8888

8989
env = Environment(
@@ -110,7 +110,7 @@ by the SCons runtime.
110110
The SConstruct `Environment` object should be created as shown:
111111

112112
```python
113-
metadata = toml.load(open("pyproject.toml"))["project"]
113+
metadata = tomllib.load(open("pyproject.toml", "rb"))["project"]
114114
tag = "py3-none-any"
115115

116116
env = Environment(
@@ -234,7 +234,7 @@ These variables are settable using kwargs to the `Environment()` constructor.
234234
235235
.. code-block:: python
236236
237-
metadata = toml.load(open("pyproject.toml"))["project"]
237+
metadata = toml.load(open("pyproject.toml", "rb"))["project"]
238238
239239
This variable is required.
240240

enscons/SConstruct.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# (filled by enscons.setup2toml)
33

44
import enscons
5-
import pytoml as toml
5+
import enscons.toml as toml
66

7-
metadata = dict(toml.load(open("pyproject.toml")))["project"]
7+
metadata = dict(toml.load(open("pyproject.toml", "rb")))["project"]
88

99
# set to True if package is not pure Python
1010
HAS_NATIVE_CODE = False

enscons/__init__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,9 @@
6565

6666
from SCons.Script import Copy, Action, FindInstalledFiles, GetOption, AddOption
6767

68-
from distutils import sysconfig
69-
from collections import defaultdict
70-
7168
from .util import safe_name, to_filename, generate_requirements
7269

7370
import codecs
74-
import distutils.ccompiler, distutils.sysconfig, distutils.unixccompiler
7571
import os.path
7672
import SCons.Node.FS
7773

@@ -82,7 +78,7 @@ def get_binary_tag():
8278
"""
8379
from packaging import tags
8480

85-
return str(next(tag for tag in tags.sys_tags() if not "manylinux" in tag.platform))
81+
return str(next(tag for tag in tags.sys_tags() if "manylinux" not in tag.platform))
8682

8783

8884
def get_universal_tag():
@@ -187,7 +183,6 @@ def egg_info_builder(target, source, env):
187183
"""
188184
Minimum egg_info. To be used only by pip to get dependencies.
189185
"""
190-
metadata = env["PACKAGE_METADATA"]
191186
for dnode in env.arg2nodes(target):
192187
if dnode.name == "PKG-INFO":
193188
with open(dnode.get_path(), "w") as f:
@@ -249,7 +244,7 @@ def metadata_source(env):
249244
# Maybe the two should be unified.
250245
if "license" in metadata:
251246
if not _is_string(metadata["license"]):
252-
if not ("text" in metadata["license"]):
247+
if "text" not in metadata["license"]:
253248
source.append(metadata["license"]["file"])
254249
if "readme" in metadata:
255250
if _is_string(metadata["readme"]):
@@ -386,7 +381,6 @@ def add_editable(target, source, env):
386381
archive = zipfile.ZipFile(
387382
target[0].get_path(), "a", compression=zipfile.ZIP_DEFLATED
388383
)
389-
lines = []
390384
for f, data in project.files():
391385
archive.writestr(zipfile.ZipInfo(f, time.gmtime(SOURCE_EPOCH_ZIP)[:6]), data)
392386
archive.close()
@@ -497,7 +491,7 @@ def init_wheel(env):
497491
# editable may need an extra dependency, so it gets its own dist-info directory.
498492
env.Command(editable_dist_info, env["DIST_INFO_PATH"], Copy("$TARGET", "$SOURCE"))
499493

500-
metadata2 = env.Command(
494+
env.Command(
501495
editable_dist_info.File("METADATA"), metadata_source(env), metadata_builder
502496
)
503497

@@ -593,7 +587,7 @@ def SDist(env, target=None, source=None):
593587
env.Clean(egg_info, env["EGG_INFO_PATH"])
594588
env.Alias("egg_info", egg_info)
595589

596-
pkg_info = env.Command("PKG-INFO", metadata_source(env), metadata_builder)
590+
env.Command("PKG-INFO", metadata_source(env), metadata_builder)
597591

598592
# also the root directory name inside the archive
599593
target_prefix = "-".join((env["PACKAGE_NAME"], env["PACKAGE_VERSION"]))

enscons/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
def _run(alias):
2424
try:
2525
SCons.Script.Main.main()
26-
except SystemExit:
27-
pass
26+
except SystemExit as e:
27+
if e.code != 0:
28+
raise
2829
# extreme non-api:
2930
lookup = SCons.Node.arg2nodes_lookups[0](alias).sources[0]
3031
return os.path.basename(str(lookup))

enscons/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import pprint
1515
import os.path
1616
import click
17-
import pytoml as toml
17+
import tomllib as toml
1818

1919

2020
class Backend(object):
2121
def __init__(self):
22-
self.metadata = dict(toml.load(open("pyproject.toml")))
22+
self.metadata = dict(toml.load(open("pyproject.toml", "rb")))
2323
build_backend = self.metadata["build-system"]["build-backend"]
2424
module, _, obj = build_backend.partition(":")
2525
__import__(module)

0 commit comments

Comments
 (0)