| 1 |
# Test that we can set module name with --module-name arg to cython |
| 2 |
CYTHON a.pyx |
| 3 |
CYTHON --module-name w b.pyx |
| 4 |
CYTHON --module-name my_module.submod.x c.pyx |
| 5 |
PYTHON setup.py build_ext --inplace |
| 6 |
PYTHON checks.py |
| 7 |
|
| 8 |
######## checks.py ######## |
| 9 |
|
| 10 |
from importlib import import_module |
| 11 |
|
| 12 |
try: |
| 13 |
exc = ModuleNotFoundError |
| 14 |
except NameError: |
| 15 |
exc = ImportError |
| 16 |
|
| 17 |
for module_name, should_import in ( |
| 18 |
('a', True), |
| 19 |
('b', False), |
| 20 |
('w', True), |
| 21 |
('my_module.submod.x', True), |
| 22 |
('c', False), |
| 23 |
): |
| 24 |
try: |
| 25 |
import_module(module_name) |
| 26 |
except exc: |
| 27 |
if should_import: |
| 28 |
assert False, "Cannot import module " + module_name |
| 29 |
else: |
| 30 |
if not should_import: |
| 31 |
assert False, ("Can import module " + module_name + |
| 32 |
" but import should not be possible") |
| 33 |
|
| 34 |
|
| 35 |
######## setup.py ######## |
| 36 |
|
| 37 |
from distutils.core import setup |
| 38 |
from distutils.extension import Extension |
| 39 |
|
| 40 |
setup( |
| 41 |
ext_modules = [ |
| 42 |
Extension("a", ["a.c"]), |
| 43 |
Extension("w", ["b.c"]), |
| 44 |
Extension("my_module.submod.x", ["c.c"]), |
| 45 |
], |
| 46 |
) |
| 47 |
|
| 48 |
######## a.pyx ######## |
| 49 |
######## b.pyx ######## |
| 50 |
######## c.pyx ######## |
| 51 |
######## my_module/__init__.py ######## |
| 52 |
######## my_module/submod/__init__.py ######## |