fiab-plugin-test 0.0.7__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.
- fiab_plugin_test-0.0.7/.python-version +1 -0
- fiab_plugin_test-0.0.7/LICENSE +201 -0
- fiab_plugin_test-0.0.7/PKG-INFO +13 -0
- fiab_plugin_test-0.0.7/README.md +1 -0
- fiab_plugin_test-0.0.7/justfile +6 -0
- fiab_plugin_test-0.0.7/pyproject.toml +42 -0
- fiab_plugin_test-0.0.7/setup.cfg +4 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test/__init__.py +189 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test/_version.py +24 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test/py.typed +0 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test/runtime.py +60 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test.egg-info/PKG-INFO +13 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test.egg-info/SOURCES.txt +16 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test.egg-info/dependency_links.txt +1 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test.egg-info/requires.txt +1 -0
- fiab_plugin_test-0.0.7/src/fiab_plugin_test.egg-info/top_level.txt +1 -0
- fiab_plugin_test-0.0.7/tests/conftest.py +30 -0
- fiab_plugin_test-0.0.7/tests/test_base.py +174 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 European Centre for Medium-Range Weather Forecasts
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fiab-plugin-test
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: Weather Forecast in a Box, test plugin
|
|
5
|
+
Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: fiab-core<1.0.0,>=0.0.1
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
Used only for tests. Not expected to be published or installed.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Used only for tests. Not expected to be published or installed.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
|
|
4
|
+
requires = [ "setuptools>=80", "setuptools-scm[toml]>=6.2" ]
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "fiab-plugin-test"
|
|
8
|
+
description = "Weather Forecast in a Box, test plugin"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = [ "LICENSE" ]
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "software.support@ecmwf.int" },
|
|
14
|
+
]
|
|
15
|
+
requires-python = ">=3.11"
|
|
16
|
+
|
|
17
|
+
dynamic = [ "version" ]
|
|
18
|
+
|
|
19
|
+
dependencies = [
|
|
20
|
+
"fiab-core>=0.0.1,<1.0.0", # ~=0.0
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
dev = [
|
|
25
|
+
"ty==0.0.2",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools_scm]
|
|
29
|
+
version_file = "src/fiab_plugin_test/_version.py"
|
|
30
|
+
write_to_template = '''# Do not change! Do not track in version control!
|
|
31
|
+
__version__ = "{version}"
|
|
32
|
+
'''
|
|
33
|
+
local_scheme = "no-local-version"
|
|
34
|
+
root = ".."
|
|
35
|
+
fallback_version = "0.0.0"
|
|
36
|
+
tag_regex = '^[vd](?P<version>\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$'
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 140
|
|
40
|
+
|
|
41
|
+
lint.ignore = [ "E731", "ANN401" ]
|
|
42
|
+
lint.select = ["I", "ANN"]
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
|
|
3
|
+
from cascade.low.func import Either
|
|
4
|
+
from earthkit.workflows.fluent import Action, Payload, PayloadBuildingContext, from_source
|
|
5
|
+
from fiab_core.artifacts import ArtifactsProvider, CompositeArtifactId
|
|
6
|
+
from fiab_core.fable import (
|
|
7
|
+
ActionLookup,
|
|
8
|
+
BlockConfigurationOption,
|
|
9
|
+
BlockExpansion,
|
|
10
|
+
BlockFactory,
|
|
11
|
+
BlockFactoryCatalogue,
|
|
12
|
+
BlockFactoryId,
|
|
13
|
+
BlockInstance,
|
|
14
|
+
BlockInstanceId,
|
|
15
|
+
BlockInstanceOutput,
|
|
16
|
+
ConfigurationOptionId,
|
|
17
|
+
NoOutput,
|
|
18
|
+
RawOutput,
|
|
19
|
+
)
|
|
20
|
+
from fiab_core.plugin import Error, Plugin
|
|
21
|
+
from fiab_core.types import FableType
|
|
22
|
+
|
|
23
|
+
TEXT = ConfigurationOptionId("text")
|
|
24
|
+
DURATION = ConfigurationOptionId("duration")
|
|
25
|
+
CHECKPOINT = ConfigurationOptionId("checkpoint")
|
|
26
|
+
AMOUNT = ConfigurationOptionId("amount")
|
|
27
|
+
FNAME = ConfigurationOptionId("fname")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _get_checkpoint_enum_type() -> str:
|
|
31
|
+
available = ArtifactsProvider.get_artifacts_lookup()
|
|
32
|
+
values = ", ".join(f"'{CompositeArtifactId.to_str(k)}'" for k in available.keys())
|
|
33
|
+
return f"enumClosed[{values}]"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
catalogue = lambda: BlockFactoryCatalogue(
|
|
37
|
+
factories={
|
|
38
|
+
BlockFactoryId("source_42"): BlockFactory(
|
|
39
|
+
kind="source",
|
|
40
|
+
title="Source 42",
|
|
41
|
+
description="Returns 42",
|
|
42
|
+
configuration_options={},
|
|
43
|
+
inputs=[],
|
|
44
|
+
),
|
|
45
|
+
BlockFactoryId("source_text"): BlockFactory(
|
|
46
|
+
kind="source",
|
|
47
|
+
title="Source Text",
|
|
48
|
+
description="Returns the input text",
|
|
49
|
+
configuration_options={TEXT: BlockConfigurationOption(title="", description="", value_type="str")},
|
|
50
|
+
inputs=[],
|
|
51
|
+
),
|
|
52
|
+
BlockFactoryId("source_sleep"): BlockFactory(
|
|
53
|
+
kind="source",
|
|
54
|
+
title="Source Sleep",
|
|
55
|
+
description="Sleeps for a duration, then retuns the input text",
|
|
56
|
+
configuration_options={
|
|
57
|
+
TEXT: BlockConfigurationOption(title="", description="", value_type="str"),
|
|
58
|
+
DURATION: BlockConfigurationOption(title="", description="", value_type="float"),
|
|
59
|
+
},
|
|
60
|
+
inputs=[],
|
|
61
|
+
),
|
|
62
|
+
BlockFactoryId("source_filesize"): BlockFactory(
|
|
63
|
+
kind="source",
|
|
64
|
+
title="File Size Source",
|
|
65
|
+
description="Returns the size of the given checkpoint file as a string",
|
|
66
|
+
configuration_options={
|
|
67
|
+
CHECKPOINT: BlockConfigurationOption(
|
|
68
|
+
title="Checkpoint",
|
|
69
|
+
description="The checkpoint whose downloaded file size to report",
|
|
70
|
+
value_type=_get_checkpoint_enum_type(),
|
|
71
|
+
),
|
|
72
|
+
},
|
|
73
|
+
inputs=[],
|
|
74
|
+
),
|
|
75
|
+
BlockFactoryId("transform_increment"): BlockFactory(
|
|
76
|
+
kind="transform",
|
|
77
|
+
title="Increment",
|
|
78
|
+
description="Adds the amount to the input",
|
|
79
|
+
configuration_options={AMOUNT: BlockConfigurationOption(title="", description="", value_type="int")},
|
|
80
|
+
inputs=["a"],
|
|
81
|
+
),
|
|
82
|
+
BlockFactoryId("product_join"): BlockFactory(
|
|
83
|
+
kind="product",
|
|
84
|
+
title="Join",
|
|
85
|
+
description="Adds the two inputs together",
|
|
86
|
+
configuration_options={},
|
|
87
|
+
inputs=["a", "b"],
|
|
88
|
+
),
|
|
89
|
+
BlockFactoryId("sink_file"): BlockFactory(
|
|
90
|
+
kind="sink",
|
|
91
|
+
title="File",
|
|
92
|
+
description="Saves the input to a file",
|
|
93
|
+
configuration_options={FNAME: BlockConfigurationOption(title="", description="", value_type="str")},
|
|
94
|
+
inputs=["data"],
|
|
95
|
+
),
|
|
96
|
+
BlockFactoryId("sink_image"): BlockFactory(
|
|
97
|
+
kind="sink",
|
|
98
|
+
title="Image",
|
|
99
|
+
description="Generates a png image, using the input number as the grayscale",
|
|
100
|
+
configuration_options={},
|
|
101
|
+
inputs=["data"],
|
|
102
|
+
),
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def validator(instance: BlockInstance, inputs: dict[str, BlockInstanceOutput]) -> Either[BlockInstanceOutput, Error]: # type:ignore[invalid-argument] # semigroup
|
|
108
|
+
if instance.factory_id.factory in ("sink_file",):
|
|
109
|
+
return Either.ok(RawOutput(type_fqn="bytes", mime_type="text/plain"))
|
|
110
|
+
elif instance.factory_id.factory in ("sink_image",):
|
|
111
|
+
return Either.ok(RawOutput(type_fqn="bytes", mime_type="image/png"))
|
|
112
|
+
elif instance.factory_id.factory in ("source_sleep", "source_text", "source_filesize"):
|
|
113
|
+
return Either.ok(RawOutput(type_fqn="str", mime_type="text/plain"))
|
|
114
|
+
elif instance.factory_id.factory in ("source_42", "transform_increment", "product_join"):
|
|
115
|
+
return Either.ok(RawOutput(type_fqn="int"))
|
|
116
|
+
else:
|
|
117
|
+
raise TypeError(f"unexpected factory {instance.factory_id.factory}")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def expander(output: BlockInstanceOutput) -> list[BlockExpansion]:
|
|
121
|
+
if isinstance(output, RawOutput):
|
|
122
|
+
if output.type_fqn == "int":
|
|
123
|
+
return [
|
|
124
|
+
BlockExpansion(
|
|
125
|
+
factory=BlockFactoryId("transform_increment"),
|
|
126
|
+
restrictions={AMOUNT: FableType.parse("enumClosed[1,2,3]")},
|
|
127
|
+
),
|
|
128
|
+
BlockExpansion(factory=BlockFactoryId("product_join")),
|
|
129
|
+
BlockExpansion(factory=BlockFactoryId("sink_file")),
|
|
130
|
+
BlockExpansion(factory=BlockFactoryId("sink_image")),
|
|
131
|
+
]
|
|
132
|
+
if output.type_fqn in ("str", "bytes"):
|
|
133
|
+
return [BlockExpansion(factory=BlockFactoryId("sink_file"))]
|
|
134
|
+
return []
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def compiler(lookup: ActionLookup, bid: BlockInstanceId, instance: BlockInstance) -> Either[Action, Error]: # type:ignore[invalid-argument] # semigroup
|
|
138
|
+
with PayloadBuildingContext(environment=[f"-e {pathlib.Path(__file__).parent.parent.parent}"]):
|
|
139
|
+
# with PayloadBuildingContext(environment=["-e /home/dev/src/fiab-plugin-test"]): # TODO handle the ssh:// scenario intelligently
|
|
140
|
+
if instance.factory_id.factory == "source_42":
|
|
141
|
+
action = from_source(Payload("fiab_plugin_test.runtime.source_42")) # type: ignore
|
|
142
|
+
elif instance.factory_id.factory == "source_text":
|
|
143
|
+
text = instance.configuration_values[TEXT]
|
|
144
|
+
if not isinstance(text, str):
|
|
145
|
+
return Either.error(f"Invalid type for {TEXT!r}: expected str, got {type(text).__name__}")
|
|
146
|
+
action = from_source(Payload("fiab_plugin_test.runtime.source_text", kwargs={"text": text})) # type: ignore
|
|
147
|
+
elif instance.factory_id.factory == "source_sleep":
|
|
148
|
+
text = instance.configuration_values[TEXT]
|
|
149
|
+
duration = instance.configuration_values[DURATION]
|
|
150
|
+
if not isinstance(text, str):
|
|
151
|
+
return Either.error(f"Invalid type for {TEXT!r}: expected str, got {type(text).__name__}")
|
|
152
|
+
if not isinstance(duration, float):
|
|
153
|
+
return Either.error(f"Invalid type for {DURATION!r}: expected float, got {type(duration).__name__}")
|
|
154
|
+
action = from_source(Payload("fiab_plugin_test.runtime.source_sleep", kwargs={"text": text, "duration": duration})) # type: ignore
|
|
155
|
+
elif instance.factory_id.factory == "source_filesize":
|
|
156
|
+
checkpoint_str = instance.configuration_values[CHECKPOINT]
|
|
157
|
+
if not isinstance(checkpoint_str, str):
|
|
158
|
+
return Either.error(f"Invalid type for {CHECKPOINT!r}: expected str, got {type(checkpoint_str).__name__}")
|
|
159
|
+
artifact_id = CompositeArtifactId.from_str(checkpoint_str)
|
|
160
|
+
local_path = ArtifactsProvider.get_artifact_local_path(artifact_id)
|
|
161
|
+
payload = Payload(
|
|
162
|
+
"fiab_plugin_test.runtime.source_filesize", kwargs={"path": str(local_path)}, metadata={"artifacts": [artifact_id]}
|
|
163
|
+
)
|
|
164
|
+
action = from_source(payload) # type: ignore
|
|
165
|
+
elif instance.factory_id.factory == "transform_increment":
|
|
166
|
+
a = lookup[instance.input_ids["a"]]
|
|
167
|
+
amount = instance.configuration_values[AMOUNT]
|
|
168
|
+
if not isinstance(amount, int):
|
|
169
|
+
return Either.error(f"Invalid type for {AMOUNT!r}: expected int, got {type(amount).__name__}")
|
|
170
|
+
action = a.map(Payload("fiab_plugin_test.runtime.transform_increment", kwargs={"amount": amount})) # type: ignore
|
|
171
|
+
elif instance.factory_id.factory == "product_join":
|
|
172
|
+
a = lookup[instance.input_ids["a"]]
|
|
173
|
+
b = lookup[instance.input_ids["b"]]
|
|
174
|
+
action = a.join(b, dim="inputs").reduce(Payload("fiab_plugin_test.runtime.product_join")) # type: ignore
|
|
175
|
+
elif instance.factory_id.factory == "sink_file":
|
|
176
|
+
data = lookup[instance.input_ids["data"]]
|
|
177
|
+
fname = instance.configuration_values[FNAME]
|
|
178
|
+
if not isinstance(fname, str):
|
|
179
|
+
return Either.error(f"Invalid type for {FNAME!r}: expected str, got {type(fname).__name__}")
|
|
180
|
+
action = data.map(Payload("fiab_plugin_test.runtime.sink_file", kwargs={"fname": fname})) # type: ignore
|
|
181
|
+
elif instance.factory_id.factory == "sink_image":
|
|
182
|
+
data = lookup[instance.input_ids["data"]]
|
|
183
|
+
action = data.map(Payload("fiab_plugin_test.runtime.sink_image")) # type: ignore
|
|
184
|
+
else:
|
|
185
|
+
raise TypeError(instance.factory_id.factory)
|
|
186
|
+
return Either.ok(action)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
plugin = lambda: Plugin(catalogue=catalogue(), validator=validator, expander=expander, compiler=compiler)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.0.7'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 7)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# NOTE we install this runtime along with the main plugin because it has no external dependencies, and the whole testing is a single venv anyway
|
|
2
|
+
import pathlib
|
|
3
|
+
import struct
|
|
4
|
+
import time
|
|
5
|
+
import zlib
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def source_42() -> int:
|
|
9
|
+
return 42
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def source_sleep(text: str, duration: float) -> str:
|
|
13
|
+
time.sleep(duration)
|
|
14
|
+
return text
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def source_text(text: str) -> str:
|
|
18
|
+
return text
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def transform_increment(a: int, amount: int) -> int:
|
|
22
|
+
return a + amount
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def product_join(a: int, b: int) -> int:
|
|
26
|
+
return a + b
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def source_filesize(path: str) -> str:
|
|
30
|
+
return str(pathlib.Path(path).stat().st_size)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def sink_file(data: object, fname: str) -> bytes:
|
|
34
|
+
p = pathlib.Path(fname)
|
|
35
|
+
p.write_text(str(data))
|
|
36
|
+
return f"file://{p.absolute()}".encode("ascii")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _png_chunk(chunk_type: bytes, data: bytes) -> bytes:
|
|
40
|
+
payload = chunk_type + data
|
|
41
|
+
return struct.pack(">I", len(data)) + payload + struct.pack(">I", zlib.crc32(payload) & 0xFFFFFFFF)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def sink_image(data: int) -> bytes:
|
|
45
|
+
"""Generate a 64x64 grayscale PNG image filled with the given value (mod 256)."""
|
|
46
|
+
pixel = data % 256
|
|
47
|
+
width = height = 64
|
|
48
|
+
|
|
49
|
+
signature = b"\x89PNG\r\n\x1a\n"
|
|
50
|
+
|
|
51
|
+
ihdr_data = struct.pack(">II", width, height) + bytes([8, 0, 0, 0, 0])
|
|
52
|
+
ihdr = _png_chunk(b"IHDR", ihdr_data)
|
|
53
|
+
|
|
54
|
+
row = bytes([0]) + bytes([pixel] * width) # filter byte 0 + pixels
|
|
55
|
+
raw_scanlines = row * height
|
|
56
|
+
idat = _png_chunk(b"IDAT", zlib.compress(raw_scanlines))
|
|
57
|
+
|
|
58
|
+
iend = _png_chunk(b"IEND", b"")
|
|
59
|
+
|
|
60
|
+
return signature + ihdr + idat + iend
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fiab-plugin-test
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: Weather Forecast in a Box, test plugin
|
|
5
|
+
Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: fiab-core<1.0.0,>=0.0.1
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
Used only for tests. Not expected to be published or installed.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.python-version
|
|
2
|
+
LICENSE
|
|
3
|
+
README.md
|
|
4
|
+
justfile
|
|
5
|
+
pyproject.toml
|
|
6
|
+
src/fiab_plugin_test/__init__.py
|
|
7
|
+
src/fiab_plugin_test/_version.py
|
|
8
|
+
src/fiab_plugin_test/py.typed
|
|
9
|
+
src/fiab_plugin_test/runtime.py
|
|
10
|
+
src/fiab_plugin_test.egg-info/PKG-INFO
|
|
11
|
+
src/fiab_plugin_test.egg-info/SOURCES.txt
|
|
12
|
+
src/fiab_plugin_test.egg-info/dependency_links.txt
|
|
13
|
+
src/fiab_plugin_test.egg-info/requires.txt
|
|
14
|
+
src/fiab_plugin_test.egg-info/top_level.txt
|
|
15
|
+
tests/conftest.py
|
|
16
|
+
tests/test_base.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fiab-core<1.0.0,>=0.0.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fiab_plugin_test
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from fiab_core.artifacts import AnemoiCheckpoint, ArtifactResolved, ArtifactsProvider, CompositeArtifactId
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@pytest.fixture(scope="session", autouse=True)
|
|
6
|
+
def register_artifacts_provider() -> None:
|
|
7
|
+
fake_id = CompositeArtifactId.from_str("mystore:mycheckpoint")
|
|
8
|
+
ArtifactsProvider.register_get_artifacts_lookup(
|
|
9
|
+
lambda: {
|
|
10
|
+
fake_id: ArtifactResolved(
|
|
11
|
+
artifact_type="AnemoiCheckpoint",
|
|
12
|
+
store_info=AnemoiCheckpoint(
|
|
13
|
+
url="http://example.com/fake_checkpoint",
|
|
14
|
+
display_name="Fake Checkpoint",
|
|
15
|
+
display_author="Test Author",
|
|
16
|
+
display_description="A fake checkpoint for testing",
|
|
17
|
+
disk_size_bytes=0,
|
|
18
|
+
pip_package_constraints=[],
|
|
19
|
+
supported_platforms=[],
|
|
20
|
+
input_characteristics=[],
|
|
21
|
+
input_qube={},
|
|
22
|
+
output_qube={},
|
|
23
|
+
timestep="1h",
|
|
24
|
+
comment="",
|
|
25
|
+
),
|
|
26
|
+
is_locally_compatible=True,
|
|
27
|
+
local_compatibility_detail=None,
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# (C) Copyright 2026- ECMWF.
|
|
2
|
+
#
|
|
3
|
+
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
4
|
+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
5
|
+
#
|
|
6
|
+
# In applying this licence, ECMWF does not waive the privileges and immunities
|
|
7
|
+
# granted to it by virtue of its status as an intergovernmental organisation
|
|
8
|
+
# nor does it submit to any jurisdiction.
|
|
9
|
+
|
|
10
|
+
import pathlib
|
|
11
|
+
import struct
|
|
12
|
+
from unittest.mock import MagicMock, patch
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
from fiab_core.artifacts import ArtifactsProvider, CompositeArtifactId
|
|
16
|
+
from fiab_core.fable import (
|
|
17
|
+
BlockFactoryId,
|
|
18
|
+
BlockInstance,
|
|
19
|
+
BlockInstanceId,
|
|
20
|
+
ConfigurationOptionId,
|
|
21
|
+
PluginBlockFactoryId,
|
|
22
|
+
PluginCompositeId,
|
|
23
|
+
PluginId,
|
|
24
|
+
PluginStoreId,
|
|
25
|
+
RawOutput,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
from fiab_plugin_test import _get_checkpoint_enum_type, catalogue, compiler, validator
|
|
29
|
+
from fiab_plugin_test.runtime import sink_file, sink_image, source_filesize
|
|
30
|
+
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
# runtime.source_filesize
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_source_filesize_returns_correct_size(tmp_path: pathlib.Path) -> None:
|
|
37
|
+
f = tmp_path / "artifact.bin"
|
|
38
|
+
f.write_bytes(b"x" * 64)
|
|
39
|
+
assert source_filesize(str(f)) == "64"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_source_filesize_returns_string_type(tmp_path: pathlib.Path) -> None:
|
|
43
|
+
f = tmp_path / "artifact.bin"
|
|
44
|
+
f.write_bytes(b"hello")
|
|
45
|
+
result = source_filesize(str(f))
|
|
46
|
+
assert isinstance(result, str)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_source_filesize_empty_file(tmp_path: pathlib.Path) -> None:
|
|
50
|
+
f = tmp_path / "empty.bin"
|
|
51
|
+
f.write_bytes(b"")
|
|
52
|
+
assert source_filesize(str(f)) == "0"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_source_filesize_missing_file_raises(tmp_path: pathlib.Path) -> None:
|
|
56
|
+
with pytest.raises(FileNotFoundError):
|
|
57
|
+
source_filesize(str(tmp_path / "does_not_exist.bin"))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# ---------------------------------------------------------------------------
|
|
61
|
+
# catalogue
|
|
62
|
+
# ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_catalogue_contains_source_filesize() -> None:
|
|
66
|
+
assert BlockFactoryId("source_filesize") in catalogue().factories
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_source_filesize_factory_is_source_kind() -> None:
|
|
70
|
+
factory = catalogue().factories[BlockFactoryId("source_filesize")]
|
|
71
|
+
assert factory.kind == "source"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_source_filesize_factory_has_checkpoint_option() -> None:
|
|
75
|
+
factory = catalogue().factories[BlockFactoryId("source_filesize")]
|
|
76
|
+
assert ConfigurationOptionId("checkpoint") in factory.configuration_options
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_source_filesize_factory_uses_closed_enum_checkpoint_type() -> None:
|
|
80
|
+
factory = catalogue().factories[BlockFactoryId("source_filesize")]
|
|
81
|
+
assert factory.configuration_options[ConfigurationOptionId("checkpoint")].value_type == "enumClosed['mystore:mycheckpoint']"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# ---------------------------------------------------------------------------
|
|
85
|
+
# validator
|
|
86
|
+
# ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
_FAKE_PLUGIN_ID = PluginCompositeId(store=PluginStoreId("s"), local=PluginId("l"))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _make_instance(factory: str, config: dict) -> BlockInstance:
|
|
92
|
+
return BlockInstance(
|
|
93
|
+
factory_id=PluginBlockFactoryId(plugin=_FAKE_PLUGIN_ID, factory=BlockFactoryId(factory)),
|
|
94
|
+
configuration_values={ConfigurationOptionId(key): value for key, value in config.items()},
|
|
95
|
+
input_ids={},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_validator_source_filesize_returns_str_raw_output() -> None:
|
|
100
|
+
instance = _make_instance("source_filesize", {"checkpoint": "mystore:mycheckpoint"})
|
|
101
|
+
result = validator(instance, {})
|
|
102
|
+
assert result.t is not None
|
|
103
|
+
assert isinstance(result.t, RawOutput)
|
|
104
|
+
assert result.t.type_fqn == "str"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------------
|
|
108
|
+
# compiler
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_compiler_source_filesize_embeds_path_and_artifact_in_payload(tmp_path: pathlib.Path) -> None:
|
|
113
|
+
artifact_path = tmp_path / "checkpoint.bin"
|
|
114
|
+
fake_id = CompositeArtifactId.from_str("mystore:mycheckpoint")
|
|
115
|
+
|
|
116
|
+
with patch.object(ArtifactsProvider, "get_artifact_local_path", return_value=artifact_path):
|
|
117
|
+
instance = _make_instance("source_filesize", {"checkpoint": "mystore:mycheckpoint"})
|
|
118
|
+
result = compiler({}, BlockInstanceId("src"), instance)
|
|
119
|
+
|
|
120
|
+
assert result.t is not None, f"compiler returned error: {result.e}"
|
|
121
|
+
|
|
122
|
+
# Inspect the single source node in the returned action graph
|
|
123
|
+
nodes = list(result.t.graph().nodes())
|
|
124
|
+
assert len(nodes) == 1
|
|
125
|
+
payload = nodes[0].payload
|
|
126
|
+
assert payload.kwargs["path"] == str(artifact_path)
|
|
127
|
+
assert fake_id in payload.metadata["artifacts"]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# ---------------------------------------------------------------------------
|
|
131
|
+
# sink_image (pre-existing tests kept here for completeness)
|
|
132
|
+
# ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_ok() -> None:
|
|
136
|
+
"""Tests, as a minimum, that everything can be imported"""
|
|
137
|
+
assert True
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_sink_image_returns_valid_png() -> None:
|
|
141
|
+
result = sink_image(42)
|
|
142
|
+
|
|
143
|
+
assert isinstance(result, bytes)
|
|
144
|
+
assert len(result) > 0
|
|
145
|
+
assert result[:8] == b"\x89PNG\r\n\x1a\n", "Missing PNG signature"
|
|
146
|
+
|
|
147
|
+
# IHDR chunk starts at offset 8
|
|
148
|
+
# layout: 4B length | 4B type | 13B data | 4B CRC
|
|
149
|
+
assert result[8:12] == b"\x00\x00\x00\x0d", "IHDR length must be 13"
|
|
150
|
+
assert result[12:16] == b"IHDR"
|
|
151
|
+
width = struct.unpack(">I", result[16:20])[0]
|
|
152
|
+
height = struct.unpack(">I", result[20:24])[0]
|
|
153
|
+
bit_depth = result[24]
|
|
154
|
+
color_type = result[25]
|
|
155
|
+
|
|
156
|
+
assert width == 64
|
|
157
|
+
assert height == 64
|
|
158
|
+
assert bit_depth == 8
|
|
159
|
+
assert color_type == 0 # grayscale
|
|
160
|
+
|
|
161
|
+
assert b"IEND" in result, "PNG must contain IEND chunk"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_sink_image_modulo_256() -> None:
|
|
165
|
+
"""Values >= 256 are taken modulo 256."""
|
|
166
|
+
result_low = sink_image(42)
|
|
167
|
+
result_high = sink_image(42 + 256)
|
|
168
|
+
assert result_low == result_high
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test_sink_file_returns_bytes_locator(tmp_path: pathlib.Path) -> None:
|
|
172
|
+
locator = sink_file("hello", str(tmp_path / "out.txt"))
|
|
173
|
+
assert isinstance(locator, bytes)
|
|
174
|
+
assert locator.startswith(b"file://")
|