Skip to content

Commit

Permalink
Made compatible to Python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
HeWeMel committed Dec 26, 2024
1 parent 06dfd6b commit ae84480
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,47 @@ def find_sources(exclude_from_compilation):


compiler = os.environ.get('SETUP_BUILD_EXTENSION', "False").capitalize()
match compiler:
case "False":
print("\nsetup.py: Building sdist (tarball) / and or pure Python wheel.")
print("(Set environment variable SETUP_BUILD_EXTENSION to MyPyC or Cython "
"to compile binaries.)")
ext_modules = []
if compiler == "False":
print("\nsetup.py: Building sdist (tarball) / and or pure Python wheel.")
print("(Set environment variable SETUP_BUILD_EXTENSION to MyPyC or Cython "
"to compile binaries.)")
ext_modules = []

case "Mypyc":
print(f"\nsetup.py: Compiling binaries using MyPyC.")
print("(Set environment variable SETUP_BUILD_EXTENSION to False "
"to build sdist / and or pure Python wheel instead.)")

from mypyc.build import mypycify
exclude_from_compilation = [
# The following file contains classes, compilation would be useful, but
# it is intentionally not compiled here due to the following issue of
# MyPyC:
# https://github.com/mypyc/mypyc/issues/1022
'depth_first_enum_types.py',
# The following file subclasses tuple[int]. MyPyC does not support this.
# But on CPython this us much faster than to store the tuple in an attribute
# Conditional class definition is also not supported. So, we simply exclude
# this file from compilation.
'_extra_matrix_gadgets.py',
]
compile_this = find_sources(exclude_from_compilation)
ext_modules = mypycify(compile_this, strip_asserts=False)
elif compiler == "Mypyc":
print(f"\nsetup.py: Compiling binaries using MyPyC.")
print("(Set environment variable SETUP_BUILD_EXTENSION to False "
"to build sdist / and or pure Python wheel instead.)")

case "Cython":
print(f"\nsetup.py: Compiling binaries using Cython.")
print("(Set environment variable SETUP_BUILD_EXTENSION to False "
"to build sdist / and or pure Python wheel instead.)")
from Cython.Build import cythonize
exclude_from_compilation = []
compile_this = find_sources(exclude_from_compilation)
ext_modules = cythonize(compile_this, compiler_directives={'language_level': 3})
from mypyc.build import mypycify
exclude_from_compilation = [
# The following file contains classes, compilation would be useful, but
# it is intentionally not compiled here due to the following issue of
# MyPyC:
# https://github.com/mypyc/mypyc/issues/1022
'depth_first_enum_types.py',
# The following file subclasses tuple[int]. MyPyC does not support this.
# But on CPython this us much faster than to store the tuple in an attribute
# Conditional class definition is also not supported. So, we simply exclude
# this file from compilation.
'_extra_matrix_gadgets.py',
]
compile_this = find_sources(exclude_from_compilation)
ext_modules = mypycify(compile_this, strip_asserts=False)

case _:
raise RuntimeError(
"Valid values or environment variable SETUP_BUILD_EXTENSION are:"
" 'False', 'MyPyC', and 'Cython'"
"If no value is set, this equals to 'False'.")
elif compiler == "Cython":
print(f"\nsetup.py: Compiling binaries using Cython.")
print("(Set environment variable SETUP_BUILD_EXTENSION to False "
"to build sdist / and or pure Python wheel instead.)")
from Cython.Build import cythonize
exclude_from_compilation = []
compile_this = find_sources(exclude_from_compilation)
ext_modules = cythonize(compile_this, compiler_directives={'language_level': 3})

else:
raise RuntimeError(
"Valid values or environment variable SETUP_BUILD_EXTENSION are:"
" 'False', 'MyPyC', and 'Cython'"
"If no value is set, this equals to 'False'.")

if ext_modules:
setup(
Expand Down

0 comments on commit ae84480

Please sign in to comment.