summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-01-11 06:50:33 +0100
committerStefan Behnel <stefan_ml@behnel.de>2019-01-11 07:45:50 +0100
commitc8e03b35ed434430c84e212acaa409ce4cab5a4d (patch)
tree8464c15577f5cc3f7aa7608b31787d01afd6e338
parentf00af64bcc2cef4c3fb1433ed670ab5f9970e2cd (diff)
downloadcython-gh2665_package_init_pyx.tar.gz
Use the same list of potential package init file names everywhere (not just "__init__.py" but also .pxd and .pyx).gh2665_package_init_pyx
Closes #2665.
-rw-r--r--Cython/Build/Cythonize.py2
-rw-r--r--Cython/Compiler/Main.py2
-rw-r--r--Cython/Utils.py7
-rwxr-xr-xruntests.py3
-rw-r--r--tests/run/different_package_names.srctree43
5 files changed, 50 insertions, 7 deletions
diff --git a/Cython/Build/Cythonize.py b/Cython/Build/Cythonize.py
index 9de84d5c8..f3704d431 100644
--- a/Cython/Build/Cythonize.py
+++ b/Cython/Build/Cythonize.py
@@ -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
diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py
index 9130fbf19..ab7a700bb 100644
--- a/Cython/Compiler/Main.py
+++ b/Cython/Compiler/Main.py
@@ -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))
diff --git a/Cython/Utils.py b/Cython/Utils.py
index 6caf41046..fe970a6ce 100644
--- a/Cython/Utils.py
+++ b/Cython/Utils.py
@@ -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
diff --git a/runtests.py b/runtests.py
index 9f0f4a7db..03ffe757d 100755
--- a/runtests.py
+++ b/runtests.py
@@ -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',
diff --git a/tests/run/different_package_names.srctree b/tests/run/different_package_names.srctree
new file mode 100644
index 000000000..f70699012
--- /dev/null
+++ b/tests/run/different_package_names.srctree
@@ -0,0 +1,43 @@
+# 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