forked from PEtab-dev/libpetab-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
72 lines (63 loc) · 2.17 KB
/
__init__.py
File metadata and controls
72 lines (63 loc) · 2.17 KB
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
"""
PEtab global
============
Attributes:
ENV_NUM_THREADS:
Name of environment variable to set number of threads or processes
PEtab should use for operations that can be performed in parallel.
By default, all operations are performed sequentially.
"""
import importlib
import sys
from functools import partial
from pathlib import Path
from warnings import warn
ENV_NUM_THREADS = "PETAB_NUM_THREADS"
__all__ = ["ENV_NUM_THREADS"]
def __getattr__(name):
if attr := globals().get(name):
return attr
if name == "v1":
return importlib.import_module("petab.v1")
if name == "v2":
return importlib.import_module("petab.v2")
if name != "__path__":
warn(
f"Accessing `petab.{name}` is deprecated and will be removed in "
f"the next major release. Please use `petab.v1.{name}` instead.",
DeprecationWarning,
stacklevel=3,
)
return getattr(importlib.import_module("petab.v1"), name)
def v1getattr(name, module):
if name != "__path__":
warn(
f"Accessing `petab.{name}` is deprecated and will be removed in "
f"the next major release. Please use `petab.v1.{name}` instead.",
DeprecationWarning,
stacklevel=3,
)
try:
return module.__dict__[name]
except KeyError:
raise AttributeError(name) from None
# Create dummy modules for all old modules
v1_root = Path(__file__).resolve().parent / "v1"
v1_objects = [f.relative_to(v1_root) for f in v1_root.rglob("*")]
for v1_object in v1_objects:
if "__pycache__" in str(v1_object):
continue
if v1_object.suffix not in ["", ".py"]:
continue
if not (v1_root / v1_object).exists():
raise ValueError(v1_root / v1_object)
v1_object_parts = [*v1_object.parts[:-1], v1_object.stem]
module_name = ".".join(["petab", *v1_object_parts])
try:
real_module = importlib.import_module(
f"petab.v1.{'.'.join(v1_object_parts)}"
)
real_module.__getattr__ = partial(v1getattr, module=real_module)
sys.modules[module_name] = real_module
except ModuleNotFoundError:
pass