Skip to content

Commit 23309d7

Browse files
authoredOct 10, 2024··
[Dexter] Set up ComInterface module to be imported correctly (#111850)
Fixes issue added by: #111833 Following the previous commit that changed how Dexter imports modules, the ComInterface module import became broken. This is because it had a different directory structure to other modules, where we want to import single file rather than a dir containing a __init__.py. For this case, an optional extra arg has been added to load_module allowing a filename to be specified, letting us import ComInterface.py directly and fixing the issue.
1 parent f5aec03 commit 23309d7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
 

‎cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
def _load_com_module():
2525
try:
2626
return load_module(
27-
"ComInterface", os.path.join(os.path.dirname(__file__), "windows")
27+
"ComInterface",
28+
os.path.join(os.path.dirname(__file__), "windows"),
29+
"ComInterface.py",
2830
)
2931
except ImportError as e:
3032
raise LoadDebuggerException(e, sys.exc_info())

‎cross-project-tests/debuginfo-tests/dexter/dex/utils/Imports.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import importlib
1+
import importlib.util
22
import os
33
import sys
44

55

6-
def load_module(name, path):
7-
spec = importlib.util.spec_from_file_location(
8-
name, os.path.join(path, name, "__init__.py")
6+
def load_module(name, path, mod_file="__init__.py"):
7+
# The module is either defined by a directory, in which case we search for
8+
# `path/name/__init__.py`, or it is a single file at `path/mod_file`.
9+
mod_path = (
10+
os.path.join(path, name, mod_file)
11+
if mod_file == "__init__.py"
12+
else os.path.join(path, mod_file)
913
)
14+
spec = importlib.util.spec_from_file_location(name, mod_path)
1015
module = importlib.util.module_from_spec(spec)
1116
sys.modules[name] = module
1217
spec.loader.exec_module(module)

0 commit comments

Comments
 (0)
Please sign in to comment.