Commit b859cf2b authored by Stefan Behnel's avatar Stefan Behnel

Allow globally forcing C file regeneration by setting the env var...

Allow globally forcing C file regeneration by setting the env var CYTHON_FORCE_REGEN=1, e.g. from external build systems.
parent 14150abd
......@@ -24,6 +24,9 @@ Features added
* ``cythonize()`` and the corresponding CLI command now regenerate the output files
also when they already exist but were generated by a different Cython version.
* The environment variable ``CYTHON_FORCE_REGEN=1`` can be used to force ``cythonize``
to regenerate the output files regardless of modification times and changes.
* The generated C code now compiles in CPython 3.11a4.
(Github issue :issue:`4500`)
......
......@@ -883,7 +883,7 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
# This is the user-exposed entry point.
def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False, force=False, language=None,
def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False, force=None, language=None,
exclude_failures=False, show_all_warnings=False, **options):
"""
Compile a set of source modules into C/C++ files and return a list of distutils
......@@ -976,6 +976,9 @@ def cythonize(module_list, exclude=None, nthreads=0, aliases=None, quiet=False,
pythran_options.cplus = True
pythran_options.np_pythran = True
if force is None:
force = os.environ.get("CYTHON_FORCE_REGEN") == "1" # allow global overrides for build systems
c_options = CompilationOptions(**options)
cpp_options = CompilationOptions(**options); cpp_options.cplus = True
ctx = Context.from_options(c_options)
......
......@@ -7,6 +7,7 @@ PYTHON test.py
######## test.py ########
import os.path
import time
from Cython.Utils import GENERATED_BY_MARKER_BYTES, clear_function_caches, clear_method_caches
from Cython.Build.Dependencies import cythonize, DependencyTree
......@@ -85,3 +86,11 @@ with open("a.c", "rb") as f:
# now up to date
fresh_cythonize("*.pyx")
assert mtime < new_mtime < other_cython_mtime <= latest_mtime == getmtime("a.c")
# force regeneration with environment variable
os.environ["CYTHON_FORCE_REGEN"] = "1"
time.sleep(0.1)
assert latest_mtime == getmtime("a.c")
fresh_cythonize("*.pyx")
assert latest_mtime < getmtime("a.c")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment