forked from cython/cython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --module-name argument to cython command (cythonGH-4548)
It can be useful to specify the module name for the output file directly, rather than working it out from the enclosing file tree - particularly for out of tree build systems, like Meson. See background in rgommers/scipy#31 (comment) Backported-By: H. Vetinari <h.vetinari@gmx.com>
- Loading branch information
1 parent
4d626ca
commit ce9a543
Showing
4 changed files
with
124 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Test that we can set module name with --module-name arg to cython | ||
CYTHON a.pyx | ||
CYTHON --module-name w b.pyx | ||
CYTHON --module-name my_module.submod.x c.pyx | ||
PYTHON setup.py build_ext --inplace | ||
PYTHON checks.py | ||
|
||
######## checks.py ######## | ||
|
||
from importlib import import_module | ||
|
||
try: | ||
exc = ModuleNotFoundError | ||
except NameError: | ||
exc = ImportError | ||
|
||
for module_name, should_import in ( | ||
('a', True), | ||
('b', False), | ||
('w', True), | ||
('my_module.submod.x', True), | ||
('c', False), | ||
): | ||
try: | ||
import_module(module_name) | ||
except exc: | ||
if should_import: | ||
assert False, "Cannot import module " + module_name | ||
else: | ||
if not should_import: | ||
assert False, ("Can import module " + module_name + | ||
" but import should not be possible") | ||
|
||
|
||
######## setup.py ######## | ||
|
||
from distutils.core import setup | ||
from distutils.extension import Extension | ||
|
||
setup( | ||
ext_modules = [ | ||
Extension("a", ["a.c"]), | ||
Extension("w", ["b.c"]), | ||
Extension("my_module.submod.x", ["c.c"]), | ||
], | ||
) | ||
|
||
######## a.pyx ######## | ||
######## b.pyx ######## | ||
######## c.pyx ######## | ||
######## my_module/__init__.py ######## | ||
######## my_module/submod/__init__.py ######## |