From ae84480c9d5a6c5f9d524f185c5e30cb7008ebdf Mon Sep 17 00:00:00 2001 From: HeWeMel <69761336+HeWeMel@users.noreply.github.com> Date: Thu, 26 Dec 2024 18:28:06 +0100 Subject: [PATCH] Made compatible to Python 3.9 --- setup.py | 77 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/setup.py b/setup.py index 707b96b..7c9a2d4 100644 --- a/setup.py +++ b/setup.py @@ -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(