Skip to content

Commit 2c35d2e

Browse files
committed
[FIX] server: do not detect empty directory as module while dependencies scan
1 parent 9b8979e commit 2c35d2e

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

server/core/import_resolver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ def resolve_import_stmt(ls, source_file_symbol, parent_symbol, from_stmt, name_a
6060
res[name_index][1] = name_symbol
6161
return res
6262

63+
def find_module(ls, name):
64+
from .python_arch_builder import PythonArchBuilder
65+
odoo_addons = Odoo.get().get_symbol(["odoo", "addons"], [])
66+
for path in odoo_addons.get_paths():
67+
full_path = os.path.join(path, name)
68+
if PythonUtils.is_dir_cs(full_path):
69+
parser = PythonArchBuilder(ls, odoo_addons, full_path)
70+
sym = parser.load_arch(require_module=True)
71+
if sym:
72+
return sym
73+
return None
74+
6375
def _resolve_packages(file_symbol, level, from_stmt):
6476
"""based on the file path and the from statement of an import statement, return the file tree
6577
to use in a get_symbol search"""

server/core/module.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ def load_depends(self, ls):
147147
loaded = []
148148
for depend in self.depends:
149149
if depend not in Odoo.get().modules:
150-
from .import_resolver import resolve_import_stmt
151-
odoo_addons = Odoo.get().get_symbol(["odoo", "addons"], [])
152-
alias = [ast.alias(name=depend, asname=None)]
153-
_, dep_module, _ = resolve_import_stmt(ls, odoo_addons, odoo_addons, None, alias, 1, 0, 0)[0]
150+
from .import_resolver import find_module
151+
dep_module = find_module(ls, depend)
154152
if not dep_module:
155153
Odoo.get().not_found_symbols.add(self)
156154
self.not_found_paths.append((BuildSteps.ARCH, ["odoo", "addons", depend]))

server/core/python_arch_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ def load_arch(self, require_module=False):
7272
else:
7373
self.filePath = os.path.join(self.filePath, "__init__.pyi")
7474
symbol.i_ext = "i"
75-
else:
75+
elif not require_module:
7676
symbol = NamespaceSymbol(self.filePath.split(os.sep)[-1], self.filePath)
7777
self.symStack[-1].add_symbol(symbol)
7878
self.symStack.append(symbol)
7979
return self.symStack[1]
80+
else:
81+
return None
8082
else:
8183
symbol = FileSymbol(self.filePath.split(os.sep)[-1].split(".py")[0], self.filePath)
8284
self.symStack[-1].add_symbol(symbol)

0 commit comments

Comments
 (0)