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
|