Skip to content

Commit

Permalink
C Extension optional by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Sulla committed Feb 17, 2023
1 parent 4b0bc55 commit 2348800
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion frozendict/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "2.3.4"
version = "2.3.5"
66 changes: 49 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import sys
from platform import python_implementation
from os import environ

name = "frozendict"
main_package_name = "frozendict"
Expand Down Expand Up @@ -109,21 +110,39 @@
undef_macros = []

argv = sys.argv
argv_1_exists = len(argv) > 1

if argv[1] == "c_debug":
if argv_1_exists and argv[1] == "c_debug":
undef_macros = ["NDEBUG"]

ext_modules = []

ext_modules.append(setuptools.Extension(
ext1_fullname,
sources = cpython_sources,
include_dirs = cpython_include_dirs,
extra_compile_args = extra_compile_args,
undef_macros = undef_macros,
))


def get_ext_module(
fullname,
sources,
include_dirs,
extra_compile_args,
undef_macros,
optional
):
ext_module = setuptools.Extension(
fullname,
sources = sources,
include_dirs = include_dirs,
extra_compile_args = extra_compile_args,
undef_macros = undef_macros,
optional = optional,
)

return ext_module

def get_ext_module_1(optional):
return get_ext_module(
fullname = ext1_fullname,
sources = cpython_sources,
include_dirs = cpython_include_dirs,
extra_compile_args = extra_compile_args,
undef_macros = undef_macros,
optional = optional,
)

# C extension - END

Expand Down Expand Up @@ -155,23 +174,36 @@

custom_arg = None

custom_args = ("py", "c", "c_debug")
custom_args_py = ("py", )
custom_args_c = ("c", "c_debug")
custom_args = custom_args_py + custom_args_c

if len(argv) > 1 and argv[1] in custom_args:
if argv_1_exists and argv[1] in custom_args:
custom_arg = argv[1]
sys.argv = [sys.argv[0]] + sys.argv[2:]
sys.argv = [argv[0]] + argv[2:]

impl = python_implementation()

# C Extension is optional by default from version 2.3.5
optional = True

if custom_arg == None:
# If the module is built by pipeline, C Extension must be mandatory.
optional = environ.get('CIBUILDWHEEL', '0') != '1'

if impl == "PyPy":
custom_arg = "py"
else:
custom_arg = "c"

elif custom_arg in custom_args_c:
optional = False

if custom_arg == "py":
if custom_arg in custom_args_py:
setuptools.setup(**common_setup_args)
elif custom_arg in ("c", "c_debug"):
elif custom_arg in custom_args_c:
ext_module_1 = get_ext_module_1(optional)
ext_modules = [ext_module_1]
setuptools.setup(ext_modules = ext_modules, **common_setup_args)
else:
raise ValueError(f"Unsupported custom_arg {custom_arg}")

0 comments on commit 2348800

Please sign in to comment.