| 1 |
PYTHON setup.py build_ext --inplace |
| 2 |
|
| 3 |
######## setup.py ########### |
| 4 |
|
| 5 |
from distutils.core import setup |
| 6 |
from Cython.Build import cythonize |
| 7 |
|
| 8 |
import Cython.Compiler.Scanning |
| 9 |
|
| 10 |
Cython.Compiler.Scanning.trace_scanner = 1 |
| 11 |
|
| 12 |
setup(ext_modules=cythonize("*.pyx")) |
| 13 |
|
| 14 |
try: |
| 15 |
from importlib.util import spec_from_file_location, module_from_spec |
| 16 |
except ImportError: |
| 17 |
# Py<=3.4 |
| 18 |
# Try to import from the current directory. |
| 19 |
import os, sys |
| 20 |
sys.path.insert(0, os.getcwd()) |
| 21 |
import simple |
| 22 |
else: |
| 23 |
# Py3.5+ |
| 24 |
import glob |
| 25 |
ext_files = glob.glob("simple*.so") + glob.glob("simple*.pyd") |
| 26 |
assert ext_files |
| 27 |
spec = spec_from_file_location('simple', ext_files[0]) |
| 28 |
simple = module_from_spec(spec) |
| 29 |
spec.loader.exec_module(simple) |
| 30 |
|
| 31 |
|
| 32 |
assert simple.test() == 123 |
| 33 |
|
| 34 |
|
| 35 |
######## simple.pyx ########### |
| 36 |
|
| 37 |
def test(): |
| 38 |
return 123 |