Commit cf5b4acb authored by Egor Dranischnikow's avatar Egor Dranischnikow

fail early if module is called cython (and not submodule)

parent 3f7a0302
...@@ -491,5 +491,5 @@ def add_metaclass(metaclass): ...@@ -491,5 +491,5 @@ def add_metaclass(metaclass):
def raise_error_if_module_name_forbidden(full_module_name): def raise_error_if_module_name_forbidden(full_module_name):
#it is bad idea to call the pyx-file cython.pyx, so fail early #it is bad idea to call the pyx-file cython.pyx, so fail early
if full_module_name == 'cython' or full_module_name.endswith('.cython'): if full_module_name == 'cython' or full_module_name.startswith('cython.'):
raise ValueError('cython is a special module, cannot be used as a module name') raise ValueError('cython is a special module, cannot be used as a module name')
...@@ -5,7 +5,7 @@ PYTHON -c "import cython_tests" ...@@ -5,7 +5,7 @@ PYTHON -c "import cython_tests"
from Cython.Build.Cythonize import main as cythonize from Cython.Build.Cythonize import main as cythonize
for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]: for test_case in ["cython.pyx", "src2/cython.pyx", "src/cython/helper.pyx"]:
try: try:
cythonize([test_case]) cythonize([test_case])
except ValueError: except ValueError:
...@@ -13,11 +13,12 @@ for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]: ...@@ -13,11 +13,12 @@ for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]:
else: else:
assert False, "ValueError not raised - forbidding cythonize "+test_case+" doesn't work" assert False, "ValueError not raised - forbidding cythonize "+test_case+" doesn't work"
try: for test_case in ["notcython.pyx", "my_module/cython.pyx", "cythontest/helper.pyx"]:
cythonize(["notcython.pys"]) try:
except ValueError: cythonize([test_case])
assert False, "ValueError raised - forbidding cythonize notcython.pyx should work" except ValueError:
else: assert False, "ValueError raised - cythonize "+test_case+" should work"
else:
pass pass
######## cython_tests.py ######## ######## cython_tests.py ########
...@@ -26,7 +27,7 @@ else: ...@@ -26,7 +27,7 @@ else:
from Cython.Compiler.Main import main as cython from Cython.Compiler.Main import main as cython
import sys import sys
for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]: for test_case in ["cython.pyx", "scr2/cython.pyx", "src/cython/helper.pyx"]:
sys.argv=["cython", test_case] #cython.py will extract parameters from sys.argv sys.argv=["cython", test_case] #cython.py will extract parameters from sys.argv
try: try:
cython(command_line=1) cython(command_line=1)
...@@ -35,16 +36,23 @@ for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]: ...@@ -35,16 +36,23 @@ for test_case in ["cython.pyx", "src/cython.pyx", "src2/cython.pyx"]:
else: else:
assert False, "ValueError not raised - forbidding cython "+test_case+" doesn't work" assert False, "ValueError not raised - forbidding cython "+test_case+" doesn't work"
sys.argv=["cython", "notcython.pyx"] #cython.py will extract parameters from sys.argv
try: for test_case in ["notcython.pyx", "my_module/cython.pyx", "cythontest/helper.pyx"]:
cython(["notcython.pys"]) sys.argv=["cython", test_case] #cython.py will extract parameters from sys.argv
except ValueError: try:
assert False, "ValueError raised - forbidding cythonize notcython.pyx should work" cython([test_case])
else: except ValueError:
assert False, "ValueError raised - cython "+test_case+" should work"
else:
pass pass
######## cython.pyx ######## ######## cython.pyx ########
######## src/__init__.py ######## ######## my_module/__init__.py ########
######## src/cython.pyx ######## ######## my_module/cython.pyx ########
######## notcython.pyx ######## ######## notcython.pyx ########
######## src2/cython.pyx ######## ######## src2/cython.pyx ########
######## src/cython/__init__.py ########
######## src/cython/helper.pyx ########
######## cythontest/__init__.py ########
######## cythontest/helper.pyx ########
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