Commit c8e03b35 authored by Stefan Behnel's avatar Stefan Behnel

Use the same list of potential package init file names everywhere (not just...

Use the same list of potential package init file names everywhere (not just "__init__.py" but also .pxd and .pyx).
Closes #2665.
parent f00af64b
......@@ -69,7 +69,7 @@ def parse_compile_time_env(option, name, value, parser):
def find_package_base(path):
base_dir, package_path = os.path.split(path)
while os.path.isfile(os.path.join(base_dir, '__init__.py')):
while is_package_dir(base_dir):
base_dir, parent = os.path.split(base_dir)
package_path = '%s/%s' % (parent, package_path)
return base_dir, package_path
......
......@@ -219,7 +219,7 @@ class Context(object):
# look for the non-existing pxd file next time.
scope.pxd_file_loaded = True
package_pathname = self.search_include_directories(qualified_name, ".py", pos)
if package_pathname and package_pathname.endswith('__init__.py'):
if package_pathname and package_pathname.endswith(Utils.PACKAGE_FILES):
pass
else:
error(pos, "'%s.pxd' not found" % qualified_name.replace('.', os.sep))
......
......@@ -23,6 +23,8 @@ import codecs
import shutil
from contextlib import contextmanager
PACKAGE_FILES = ("__init__.py", "__init__.pyc", "__init__.pyx", "__init__.pxd")
modification_time = os.path.getmtime
_function_caches = []
......@@ -191,10 +193,7 @@ def check_package_dir(dir, package_names):
@cached_function
def is_package_dir(dir_path):
for filename in ("__init__.py",
"__init__.pyc",
"__init__.pyx",
"__init__.pxd"):
for filename in PACKAGE_FILES:
path = os.path.join(dir_path, filename)
if path_exists(path):
return 1
......
......@@ -419,11 +419,12 @@ VER_DEP_MODULES = {
# to be unsafe...
(2,999): (operator.lt, lambda x: x in ['run.special_methods_T561_py3',
'run.test_raisefrom',
'run.different_package_names',
]),
(3,): (operator.ge, lambda x: x in ['run.non_future_division',
'compile.extsetslice',
'compile.extdelslice',
'run.special_methods_T561_py2'
'run.special_methods_T561_py2',
]),
(3,3) : (operator.lt, lambda x: x in ['build.package_compilation',
'run.yield_from_py33',
......
# mode: run
# tag: import,cimport,packages
PYTHON setup.py build_ext --inplace
PYTHON -c "import pkg_py"
PYTHON -c "import pkg_py.pkg_pyx"
PYTHON -c "import pkg_py.pkg_pyx.module as module; module.run_test()"
######## setup.py ########
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize('**/*.pyx', language_level=3),
)
######## pkg_py/__init__.py ########
TYPE = 'py'
######## pkg_py/pkg_pyx/__init__.pyx ########
TYPE = 'pyx'
######## pkg_py/pkg_pyx/pkg_pxd/__init__.pxd ########
# Not what Python would consider a package, but Cython can use it for cimports.
from libc.math cimport fabs
######## pkg_py/pkg_pyx/module.pyx ########
from pkg_py.pkg_pyx.pkg_pxd cimport fabs
def run_test():
import pkg_py
assert pkg_py.TYPE == 'py'
import pkg_py.pkg_pyx
assert pkg_py.pkg_pyx.TYPE == 'pyx'
assert fabs(-2.0) == 2.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment