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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
PYTHON setup.py build_ext --inplace
PYTHON -c "import my_test_package as p; assert not p.__file__.rstrip('co').endswith('.py'), p.__file__; p.test()"
PYTHON -c "import my_test_package.a as a; a.test()"
PYTHON -c "import my_test_package.another as p; assert not p.__file__.rstrip('co').endswith('.py'), p.__file__; p.test()"
PYTHON -c "import my_test_package.another.a as a; a.test()"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize(["my_test_package/**/*.py"]),
)
######## my_test_package/__init__.py ########
# cython: set_initial_path=SOURCEFILE
initial_path = __path__
initial_file = __file__
try:
from . import a
import_error = None
except ImportError as e:
import_error = e
import traceback
traceback.print_exc()
def test():
print("FILE: ", initial_file)
print("PATH: ", initial_path)
assert initial_path[0].endswith('my_test_package'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
assert import_error is None, import_error
######## my_test_package/another/__init__.py ########
# cython: set_initial_path=SOURCEFILE
initial_path = __path__
initial_file = __file__
try:
from . import a
import_error = None
except ImportError as e:
import_error = e
import traceback
traceback.print_exc()
def test():
print("FILE: ", initial_file)
print("PATH: ", initial_path)
assert initial_path[0].endswith('another'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
assert import_error is None, import_error
######## my_test_package/a.py ########
# cython: set_initial_path=SOURCEFILE
initial_file = __file__
try:
initial_path = __path__
except NameError:
got_name_error = True
else:
got_name_error = False
def test():
assert initial_file.endswith('a.py'), initial_file
assert got_name_error, "looks like __path__ was set at module init time: " + initial_path
######## my_test_package/another/a.py ########
# cython: set_initial_path=SOURCEFILE
initial_file = __file__
try:
initial_path = __path__
except NameError:
got_name_error = True
else:
got_name_error = False
def test():
assert initial_file.endswith('a.py'), initial_file
assert got_name_error, "looks like __path__ was set at module init time: " + initial_path
|