Commit f7342f76 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2794 from cython/gh2665_package_init_pyx

Use the same list of potential package init file names everywhere
parents f00af64b c8e03b35
...@@ -69,7 +69,7 @@ def parse_compile_time_env(option, name, value, parser): ...@@ -69,7 +69,7 @@ def parse_compile_time_env(option, name, value, parser):
def find_package_base(path): def find_package_base(path):
base_dir, package_path = os.path.split(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) base_dir, parent = os.path.split(base_dir)
package_path = '%s/%s' % (parent, package_path) package_path = '%s/%s' % (parent, package_path)
return base_dir, package_path return base_dir, package_path
......
...@@ -219,7 +219,7 @@ class Context(object): ...@@ -219,7 +219,7 @@ class Context(object):
# look for the non-existing pxd file next time. # look for the non-existing pxd file next time.
scope.pxd_file_loaded = True scope.pxd_file_loaded = True
package_pathname = self.search_include_directories(qualified_name, ".py", pos) 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 pass
else: else:
error(pos, "'%s.pxd' not found" % qualified_name.replace('.', os.sep)) error(pos, "'%s.pxd' not found" % qualified_name.replace('.', os.sep))
......
...@@ -23,6 +23,8 @@ import codecs ...@@ -23,6 +23,8 @@ import codecs
import shutil import shutil
from contextlib import contextmanager from contextlib import contextmanager
PACKAGE_FILES = ("__init__.py", "__init__.pyc", "__init__.pyx", "__init__.pxd")
modification_time = os.path.getmtime modification_time = os.path.getmtime
_function_caches = [] _function_caches = []
...@@ -191,10 +193,7 @@ def check_package_dir(dir, package_names): ...@@ -191,10 +193,7 @@ def check_package_dir(dir, package_names):
@cached_function @cached_function
def is_package_dir(dir_path): def is_package_dir(dir_path):
for filename in ("__init__.py", for filename in PACKAGE_FILES:
"__init__.pyc",
"__init__.pyx",
"__init__.pxd"):
path = os.path.join(dir_path, filename) path = os.path.join(dir_path, filename)
if path_exists(path): if path_exists(path):
return 1 return 1
......
...@@ -419,11 +419,12 @@ VER_DEP_MODULES = { ...@@ -419,11 +419,12 @@ VER_DEP_MODULES = {
# to be unsafe... # to be unsafe...
(2,999): (operator.lt, lambda x: x in ['run.special_methods_T561_py3', (2,999): (operator.lt, lambda x: x in ['run.special_methods_T561_py3',
'run.test_raisefrom', 'run.test_raisefrom',
'run.different_package_names',
]), ]),
(3,): (operator.ge, lambda x: x in ['run.non_future_division', (3,): (operator.ge, lambda x: x in ['run.non_future_division',
'compile.extsetslice', 'compile.extsetslice',
'compile.extdelslice', 'compile.extdelslice',
'run.special_methods_T561_py2' 'run.special_methods_T561_py2',
]), ]),
(3,3) : (operator.lt, lambda x: x in ['build.package_compilation', (3,3) : (operator.lt, lambda x: x in ['build.package_compilation',
'run.yield_from_py33', '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