-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
30 lines (24 loc) · 835 Bytes
/
conftest.py
File metadata and controls
30 lines (24 loc) · 835 Bytes
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
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
def _force_local_scripts_package() -> None:
root = Path(__file__).parent
pkg_dir = root / "scripts"
init_py = pkg_dir / "__init__.py"
if not init_py.is_file():
return
# If already bound to our package file, nothing to do.
existing = sys.modules.get("scripts")
if existing is not None and getattr(existing, "__file__", None) == str(init_py):
return
spec = importlib.util.spec_from_file_location(
"scripts",
str(init_py),
submodule_search_locations=[str(pkg_dir)],
)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules["scripts"] = module
spec.loader.exec_module(module)
_force_local_scripts_package()