Skip to content

Commit

Permalink
[README.md,setup.py,cdd/shared/pkg_utils.py,cdd/tests/{mocks/cstify.p…
Browse files Browse the repository at this point in the history
…y,test_setup.py}] Python 3.13 support
  • Loading branch information
SamuelMarks committed Dec 5, 2024
1 parent 9cb55df commit 7675deb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 215 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cdd-python
==========
![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)
![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)
![Python implementation](https://img.shields.io/badge/implementation-cpython-blue.svg)
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![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)
Expand Down
88 changes: 4 additions & 84 deletions cdd/shared/pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,11 @@
from cdd.shared.pure_utils import PY_GTE_3_12

if PY_GTE_3_12:
import os
import sys
from sysconfig import _BASE_EXEC_PREFIX as BASE_EXEC_PREFIX
from sysconfig import _BASE_PREFIX as BASE_PREFIX
from sysconfig import _EXEC_PREFIX as EXEC_PREFIX
from sysconfig import _PREFIX as PREFIX
from sysconfig import get_python_version

Str = type(
"_Never",
tuple(),
{
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
or n
},
)

def is_virtual_environment():
"""
Whether one is in a virtual environment
"""
return sys.base_prefix != sys.prefix or hasattr(sys, "real_prefix")

def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"""Return the directory containing the Python library (standard or
site additions).
If 'plat_specific' is true, return the directory containing
platform-specific modules, i.e. any module from a non-pure-Python
module distribution; otherwise, return the platform-shared library
directory. If 'standard_lib' is true, return the directory
containing standard Python library modules; otherwise, return the
directory for site-specific modules.
If 'prefix' is supplied, use it instead of sys.base_prefix or
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
"""
is_default_prefix = not prefix or os.path.normpath(prefix) in (
"/usr",
"/usr/local",
)
prefix = (
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
if standard_lib
else (EXEC_PREFIX or PREFIX)
)

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""

assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '{}'".format(os.name)
)
return (
(
# plat_specific or standard_lib:
# Platform-specific modules (any module from a non-pure-Python
# module distribution) or standard Python library modules.
# else:
# Pure Python
lambda libpython: (
libpython
if standard_lib
else (
os.path.join(prefix, "lib", "python3", "dist-packages")
if is_default_prefix and not is_virtual_environment()
else os.path.join(libpython, "site-packages")
)
)
)(
os.path.join(
prefix,
sys.platlibdir if plat_specific or standard_lib else "lib",
"python" + get_python_version(),
)
)
if os.name == "posix"
else (
os.path.join(prefix, "Lib")
if standard_lib
else os.path.join(prefix, "Lib", "site-packages")
)
)
from sysconfig import get_paths

get_python_lib = lambda prefix="", *args, **kwargs: get_paths(*args, **kwargs)[
prefix or "purelib"
]
else:
from distutils.sysconfig import get_python_lib

Expand Down
19 changes: 8 additions & 11 deletions cdd/tests/mocks/cstify.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def add1(foo):
"""

"""foo"""
def g(): """foo : bar ; can"""; pass

def h(): # stuff
def g():
"""foo : bar ; can"""
pass

def adder(a: int,
b: int) -> int:
def h(): # stuff
pass

def adder(a: int, b: int) -> int:
"""
:param a: First arg
Expand All @@ -40,19 +42,14 @@ def adder(a: int,
= a + b
return res

r = (
add(foo, 1)
or
adder(foo, 1)
)
r = add(foo, 1) or adder(foo, 1)
if r:
None
elif r:
True
False
# ([5,5] @ [5,5]) *\
-5 / 7 ** 6 + \
6.0 - 6e1 & 1+2.34j
-5 / 7**6 + 6.0 - 6e1 & 1 + 2.34j
r <<= 5
print(r)
else:
Expand Down
13 changes: 0 additions & 13 deletions cdd/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ def test_properties(self) -> None:
self.assertEqual(getattr(self.mod, "package_name"), "cdd")
self.assertEqual(self.mod.__name__, "setup_py")

def test_to_funcs(self) -> None:
"""Tests that `to_funcs` produces the right local and install dirs"""
to_funcs = getattr(self.mod, "to_funcs")
args = "5", "6" # type: tuple[str, str]
local_dir_join_func_resp, install_dir_join_func_resp = map(
methodcaller("__call__"), to_funcs(*args)
)
self.assertNotEqual(local_dir_join_func_resp, install_dir_join_func_resp)
self.assertEqual(
local_dir_join_func_resp,
path.join(path.dirname(path.dirname(__file__)), *args),
)

def test_main(self) -> None:
"""
Tests that no errors occur in `main` function call (up to `setup()`, which is tested in setuptools)
Expand Down
127 changes: 21 additions & 106 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import sys
from ast import Assign, Constant, Name, parse
from ast import Assign, Name, parse
from functools import partial
from operator import attrgetter
from os import path
Expand All @@ -15,93 +15,22 @@
from setuptools import find_packages, setup

if sys.version_info[:2] >= (3, 12):
import os
from sysconfig import _BASE_EXEC_PREFIX as BASE_EXEC_PREFIX
from sysconfig import _BASE_PREFIX as BASE_PREFIX
from sysconfig import _EXEC_PREFIX as EXEC_PREFIX
from sysconfig import _PREFIX as PREFIX
from sysconfig import get_python_version

Str = type(
"_Never",
tuple(),
{
"__init__": lambda s=None, n=None, constant_value=None, string=None, col_offset=None, lineno=None: s
or n
},
)
from ast import Del as Str
else:
from ast import Str

def is_virtual_environment():
"""
Whether one is in a virtual environment
"""
return sys.base_prefix != sys.prefix or hasattr(sys, "real_prefix")

def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"""Return the directory containing the Python library (standard or
site additions).
If 'plat_specific' is true, return the directory containing
platform-specific modules, i.e. any module from a non-pure-Python
module distribution; otherwise, return the platform-shared library
directory. If 'standard_lib' is true, return the directory
containing standard Python library modules; otherwise, return the
directory for site-specific modules.
If 'prefix' is supplied, use it instead of sys.base_prefix or
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
"""
is_default_prefix = not prefix or os.path.normpath(prefix) in (
"/usr",
"/usr/local",
)
prefix = (
prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX)
if standard_lib
else (EXEC_PREFIX or PREFIX)
)
if sys.version_info[0] == 2:
from itertools import ifilter as filter
from itertools import imap as map

class DistutilsPlatformError(Exception):
"""DistutilsPlatformError"""
if sys.version_info[:2] > (3, 7):
from ast import Constant
else:
from ast import expr

assert os.name in frozenset(("posix", "nt")), DistutilsPlatformError(
"I don't know where Python installs its library "
"on platform '{}'".format(os.name)
)
return (
(
# plat_specific or standard_lib:
# Platform-specific modules (any module from a non-pure-Python
# module distribution) or standard Python library modules.
# else:
# Pure Python
lambda libpython: (
libpython
if standard_lib
else (
os.path.join(prefix, "lib", "python3", "dist-packages")
if is_default_prefix and not is_virtual_environment()
else os.path.join(libpython, "site-packages")
)
)
)(
os.path.join(
prefix,
sys.platlibdir if plat_specific or standard_lib else "lib",
"python" + get_python_version(),
)
)
if os.name == "posix"
else (
os.path.join(prefix, "Lib")
if standard_lib
else os.path.join(prefix, "Lib", "site-packages")
)
)
# Constant. Will never be used in Python =< 3.8
Constant = type("Constant", (expr,), {})

else:
from ast import Str
from distutils.sysconfig import get_python_lib

package_name = "cdd"

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


def to_funcs(*paths):
"""
Produce function tuples that produce the local and install dir, respectively.
:param paths: one or more str, referring to relative folder names
:type paths: ```*paths```
:return: 2 functions
:rtype: ```tuple[Callable[Optional[List[str]], str], Callable[Optional[List[str]], str]]```
"""
return (
partial(path.join, path.dirname(__file__), package_name, *paths),
partial(path.join, get_python_lib(prefix=""), package_name, *paths),
)


def main():
"""Main function for setup.py; this actually does the installation"""
with open(
Expand Down Expand Up @@ -165,18 +78,14 @@ def main():
)

setup(
name="python-{}".format(package_name),
name=package_name,
author=__author__,
author_email="[email protected]",
version=__version__,
url="https://github.com/offscale/{}".format(package_name),
description=__description__,
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/offscale/{}-python".format(package_name),
install_requires=["pyyaml"],
test_suite="{}{}tests".format(package_name, path.extsep),
packages=find_packages(),
package_dir={package_name: package_name},
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
Expand All @@ -194,6 +103,7 @@ def main():
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
Expand All @@ -203,6 +113,11 @@ def main():
"Topic :: Software Development :: Compilers",
"Topic :: Software Development :: Pre-processors",
],
license="(Apache-2.0 OR MIT)",
license_files=["LICENSE-APACHE", "LICENSE-MIT"],
install_requires=["pyyaml"],
test_suite="{}{}tests".format(package_name, path.extsep),
packages=find_packages(),
python_requires=">=3.6",
)

Expand Down

0 comments on commit 7675deb

Please sign in to comment.