Skip to content

Commit 7675deb

Browse files
committed
[README.md,setup.py,cdd/shared/pkg_utils.py,cdd/tests/{mocks/cstify.py,test_setup.py}] Python 3.13 support
1 parent 9cb55df commit 7675deb

File tree

5 files changed

+34
-215
lines changed

5 files changed

+34
-215
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cdd-python
22
==========
3-
![Python version range](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-blue.svg)
3+
![Python version range](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-blue.svg)
44
![Python implementation](https://img.shields.io/badge/implementation-cpython-blue.svg)
55
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
66
[![Linting, testing, coverage, and release](https://github.com/offscale/cdd-python/workflows/Linting,%20testing,%20coverage,%20and%20release/badge.svg)](https://github.com/offscale/cdd-python/actions)

cdd/shared/pkg_utils.py

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,91 +5,11 @@
55
from cdd.shared.pure_utils import PY_GTE_3_12
66

77
if PY_GTE_3_12:
8-
import os
9-
import sys
10-
from sysconfig import _BASE_EXEC_PREFIX as BASE_EXEC_PREFIX
11-
from sysconfig import _BASE_PREFIX as BASE_PREFIX
12-
from sysconfig import _EXEC_PREFIX as EXEC_PREFIX
13-
from sysconfig import _PREFIX as PREFIX
14-
from sysconfig import get_python_version
15-
16-
Str = type(
17-
"_Never",
18-
tuple(),
19-
{
20-
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
21-
or n
22-
},
23-
)
24-
25-
def is_virtual_environment():
26-
"""
27-
Whether one is in a virtual environment
28-
"""
29-
return sys.base_prefix != sys.prefix or hasattr(sys, "real_prefix")
30-
31-
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
32-
"""Return the directory containing the Python library (standard or
33-
site additions).
34-
35-
If 'plat_specific' is true, return the directory containing
36-
platform-specific modules, i.e. any module from a non-pure-Python
37-
module distribution; otherwise, return the platform-shared library
38-
directory. If 'standard_lib' is true, return the directory
39-
containing standard Python library modules; otherwise, return the
40-
directory for site-specific modules.
41-
42-
If 'prefix' is supplied, use it instead of sys.base_prefix or
43-
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
44-
"""
45-
is_default_prefix = not prefix or os.path.normpath(prefix) in (
46-
"/usr",
47-
"/usr/local",
48-
)
49-
prefix = (
50-
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
51-
if standard_lib
52-
else (EXEC_PREFIX or PREFIX)
53-
)
54-
55-
class DistutilsPlatformError(Exception):
56-
"""DistutilsPlatformError"""
57-
58-
assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
59-
"I don't know where Python installs its library "
60-
"on platform '{}'".format(os.name)
61-
)
62-
return (
63-
(
64-
# plat_specific or standard_lib:
65-
# Platform-specific modules (any module from a non-pure-Python
66-
# module distribution) or standard Python library modules.
67-
# else:
68-
# Pure Python
69-
lambda libpython: (
70-
libpython
71-
if standard_lib
72-
else (
73-
os.path.join(prefix, "lib", "python3", "dist-packages")
74-
if is_default_prefix and not is_virtual_environment()
75-
else os.path.join(libpython, "site-packages")
76-
)
77-
)
78-
)(
79-
os.path.join(
80-
prefix,
81-
sys.platlibdir if plat_specific or standard_lib else "lib",
82-
"python" + get_python_version(),
83-
)
84-
)
85-
if os.name == "posix"
86-
else (
87-
os.path.join(prefix, "Lib")
88-
if standard_lib
89-
else os.path.join(prefix, "Lib", "site-packages")
90-
)
91-
)
8+
from sysconfig import get_paths
929

10+
get_python_lib = lambda prefix="", *args, **kwargs: get_paths(*args, **kwargs)[
11+
prefix or "purelib"
12+
]
9313
else:
9414
from distutils.sysconfig import get_python_lib
9515

cdd/tests/mocks/cstify.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ def add1(foo):
2020
"""
2121

2222
"""foo"""
23-
def g(): """foo : bar ; can"""; pass
2423

25-
def h(): # stuff
24+
def g():
25+
"""foo : bar ; can"""
2626
pass
2727

28-
def adder(a: int,
29-
b: int) -> int:
28+
def h(): # stuff
29+
pass
30+
31+
def adder(a: int, b: int) -> int:
3032
"""
3133
:param a: First arg
3234
@@ -40,19 +42,14 @@ def adder(a: int,
4042
= a + b
4143
return res
4244

43-
r = (
44-
add(foo, 1)
45-
or
46-
adder(foo, 1)
47-
)
45+
r = add(foo, 1) or adder(foo, 1)
4846
if r:
4947
None
5048
elif r:
5149
True
5250
False
5351
# ([5,5] @ [5,5]) *\
54-
-5 / 7 ** 6 + \
55-
6.0 - 6e1 & 1+2.34j
52+
-5 / 7**6 + 6.0 - 6e1 & 1 + 2.34j
5653
r <<= 5
5754
print(r)
5855
else:

cdd/tests/test_setup.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ def test_properties(self) -> None:
5151
self.assertEqual(getattr(self.mod, "package_name"), "cdd")
5252
self.assertEqual(self.mod.__name__, "setup_py")
5353

54-
def test_to_funcs(self) -> None:
55-
"""Tests that `to_funcs` produces the right local and install dirs"""
56-
to_funcs = getattr(self.mod, "to_funcs")
57-
args = "5", "6" # type: tuple[str, str]
58-
local_dir_join_func_resp, install_dir_join_func_resp = map(
59-
methodcaller("__call__"), to_funcs(*args)
60-
)
61-
self.assertNotEqual(local_dir_join_func_resp, install_dir_join_func_resp)
62-
self.assertEqual(
63-
local_dir_join_func_resp,
64-
path.join(path.dirname(path.dirname(__file__)), *args),
65-
)
66-
6754
def test_main(self) -> None:
6855
"""
6956
Tests that no errors occur in `main` function call (up to `setup()`, which is tested in setuptools)

setup.py

Lines changed: 21 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import sys
9-
from ast import Assign, Constant, Name, parse
9+
from ast import Assign, Name, parse
1010
from functools import partial
1111
from operator import attrgetter
1212
from os import path
@@ -15,93 +15,22 @@
1515
from setuptools import find_packages, setup
1616

1717
if sys.version_info[:2] >= (3, 12):
18-
import os
19-
from sysconfig import _BASE_EXEC_PREFIX as BASE_EXEC_PREFIX
20-
from sysconfig import _BASE_PREFIX as BASE_PREFIX
21-
from sysconfig import _EXEC_PREFIX as EXEC_PREFIX
22-
from sysconfig import _PREFIX as PREFIX
23-
from sysconfig import get_python_version
24-
25-
Str = type(
26-
"_Never",
27-
tuple(),
28-
{
29-
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
30-
or n
31-
},
32-
)
18+
from ast import Del as Str
19+
else:
20+
from ast import Str
3321

34-
def is_virtual_environment():
35-
"""
36-
Whether one is in a virtual environment
37-
"""
38-
return sys.base_prefix != sys.prefix or hasattr(sys, "real_prefix")
39-
40-
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
41-
"""Return the directory containing the Python library (standard or
42-
site additions).
43-
44-
If 'plat_specific' is true, return the directory containing
45-
platform-specific modules, i.e. any module from a non-pure-Python
46-
module distribution; otherwise, return the platform-shared library
47-
directory. If 'standard_lib' is true, return the directory
48-
containing standard Python library modules; otherwise, return the
49-
directory for site-specific modules.
50-
51-
If 'prefix' is supplied, use it instead of sys.base_prefix or
52-
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
53-
"""
54-
is_default_prefix = not prefix or os.path.normpath(prefix) in (
55-
"/usr",
56-
"/usr/local",
57-
)
58-
prefix = (
59-
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
60-
if standard_lib
61-
else (EXEC_PREFIX or PREFIX)
62-
)
22+
if sys.version_info[0] == 2:
23+
from itertools import ifilter as filter
24+
from itertools import imap as map
6325

64-
class DistutilsPlatformError(Exception):
65-
"""DistutilsPlatformError"""
26+
if sys.version_info[:2] > (3, 7):
27+
from ast import Constant
28+
else:
29+
from ast import expr
6630

67-
assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
68-
"I don't know where Python installs its library "
69-
"on platform '{}'".format(os.name)
70-
)
71-
return (
72-
(
73-
# plat_specific or standard_lib:
74-
# Platform-specific modules (any module from a non-pure-Python
75-
# module distribution) or standard Python library modules.
76-
# else:
77-
# Pure Python
78-
lambda libpython: (
79-
libpython
80-
if standard_lib
81-
else (
82-
os.path.join(prefix, "lib", "python3", "dist-packages")
83-
if is_default_prefix and not is_virtual_environment()
84-
else os.path.join(libpython, "site-packages")
85-
)
86-
)
87-
)(
88-
os.path.join(
89-
prefix,
90-
sys.platlibdir if plat_specific or standard_lib else "lib",
91-
"python" + get_python_version(),
92-
)
93-
)
94-
if os.name == "posix"
95-
else (
96-
os.path.join(prefix, "Lib")
97-
if standard_lib
98-
else os.path.join(prefix, "Lib", "site-packages")
99-
)
100-
)
31+
# Constant. Will never be used in Python =< 3.8
32+
Constant = type("Constant", (expr,), {})
10133

102-
else:
103-
from ast import Str
104-
from distutils.sysconfig import get_python_lib
10534

10635
package_name = "cdd"
10736

@@ -113,22 +42,6 @@ class DistutilsPlatformError(Exception):
11342
long_description = fh.read()
11443

11544

116-
def to_funcs(*paths):
117-
"""
118-
Produce function tuples that produce the local and install dir, respectively.
119-
120-
:param paths: one or more str, referring to relative folder names
121-
:type paths: ```*paths```
122-
123-
:return: 2 functions
124-
:rtype: ```tuple[Callable[Optional[List[str]], str], Callable[Optional[List[str]], str]]```
125-
"""
126-
return (
127-
partial(path.join, path.dirname(__file__), package_name, *paths),
128-
partial(path.join, get_python_lib(prefix=""), package_name, *paths),
129-
)
130-
131-
13245
def main():
13346
"""Main function for setup.py; this actually does the installation"""
13447
with open(
@@ -165,18 +78,14 @@ def main():
16578
)
16679

16780
setup(
168-
name="python-{}".format(package_name),
81+
name=package_name,
16982
author=__author__,
17083
author_email="807580+SamuelMarks@users.noreply.github.com",
17184
version=__version__,
85+
url="https://github.com/offscale/{}".format(package_name),
17286
description=__description__,
17387
long_description=long_description,
17488
long_description_content_type="text/markdown",
175-
url="https://github.com/offscale/{}-python".format(package_name),
176-
install_requires=["pyyaml"],
177-
test_suite="{}{}tests".format(package_name, path.extsep),
178-
packages=find_packages(),
179-
package_dir={package_name: package_name},
18089
classifiers=[
18190
"Development Status :: 3 - Alpha",
18291
"Environment :: Console",
@@ -194,6 +103,7 @@ def main():
194103
"Programming Language :: Python :: 3.10",
195104
"Programming Language :: Python :: 3.11",
196105
"Programming Language :: Python :: 3.12",
106+
"Programming Language :: Python :: 3.13",
197107
"Programming Language :: Python :: Implementation",
198108
"Programming Language :: Python :: Implementation :: CPython",
199109
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
@@ -203,6 +113,11 @@ def main():
203113
"Topic :: Software Development :: Compilers",
204114
"Topic :: Software Development :: Pre-processors",
205115
],
116+
license="(Apache-2.0 OR MIT)",
117+
license_files=["LICENSE-APACHE", "LICENSE-MIT"],
118+
install_requires=["pyyaml"],
119+
test_suite="{}{}tests".format(package_name, path.extsep),
120+
packages=find_packages(),
206121
python_requires=">=3.6",
207122
)
208123

0 commit comments

Comments
 (0)