File: module_name_arg.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (52 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 ########