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
|
--- contrib/tools/cython/Cython/Compiler/Main.py (index)
+++ contrib/tools/cython/Cython/Compiler/Main.py (working tree)
@@ -701,48 +701,27 @@ def search_include_directories(dirs, qualified_name, suffix="", pos=None, includ
if suffix:
dotted_filename += suffix
- for dirname in dirs:
- path = os.path.join(dirname, dotted_filename)
- if os.path.exists(path):
- return path
-
- # search for filename in package structure e.g. <dir>/foo/bar.pxd or <dir>/foo/bar/__init__.pxd
if not include:
-
names = qualified_name.split('.')
package_names = tuple(names[:-1])
module_name = names[-1]
+ module_filename = module_name + suffix
+ package_filename = "__init__" + suffix
- # search for standard packages first - PEP420
- namespace_dirs = []
- for dirname in dirs:
- package_dir, is_namespace = Utils.check_package_dir(dirname, package_names)
- if package_dir is not None:
- if is_namespace:
- namespace_dirs.append(package_dir)
- continue
- path = search_module_in_dir(package_dir, module_name, suffix)
- if path:
- return path
-
- # search for namespaces second - PEP420
- for package_dir in namespace_dirs:
- path = search_module_in_dir(package_dir, module_name, suffix)
- if path:
- return path
+ for dirname in dirs:
+ path = os.path.join(dirname, dotted_filename)
+ if os.path.exists(path):
+ return path
# Arcadia-specific lookup: search for packages in include paths,
# ignoring existence of __init__.py files as packages markers
# (they are not required by Arcadia build system)
- module_filename = module_name + suffix
- package_filename = "__init__" + suffix
-
- for dir in dirs:
- package_dir = os.path.join(dir, *package_names)
+ if not include:
+ package_dir = os.path.join(dirname, *package_names)
path = os.path.join(package_dir, module_filename)
if os.path.exists(path):
return path
- path = os.path.join(dir, package_dir, module_name,
+ path = os.path.join(dirname, package_dir, module_name,
package_filename)
if os.path.exists(path):
return path
--- contrib/tools/cython/Cython/Compiler/Nodes.py (index)
+++ contrib/tools/cython/Cython/Compiler/Nodes.py (working tree)
@@ -8944,7 +8944,7 @@ class FromCImportStatNode(StatNode):
# 2. case: importing from same level but current dir is not package: from . import module
error(self.pos, "relative cimport from non-package directory is not allowed")
return
- module_scope = env.find_module(self.module_name, self.pos, relative_level=self.relative_level)
+ module_scope = env.find_module(self.module_name, self.pos, relative_level=self.relative_level, need_pxd=0)
if not module_scope:
return
module_name = module_scope.qualified_name
--- contrib/tools/cython/Cython/Compiler/Symtab.py (index)
+++ contrib/tools/cython/Cython/Compiler/Symtab.py (working tree)
@@ -1411,7 +1411,7 @@ class ModuleScope(Scope):
entry.qualified_name = self.builtin_scope().qualify_name(name)
return entry
- def find_module(self, module_name, pos, relative_level=-1):
+ def find_module(self, module_name, pos, relative_level=-1, need_pxd=1):
# Find a module in the import namespace, interpreting
# relative imports relative to this module's parent.
# Finds and parses the module's .pxd file if the module
@@ -1440,7 +1440,7 @@ class ModuleScope(Scope):
module_scope = self.global_scope()
return module_scope.context.find_module(
- module_name, from_module=from_module, pos=pos, absolute_fallback=absolute_fallback, relative_import=is_relative_import)
+ module_name, from_module=from_module, pos=pos, absolute_fallback=absolute_fallback, relative_import=is_relative_import, need_pxd=need_pxd)
def find_submodule(self, name, as_package=False):
# Find and return scope for a submodule of this module,
|