Skip to content

Commit

Permalink
python 3.12 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dholth committed Jul 20, 2024
1 parent 27006a5 commit e0599b5
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 59 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.30.0
------
- Support Python 3.12 with deprecated distutils, imp
- Use setuptools for enscons.cpyext
- Use tomllib (requires Python 3.11+)

0.28.0
------
- Update editables for approved PEP 660
Expand Down
3 changes: 1 addition & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

import pytoml as toml
import tomllib as toml
import enscons
import sys

metadata = toml.load(open("pyproject.toml"))["project"]

Expand Down
21 changes: 10 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'enscons'
copyright = '2023, Daniel Holth & enscons developers'
author = 'Daniel Holth & enscons developers'
release = '0.28.0'
project = "enscons"
copyright = "2023, Daniel Holth & enscons developers"
author = "Daniel Holth & enscons developers"
release = "0.30.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand All @@ -18,17 +18,16 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'myst_parser',
"sphinx.ext.autodoc",
"myst_parser",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


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

html_theme = 'furo'
html_static_path = ['_static']
html_theme = "furo"
html_static_path = ["_static"]
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ builder, a `WhlFile` builder, and an `SDist` builder.
Here's a simple and complete example. The following sections will go over each part in more detail.

```python
import pytoml as toml
import tomllib
import enscons

metadata = toml.load(open("pyproject.toml"))["project"]
metadata = tomllib.load(open("pyproject.toml"))["project"]
tag = "py3-none-any"

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

```python
metadata = toml.load(open("pyproject.toml"))["project"]
metadata = tomllib.load(open("pyproject.toml"))["project"]
tag = "py3-none-any"

env = Environment(
Expand Down
2 changes: 1 addition & 1 deletion enscons/SConstruct.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# (filled by enscons.setup2toml)

import enscons
import pytoml as toml
import tomllib as toml

metadata = dict(toml.load(open("pyproject.toml")))["project"]

Expand Down
15 changes: 5 additions & 10 deletions enscons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@

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

from distutils import sysconfig
from collections import defaultdict

from .util import safe_name, to_filename, generate_requirements

import codecs
import distutils.ccompiler, distutils.sysconfig, distutils.unixccompiler
import os.path
import SCons.Node.FS

Expand All @@ -82,7 +78,7 @@ def get_binary_tag():
"""
from packaging import tags

return str(next(tag for tag in tags.sys_tags() if not "manylinux" in tag.platform))
return str(next(tag for tag in tags.sys_tags() if "manylinux" not in tag.platform))


def get_universal_tag():
Expand Down Expand Up @@ -187,7 +183,7 @@ def egg_info_builder(target, source, env):
"""
Minimum egg_info. To be used only by pip to get dependencies.
"""
metadata = env["PACKAGE_METADATA"]
env["PACKAGE_METADATA"]
for dnode in env.arg2nodes(target):
if dnode.name == "PKG-INFO":
with open(dnode.get_path(), "w") as f:
Expand Down Expand Up @@ -249,7 +245,7 @@ def metadata_source(env):
# Maybe the two should be unified.
if "license" in metadata:
if not _is_string(metadata["license"]):
if not ("text" in metadata["license"]):
if "text" not in metadata["license"]:
source.append(metadata["license"]["file"])
if "readme" in metadata:
if _is_string(metadata["readme"]):
Expand Down Expand Up @@ -386,7 +382,6 @@ def add_editable(target, source, env):
archive = zipfile.ZipFile(
target[0].get_path(), "a", compression=zipfile.ZIP_DEFLATED
)
lines = []
for f, data in project.files():
archive.writestr(zipfile.ZipInfo(f, time.gmtime(SOURCE_EPOCH_ZIP)[:6]), data)
archive.close()
Expand Down Expand Up @@ -497,7 +492,7 @@ def init_wheel(env):
# editable may need an extra dependency, so it gets its own dist-info directory.
env.Command(editable_dist_info, env["DIST_INFO_PATH"], Copy("$TARGET", "$SOURCE"))

metadata2 = env.Command(
env.Command(
editable_dist_info.File("METADATA"), metadata_source(env), metadata_builder
)

Expand Down Expand Up @@ -593,7 +588,7 @@ def SDist(env, target=None, source=None):
env.Clean(egg_info, env["EGG_INFO_PATH"])
env.Alias("egg_info", egg_info)

pkg_info = env.Command("PKG-INFO", metadata_source(env), metadata_builder)
env.Command("PKG-INFO", metadata_source(env), metadata_builder)

# also the root directory name inside the archive
target_prefix = "-".join((env["PACKAGE_NAME"], env["PACKAGE_VERSION"]))
Expand Down
2 changes: 1 addition & 1 deletion enscons/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pprint
import os.path
import click
import pytoml as toml
import tomllib as toml


class Backend(object):
Expand Down
23 changes: 11 additions & 12 deletions enscons/cpyext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

from __future__ import print_function

import distutils.sysconfig, sysconfig, os, os.path
import sysconfig
import os
import os.path

from distutils.core import Distribution
from distutils.extension import Extension
from distutils.command.build_ext import build_ext
from setuptools import Distribution
from setuptools.extension import Extension
from setuptools.command.build_ext import build_ext

import importlib
import importlib.machinery


# not used when generate is passed directly to Environment
def exists(env):
return True
Expand All @@ -28,8 +31,6 @@ def extension_filename(modname, abi3=False):
If abi3=True and supported by the interpreter, return e.g.
"a/b/c.abi3.so".
"""
from distutils.sysconfig import get_config_var

# we could probably just split modname by '.' instead of using ext here:
ext = get_build_ext()
fullname = ext.get_ext_fullname(modname)
Expand All @@ -42,10 +43,7 @@ def extension_filename(modname, abi3=False):
suffix = suffixes[0] if suffixes else None
except AttributeError:
pass
if not suffix:
suffix = get_config_var("EXT_SUFFIX")
if not suffix:
suffix = get_config_var("SO") # py2
suffix = sysconfig.get_config_var("EXT_SUFFIX")

if abi3:
suffix = get_abi3_suffix() or suffix
Expand All @@ -55,6 +53,7 @@ def extension_filename(modname, abi3=False):

class no_build_ext(build_ext):
output = [] # for testing

# Are you kidding me? We have to run build_ext() to finish configuring the compiler.
def build_extension(self, ext):
def noop_spawn(*args):
Expand Down Expand Up @@ -102,8 +101,8 @@ def generate(env):
# Actually this has side effects adding redundant arguments to ext's compiler.
# Could copy the compiler from ext before run() is called.
if False:
compiler = distutils.ccompiler.new_compiler()
distutils.sysconfig.customize_compiler(compiler)
compiler = setuptools.ccompiler.new_compiler()
setuptools.sysconfig.customize_compiler(compiler)

ext = get_build_ext()

Expand Down
6 changes: 3 additions & 3 deletions enscons/pytar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def tar(target, source, env):

def _filter(info):
"""Return potentially anonymize tarinfo"""
if taruid != None:
if taruid is not None:
info.uid = taruid
info.uname = ""
if targid != None:
if targid is not None:
info.gid = targid
info.gname = ""
if tarmtime != None:
if tarmtime is not None:
info.mtime = tarmtime
return info

Expand Down
6 changes: 5 additions & 1 deletion enscons/setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
enscons' implementation of setup.py, to be called from a shim setup.py for
compatibility with traditional style packaging & tools.
Now that pyproject.toml is widely supported, this should not be needed.
"""

import sys, pkg_resources, argparse
import sys
import pkg_resources
import argparse


def develop(path):
Expand Down
22 changes: 15 additions & 7 deletions enscons/setup2toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

import runpy
from collections import OrderedDict
import setuptools, distutils.core
import sys, os, codecs, errno
import pytoml
import setuptools
try:
import distutils.core as distutils_core
except ImportError:
distutils_core = None
import sys
import os
import codecs
import errno
import tomli_w

import pkgutil

Expand Down Expand Up @@ -90,7 +97,8 @@ def setup_(**kw):
setup_.arguments = kw

setuptools.setup = setup_
distutils.core.setup = setup_
if distutils_core:
distutils_core.setup = setup_

sys.path[0:0] = "."

Expand Down Expand Up @@ -138,14 +146,14 @@ def setup_(**kw):
if "long_description" in ordered_arguments:
sys.stderr.write("Consider replacing long_description with description_file\n")

pyproject = pytoml.dumps(
OrderedDict(
pyproject = tomli_w.dumps(
dict(
[
["project", ordered_arguments],
[
"build-system",
{
"requires": ["pytoml>=0.1", "enscons"],
"requires": ["enscons"],
"build-backend": "enscons.api",
},
],
Expand Down
31 changes: 30 additions & 1 deletion enscons/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,37 @@
Utilities otherwise provided by pkg_resources or wheel
"""

from pkg_resources import safe_name, safe_extra, to_filename
import re
from packaging.requirements import Requirement
import packaging


# from pkg_resources
def safe_extra(extra):
return re.sub("[^A-Za-z0-9.-]+", "_", extra).lower()


# from pkg_resources
def safe_name(name):
"""Convert an arbitrary string to a standard distribution name
Any runs of non-alphanumeric/. characters are replaced with a single '-'.
"""
return re.sub("[^A-Za-z0-9.]+", "-", name)


# from pkg_resources
def safe_version(version):
"""
Convert an arbitrary string to a standard version string
"""
try:
# normalize the version
return str(packaging.version.Version(version))
except packaging.version.InvalidVersion:
version = version.replace(" ", ".")
return re.sub("[^A-Za-z0-9.]+", "-", version)


# from wheel
def requires_to_requires_dist(requirement):
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
[project]
name = "enscons"
description = "Tools for building Python packages with SCons"
version = "0.28.0"
version = "0.30.0"

authors = [{ name = "Daniel Holth", email = "dholth@fastmail.fm" }]
classifiers = [
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
]
dependencies = [
"scons>=3.0.5",
"pytoml>=0.1",
"tomli;python_version<'3.11'",
"setuptools",
"wheel",
"attrs",
"packaging>=20.9",
"editables==0.2;python_version>'3.0'",
"editables",
]
keywords = ["packaging", "wheel"]
license = "MIT"
Expand All @@ -37,5 +36,5 @@ backend-path = ["."] # only for bootstrapped enscons
requires = [
"scons",
"packaging",
"pytoml>=0.1",
"tomli;python_version<'3.11'",
] # enscons users add "enscons>=0.28" to this list
Loading

0 comments on commit e0599b5

Please sign in to comment.