-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompiler.py
More file actions
163 lines (146 loc) · 5.37 KB
/
Copy pathcompiler.py
File metadata and controls
163 lines (146 loc) · 5.37 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""Public BuildCompiler API skeleton."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
from buildcompiler.planning import FullBuildPlanner
from buildcompiler.sbol import PartShopRepositoryClient
from .options import BuildOptions
@dataclass
class BuildCompiler:
inventory: Any = None
sbol_document: Any = None
planner: Any = None
executor: Any = None
adapters: Any = None
repository_client: PartShopRepositoryClient | None = None
options: BuildOptions = field(default_factory=BuildOptions)
@classmethod
def from_synbiohub(
cls,
*,
collections: list[str] | None = None,
repository_url: str | None = None,
sbh_registry: str | None = None,
auth_token: str | None = None,
email: str | None = None,
password: str | None = None,
sbol_doc: Any = None,
options: BuildOptions | None = None,
**kwargs: Any,
) -> "BuildCompiler":
resolved_repository_url = repository_url or sbh_registry
if auth_token and password:
raise ValueError("auth_token cannot be combined with password")
requires_repository = bool(
collections or resolved_repository_url or auth_token or email or password
)
if requires_repository and not resolved_repository_url:
raise ValueError("repository_url (or sbh_registry) is required")
document = sbol_doc
repository_client = None
if resolved_repository_url:
import sbol2
document = document or sbol2.Document()
repository_client = PartShopRepositoryClient(
repository_url=resolved_repository_url,
document=document,
auth_token=auth_token,
email=email,
password=password,
)
for collection_uri in collections or []:
repository_client.pull_collection(collection_uri)
return cls(
sbol_document=document,
repository_client=repository_client,
options=options or BuildOptions(),
**kwargs,
)
def plan(self, abstract_designs: Any, options: BuildOptions | None = None) -> Any:
effective_options = options or self.options
planner = self.planner or FullBuildPlanner(options=effective_options)
return planner.plan(abstract_designs, options=effective_options)
def execute(self, plan: Any, options: BuildOptions | None = None) -> Any:
effective_options = options or self.options
executor = self.executor
if executor is None:
if self.inventory is None:
raise ValueError(
"BuildCompiler.execute requires an inventory when no executor is injected."
)
if self.sbol_document is None:
raise ValueError(
"BuildCompiler.execute requires an sbol_document when no executor is injected."
)
from buildcompiler.execution import FullBuildExecutor
executor = FullBuildExecutor.from_dependencies(
inventory=self.inventory,
sbol_document=self.sbol_document,
options=effective_options,
adapters=self.adapters,
pull_client=(
self.repository_client.pull_identity
if self.repository_client is not None
else None
),
)
return executor.execute(plan, options=effective_options)
def full_build(
self, abstract_designs: Any, options: BuildOptions | None = None
) -> Any:
plan = self.plan(abstract_designs, options=options)
return self.execute(plan, options=options)
def full_build(
abstract_designs: Any,
*,
inventory: Any = None,
sbol_document: Any = None,
planner: Any = None,
executor: Any = None,
adapters: Any = None,
options: BuildOptions | None = None,
collections: list[str] | None = None,
repository_url: str | None = None,
sbh_registry: str | None = None,
auth_token: str | None = None,
email: str | None = None,
password: str | None = None,
sbol_doc: Any = None,
**kwargs: Any,
) -> Any:
compiler_options = options or BuildOptions()
if (
collections is not None
or sbh_registry is not None
or repository_url is not None
or auth_token is not None
or email is not None
or password is not None
or sbol_doc is not None
):
compiler = BuildCompiler.from_synbiohub(
collections=collections,
repository_url=repository_url,
sbh_registry=sbh_registry,
auth_token=auth_token,
email=email,
password=password,
sbol_doc=sbol_doc,
options=compiler_options,
inventory=inventory,
planner=planner,
executor=executor,
adapters=adapters,
**kwargs,
)
else:
compiler = BuildCompiler(
inventory=inventory,
sbol_document=sbol_document,
planner=planner,
executor=executor,
adapters=adapters,
options=compiler_options,
**kwargs,
)
return compiler.full_build(abstract_designs, options=compiler_options)