process-bigraph 0.0.49__tar.gz → 0.0.51__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {process_bigraph-0.0.49/process_bigraph.egg-info → process_bigraph-0.0.51}/PKG-INFO +1 -1
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/__init__.py +5 -0
- process_bigraph-0.0.51/process_bigraph/package/discover.py +103 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/process_types.py +0 -2
- process_bigraph-0.0.51/process_bigraph/run.py +29 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51/process_bigraph.egg-info}/PKG-INFO +1 -1
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph.egg-info/SOURCES.txt +1 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/pyproject.toml +1 -1
- process_bigraph-0.0.49/process_bigraph/package/discover.py +0 -99
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/AUTHORS.md +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/LICENSE +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/README.md +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/composite.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/emitter.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/experiments/__init__.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/experiments/minimal_gillespie.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/package/__init__.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/processes/__init__.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/processes/growth_division.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/processes/parameter_scan.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/__init__.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/docker.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/local.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/parallel.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/protocol.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/rest.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/protocols/socket.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/tests.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/units.py +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph.egg-info/dependency_links.txt +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph.egg-info/requires.txt +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph.egg-info/top_level.txt +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/setup.cfg +0 -0
- {process_bigraph-0.0.49 → process_bigraph-0.0.51}/setup.py +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
import pkgutil
|
|
3
|
+
import inspect
|
|
4
|
+
from pprint import pprint as pp
|
|
5
|
+
|
|
6
|
+
from process_bigraph import Process, Step, ProcessTypes
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def recursive_dynamic_import(core, package_name: str) -> list[tuple[str, Process | Step ]]:
|
|
10
|
+
classes_to_import = []
|
|
11
|
+
adjusted_package_name: str = package_name.replace("-", "_")
|
|
12
|
+
|
|
13
|
+
# TODO: fix module name discovery based on package name
|
|
14
|
+
if adjusted_package_name == "vivarium_interface":
|
|
15
|
+
adjusted_package_name = "vivarium"
|
|
16
|
+
if adjusted_package_name == "sed2_demo":
|
|
17
|
+
adjusted_package_name = "sed2"
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
module = importlib.import_module(adjusted_package_name)
|
|
21
|
+
except ModuleNotFoundError:
|
|
22
|
+
# TODO: Add code to try and find correct module name via accessing `top_level.txt`,
|
|
23
|
+
# and getting the correct module name
|
|
24
|
+
# find top-level.txt
|
|
25
|
+
# find correct module name
|
|
26
|
+
# return recursive_dynamic_import(correct_module_name)
|
|
27
|
+
raise ModuleNotFoundError(f"Error: module `{adjusted_package_name}` not found when trying to dynamically import!")
|
|
28
|
+
|
|
29
|
+
if hasattr(module, 'register_types'):
|
|
30
|
+
core = module.register_types(core)
|
|
31
|
+
|
|
32
|
+
class_members = inspect.getmembers(module, inspect.isclass)
|
|
33
|
+
for class_name, cls in class_members:
|
|
34
|
+
if cls == Process:
|
|
35
|
+
continue
|
|
36
|
+
if cls == Step:
|
|
37
|
+
continue
|
|
38
|
+
if issubclass(cls, Process):
|
|
39
|
+
classes_to_import.append((f"{package_name}.{class_name}", cls))
|
|
40
|
+
if issubclass(cls, Step):
|
|
41
|
+
classes_to_import.append((f"{package_name}.{class_name}", cls))
|
|
42
|
+
|
|
43
|
+
modules_to_check = pkgutil.iter_modules(module.__path__) if hasattr(module, '__path__') else []
|
|
44
|
+
|
|
45
|
+
for _module_loader, subname, isPkg in modules_to_check:
|
|
46
|
+
classes_to_import += recursive_dynamic_import(core, f"{adjusted_package_name}.{subname}")
|
|
47
|
+
|
|
48
|
+
return classes_to_import
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def import_package_modules(core, name, package):
|
|
52
|
+
import ipdb; ipdb.set_trace()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def is_process_library(package: importlib.metadata.Distribution) -> bool:
|
|
56
|
+
for entry in ([] if package.requires is None else package.requires):
|
|
57
|
+
if "process-bigraph" in entry:
|
|
58
|
+
return True
|
|
59
|
+
|
|
60
|
+
return False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def load_local_modules(core) -> list[tuple[str, Process | Step ]]:
|
|
64
|
+
packages = importlib.metadata.distributions()
|
|
65
|
+
processes = []
|
|
66
|
+
for package in packages:
|
|
67
|
+
if not is_process_library(package):
|
|
68
|
+
continue
|
|
69
|
+
processes += recursive_dynamic_import(core, package.name)
|
|
70
|
+
|
|
71
|
+
return processes
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def import_processes(core, name):
|
|
75
|
+
processes = {}
|
|
76
|
+
module = importlib.import_module(name)
|
|
77
|
+
for attr in dir(module):
|
|
78
|
+
entry = getattr(module, attr)
|
|
79
|
+
if inspect.isclass(entry) and issubclass(entry, (Process, Step)):
|
|
80
|
+
processes[attr] = entry
|
|
81
|
+
return processes
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def traverse_modules(core) -> list[tuple[str, Process | Step ]]:
|
|
85
|
+
processes = {}
|
|
86
|
+
package_modules = pkgutil.walk_packages(['.'])
|
|
87
|
+
|
|
88
|
+
for _, module_name, is_package in package_modules:
|
|
89
|
+
processes.update(import_processes(core, module_name))
|
|
90
|
+
|
|
91
|
+
return processes
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def discover_packages(core) -> ProcessTypes:
|
|
95
|
+
for name, process in load_local_modules(core):
|
|
96
|
+
if name not in core.process_registry.registry:
|
|
97
|
+
core.register_process(name, process)
|
|
98
|
+
|
|
99
|
+
processes = traverse_modules(core)
|
|
100
|
+
core.register_processes(processes)
|
|
101
|
+
|
|
102
|
+
return core
|
|
103
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fire
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from process_bigraph import generate_core, Composite
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def run(document=None, time=None):
|
|
8
|
+
if not document:
|
|
9
|
+
return
|
|
10
|
+
|
|
11
|
+
if isinstance(document, str):
|
|
12
|
+
with open(document, 'r') as path:
|
|
13
|
+
document = json.load(path)
|
|
14
|
+
|
|
15
|
+
core = generate_core()
|
|
16
|
+
composite = Composite(
|
|
17
|
+
document,
|
|
18
|
+
core=core)
|
|
19
|
+
|
|
20
|
+
if not time:
|
|
21
|
+
composite.run(0.0)
|
|
22
|
+
else:
|
|
23
|
+
composite.run(time)
|
|
24
|
+
|
|
25
|
+
print(composite.read_bridge())
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == '__main__':
|
|
29
|
+
fire.Fire(run)
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import importlib.metadata
|
|
2
|
-
import pkgutil
|
|
3
|
-
import inspect
|
|
4
|
-
|
|
5
|
-
from process_bigraph import Process, Step, ProcessTypes
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def recursive_dynamic_import(core, package_name: str, verbose: bool = False) -> list[tuple[str, Process | Step ]]:
|
|
9
|
-
classes_to_import = []
|
|
10
|
-
adjusted_package_name: str = package_name.replace("-", "_")
|
|
11
|
-
# TODO: fix module name discovery based on package name
|
|
12
|
-
if adjusted_package_name == "vivarium_interface":
|
|
13
|
-
adjusted_package_name = "vivarium"
|
|
14
|
-
try:
|
|
15
|
-
module = importlib.import_module(adjusted_package_name)
|
|
16
|
-
except ModuleNotFoundError:
|
|
17
|
-
# TODO: Add code to try and find correct module name via accessing `top_level.txt`,
|
|
18
|
-
# and getting the correct module name
|
|
19
|
-
# find top-level.txt
|
|
20
|
-
# find correct module name
|
|
21
|
-
# return recursive_dynamic_import(correct_module_name)
|
|
22
|
-
raise ModuleNotFoundError(f"Error: module `{adjusted_package_name}` not found when trying to dynamically import!")
|
|
23
|
-
|
|
24
|
-
if hasattr(module, 'register_types'):
|
|
25
|
-
core = module.register_types(core)
|
|
26
|
-
|
|
27
|
-
class_members = inspect.getmembers(module, inspect.isclass)
|
|
28
|
-
if verbose:
|
|
29
|
-
print(f"Processing {len(class_members)} members...")
|
|
30
|
-
for class_name, clazz in class_members:
|
|
31
|
-
if clazz == Process:
|
|
32
|
-
if verbose:
|
|
33
|
-
print(f'Process `{class_name}` skipped, because it is `Process` itself.')
|
|
34
|
-
continue
|
|
35
|
-
if clazz == Step:
|
|
36
|
-
if verbose:
|
|
37
|
-
print(f'Process `{class_name}` skipped, because it is `Step` itself.')
|
|
38
|
-
continue
|
|
39
|
-
if issubclass(clazz, Process):
|
|
40
|
-
if verbose:
|
|
41
|
-
print(f'Process `{class_name}` added to queue!')
|
|
42
|
-
classes_to_import.append((f"{package_name}.{class_name}", clazz))
|
|
43
|
-
if issubclass(clazz, Step):
|
|
44
|
-
if verbose:
|
|
45
|
-
print(f'Step `{class_name}` added to queue!')
|
|
46
|
-
classes_to_import.append((f"{package_name}.{class_name}", clazz))
|
|
47
|
-
if verbose:
|
|
48
|
-
print(f'Invalid `{class_name}` skipped; not a Process nor Step!')
|
|
49
|
-
|
|
50
|
-
path = module.__path__ if hasattr(module, '__path__') else "<No `__path__` attr>"
|
|
51
|
-
modules_to_check = pkgutil.iter_modules(module.__path__) if hasattr(module, '__path__') else []
|
|
52
|
-
if verbose:
|
|
53
|
-
print(f"Checking for modules in `{module.__name__}` [path: {path}]...")
|
|
54
|
-
for _module_loader, subname, isPkg in modules_to_check:
|
|
55
|
-
# if not isPkg: continue
|
|
56
|
-
if verbose:
|
|
57
|
-
print(f"Found: {adjusted_package_name}.{subname}")
|
|
58
|
-
classes_to_import += recursive_dynamic_import(core, f"{adjusted_package_name}.{subname}", verbose)
|
|
59
|
-
if verbose:
|
|
60
|
-
print(f'Found {len(classes_to_import)} classes in `{package_name}` to import'"")
|
|
61
|
-
return classes_to_import
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def load_local_modules(core, verbose: bool = False) -> list[tuple[str, Process | Step ]]:
|
|
65
|
-
if verbose:
|
|
66
|
-
print("Loading local registry...")
|
|
67
|
-
packages = importlib.metadata.distributions()
|
|
68
|
-
classes_to_load = []
|
|
69
|
-
for package in packages:
|
|
70
|
-
if not does_package_require_process_bigraph(package):
|
|
71
|
-
continue
|
|
72
|
-
# If a package requires BSail, it probably has abstractions for us; worth importing.
|
|
73
|
-
if verbose:
|
|
74
|
-
print(f'Relevant Processes found in `{package.name}`...')
|
|
75
|
-
classes_to_load += recursive_dynamic_import(core, package.name, verbose)
|
|
76
|
-
|
|
77
|
-
return classes_to_load
|
|
78
|
-
|
|
79
|
-
def does_package_require_process_bigraph(package: importlib.metadata.Distribution) -> bool:
|
|
80
|
-
for entry in ([] if package.requires is None else package.requires):
|
|
81
|
-
if "process-bigraph" in entry:
|
|
82
|
-
return True
|
|
83
|
-
return False
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def discover_packages(core, verbose: bool) -> ProcessTypes:
|
|
87
|
-
# core = ProcessTypes()
|
|
88
|
-
counter = 0
|
|
89
|
-
for name, clazz in load_local_modules(core, verbose):
|
|
90
|
-
if name not in core.process_registry.registry:
|
|
91
|
-
core.register_process(name, clazz)
|
|
92
|
-
if verbose:
|
|
93
|
-
counter += 1
|
|
94
|
-
print(f'Registered `{name}` to `{clazz.__name__}`')
|
|
95
|
-
if verbose:
|
|
96
|
-
print(f"Registered {counter} processes...")
|
|
97
|
-
|
|
98
|
-
return core
|
|
99
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/experiments/minimal_gillespie.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/processes/growth_division.py
RENAMED
|
File without changes
|
{process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph/processes/parameter_scan.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{process_bigraph-0.0.49 → process_bigraph-0.0.51}/process_bigraph.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|