-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.29] Add --module-name argument to cython command (GH-4906)
Backport of #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)
- Loading branch information
1 parent
34ce43c
commit 6cede00
Showing
4 changed files
with
138 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 ######## |