diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 75d6483df445415452781eadf169fd771baea8f8..348a3eb013584d1576dc9eb377d01b9c5393afea 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -182,7 +182,7 @@ class Context(object): # the directory containing the source file is searched first # for a dotted filename, and its containing package root # directory is searched first for a non-dotted filename. - pxd = self.search_include_directories(qualified_name, ".pxd", pos) + pxd = self.search_include_directories(qualified_name, ".pxd", pos, sys_path=True) if pxd is None: # XXX Keep this until Includes/Deprecated is removed if (qualified_name.startswith('python') or qualified_name in ('stdlib', 'stdio', 'stl')): @@ -221,13 +221,16 @@ class Context(object): return path def search_include_directories(self, qualified_name, suffix, pos, - include=False): + include=False, sys_path=False): # Search the list of include directories for the given # file name. If a source file position is given, first # searches the directory containing that file. Returns # None if not found, but does not report an error. # The 'include' option will disable package dereferencing. + # If 'sys_path' is True, also search sys.path. dirs = self.include_directories + if sys_path: + dirs = dirs + sys.path if pos: file_desc = pos[0] if not isinstance(file_desc, FileSourceDescriptor): diff --git a/tests/run/cimport_from_sys_path.srctree b/tests/run/cimport_from_sys_path.srctree new file mode 100644 index 0000000000000000000000000000000000000000..1fc031eaadb4ef33949f363ce72918d4ad391961 --- /dev/null +++ b/tests/run/cimport_from_sys_path.srctree @@ -0,0 +1,31 @@ +PYTHON setup.py build_ext --inplace +PYTHON -c "import a" + +######## setup.py ######## + +from Cython.Build import cythonize +from distutils.core import setup + +# Add ./site-packages to sys.path +from os.path import realpath +import sys +sys.path.append(realpath('site-packages')) + +setup( + ext_modules = cythonize("*.pyx"), +) + +######## site-packages/b/__init__.py ######## + +######## site-packages/b/other.pxd ######## + +cdef inline foo(int a): + return a**2 + +######## a.pyx ######## + +from b.other cimport foo +print foo(10) + +cimport b.other +print b.other.foo(10)