Skip to content

Commit 9431731

Browse files
committed
Add feature resolve=True
1 parent b5be7e5 commit 9431731

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

examples/configs/default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ b:
44
b1: 1
55
b2: 2
66
b3: 3
7+
reference: ${a1}

examples/example.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,36 @@ class A:
2929
a4: int
3030
a5: int
3131
b: B
32+
reference: int
3233

3334

3435
@dataclass
3536
class C:
3637
c1: int
3738
c2: int
3839
c3: int
39-
c_complex: multiprocessing.SimpleQueue # We can have more than simple types in runtime classes
40+
c_complex: (
41+
multiprocessing.SimpleQueue
42+
) # We can have more than simple types in runtime classes
4043

4144

4245
# Look at the implementation of this function in argmument_parser.py for the exact details, and if you want to do argument parsing outside of the CLI
4346
data = parse_arguments_cli(A, C) # A are constants, C are runtime variables
4447

4548
assert (
4649
str(data)
47-
== "Component(conf={'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': '???', 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}}, runtime=C(c1=None, c2=None, c3=None, c_complex=None), sealed=False)"
48-
)
50+
== "Component(conf={'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': '???', 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}, 'reference': '${a1}'}, runtime=C(c1=None, c2=None, c3=None, c_complex=None), sealed=False)"
51+
), f"Actual: {str(data)}"
52+
53+
assert (
54+
str(data.get_conf())
55+
== "{'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': '???', 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}, 'reference': '${a1}'}"
56+
), f"Actual: {str(data.get_conf())}"
57+
58+
assert (
59+
str(data.get_conf(resolve=True))
60+
== "{'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': '???', 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}, 'reference': 1}"
61+
), f"Actual: {str(data.get_conf(resolve=True))}"
4962

5063
data.a5 = -500
5164

@@ -61,12 +74,15 @@ class C:
6174
def add(x: int, y: int):
6275
return x + y
6376

77+
6478
def store_a_into_c(a1: int, a2: int): # Use type hinting here
6579
return {"c1": a1, "c2": a2}
6680

81+
6782
def add_a2_and_c2_and_store_into_c2(c2: int, a2: int):
6883
return {"c2": add(c2, a2)}
6984

85+
7086
init_pipeline = Pipeline(
7187
component=data,
7288
systems=[store_a_into_c],
@@ -88,4 +104,7 @@ def add_a2_and_c2_and_store_into_c2(c2: int, a2: int):
88104
add_pipeline.execute() # We can run pipelines as many times as we want
89105
assert data.c1 == 3 and data.c2 == -6
90106

91-
assert str(data) == "Component(conf={'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': -500, 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}}, runtime=C(c1=3, c2=-6, c3=None, c_complex=None), sealed=True)"
107+
assert (
108+
str(data)
109+
== "Component(conf={'a1': 1, 'a2': -2, 'a3': -3, 'a4': 400, 'a5': -500, 'b': {'b1': 1, 'b2': 500, 'b3': -3, 'b4': -4, 'b5': '???', 'b6': '???'}, 'reference': '${a1}'}, runtime=C(c1=3, c2=-6, c3=None, c_complex=None), sealed=True)"
110+
)

pcs/component.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ def seal(self):
5656
def is_sealed(self):
5757
return self.sealed
5858

59-
def get_conf(self):
60-
return super().__getattribute__("conf")
59+
def get_conf(self, resolve=False):
60+
conf = super().__getattribute__("conf")
61+
if resolve:
62+
return OmegaConf.to_container(conf, resolve=True)
63+
return conf
6164

6265
def get_runtime(self):
6366
return super().__getattribute__("runtime")

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ classifiers = [
1616
"Intended Audience :: Developers"
1717
]
1818
dependencies = [
19-
"oyaml==1.0",
20-
"omegaconf==2.3.0",
19+
"oyaml>=1.0",
20+
"omegaconf>=2.3.0",
2121
]
2222

2323
[project.urls]

0 commit comments

Comments
 (0)