File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,10 @@ def get_hooks(self) -> Iterable[BuildHookInterface]:
134
134
local_hook = self .config .build_config .custom_hook
135
135
if local_hook is not None :
136
136
yield cast (
137
- BuildHookInterface , import_module_at_path (self .location / local_hook )
137
+ BuildHookInterface ,
138
+ import_module_at_path (
139
+ self .location / local_hook , context = self .location
140
+ ),
138
141
)
139
142
140
143
def call_hook (
Original file line number Diff line number Diff line change @@ -152,14 +152,18 @@ def replace_func(match: Match[str]) -> str:
152
152
153
153
154
154
def import_module_at_path (
155
- src_path : str | Path , module_name : str = "_local"
155
+ src_path : str | Path , module_name : str = "_local" , context : Path | None = None
156
156
) -> types .ModuleType :
157
157
"""Import a module from a given path."""
158
158
spec = importlib .util .spec_from_file_location (module_name , src_path )
159
159
if spec is None :
160
160
raise ValueError (f"Could not import module { module_name } from { src_path } " )
161
+ if context is not None :
162
+ sys .path .insert (0 , str (context .absolute ()))
161
163
module = importlib .util .module_from_spec (spec )
162
164
spec .loader .exec_module (module ) # type: ignore
165
+ if context is not None :
166
+ sys .path .pop (0 )
163
167
return module
164
168
165
169
You can’t perform that action at this time.
0 commit comments