File: cpdef_scoped_enums_import.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: 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 (71 lines) | stat: -rw-r--r-- 1,522 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# mode: run
# tag: cpp, cpp11

"""
PYTHON setup.py build_ext --inplace
PYTHON -c "import runner"
"""

######## setup.py ########

from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(ext_modules=cythonize("*.pyx", language='c++'))

setup(
  ext_modules = cythonize([
              "cheese.pyx",
              "import_scoped_enum_test.pyx",
              "dotted_import_scoped_enum_test.pyx"
              ])
)

######## cheese.pxd ########
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11


cdef extern from * namespace "Namespace":
    """
    namespace Namespace {
        enum class Cheese {
            cheddar = 1,
            camembert = 2
        };
    }
    """
    cpdef enum class Cheese:
        cheddar
        camembert

######## cheese.pyx ########
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11

pass

######## import_scoped_enum_test.pyx ########
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11

from cheese import Cheese
from cheese cimport Cheese

cdef Cheese c = Cheese.cheddar
assert list(Cheese) == [1, 2]

######## dotted_import_scoped_enum_test.pyx ########
# distutils: language = c++
# distutils: extra_compile_args = -std=c++11


cimport cheese

cdef cheese.Cheese c = cheese.Cheese.cheddar
assert [cheese.Cheese.cheddar, cheese.Cheese.camembert] == [1, 2]
cdef cheese.Cheese d = int(1)

######## runner.py ########

import import_scoped_enum_test
import dotted_import_scoped_enum_test