transpiler-mate-api 1.0.0__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.
Files changed (26) hide show
  1. transpiler_mate_api-1.0.0/.gitignore +9 -0
  2. transpiler_mate_api-1.0.0/LICENSE +201 -0
  3. transpiler_mate_api-1.0.0/PKG-INFO +23 -0
  4. transpiler_mate_api-1.0.0/README.md +5 -0
  5. transpiler_mate_api-1.0.0/docs/explanation/architecture.md +48 -0
  6. transpiler_mate_api-1.0.0/docs/explanation/failure-semantics.md +27 -0
  7. transpiler_mate_api-1.0.0/docs/how-to/define-options.md +49 -0
  8. transpiler_mate_api-1.0.0/docs/how-to/develop-a-plugin.md +121 -0
  9. transpiler_mate_api-1.0.0/docs/how-to/report-failures.md +64 -0
  10. transpiler_mate_api-1.0.0/docs/how-to/resolve-another-source.md +36 -0
  11. transpiler_mate_api-1.0.0/docs/how-to/test-a-plugin.md +82 -0
  12. transpiler_mate_api-1.0.0/docs/index.md +37 -0
  13. transpiler_mate_api-1.0.0/docs/reference/context-api.md +89 -0
  14. transpiler_mate_api-1.0.0/docs/reference/exceptions.md +73 -0
  15. transpiler_mate_api-1.0.0/docs/reference/plugin-api.md +56 -0
  16. transpiler_mate_api-1.0.0/docs/reference/software-metadata.md +42 -0
  17. transpiler_mate_api-1.0.0/docs/tutorials/build-your-first-plugin.md +163 -0
  18. transpiler_mate_api-1.0.0/mkdocs.yml +47 -0
  19. transpiler_mate_api-1.0.0/pyproject.toml +134 -0
  20. transpiler_mate_api-1.0.0/src/transpiler_mate/api/__about__.py +18 -0
  21. transpiler_mate_api-1.0.0/src/transpiler_mate/api/__init__.py +65 -0
  22. transpiler_mate_api-1.0.0/src/transpiler_mate/api/plugin.py +201 -0
  23. transpiler_mate_api-1.0.0/src/transpiler_mate/api/py.typed +0 -0
  24. transpiler_mate_api-1.0.0/src/transpiler_mate/api/software_application_models.py +540 -0
  25. transpiler_mate_api-1.0.0/tests/test_namespace.py +34 -0
  26. transpiler_mate_api-1.0.0/tests/test_plugin.py +317 -0
@@ -0,0 +1,9 @@
1
+ .task
2
+ .venv
3
+ __pycache__
4
+ uv.lock
5
+ .mypy_cache
6
+ .pytest_cache
7
+ .ruff_cache
8
+ .vscode
9
+ site
@@ -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 [yyyy] [name of copyright owner]
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,23 @@
1
+ Metadata-Version: 2.5
2
+ Name: transpiler-mate-api
3
+ Version: 1.0.0
4
+ Summary: Stable, execution-environment-neutral contracts for transpiler-mate plugins
5
+ Project-URL: Documentation, https://transpiler-mate.github.io/transpiler-mate-api/
6
+ Project-URL: Issues, https://github.com/transpiler-mate/transpiler-mate-api/issues
7
+ Project-URL: Source, https://github.com/transpiler-mate/transpiler-mate-api
8
+ Author-email: Simone Tripodi <simone.tripodi@terradue.com>, Fabrice Brito <fabrice.brito@terradue.com>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: cwl-utils<1,>=0.43
22
+ Requires-Dist: email-validator>=2.3.0
23
+ Requires-Dist: pydantic<3,>=2.13.4
@@ -0,0 +1,5 @@
1
+ # transpiler-mate-api
2
+
3
+ Stable contracts shared by the runtime and independently distributed plugins.
4
+
5
+ This package deliberately contains no Click dependency, entry-point discovery, source loading, or application orchestration.
@@ -0,0 +1,48 @@
1
+ # Architecture and boundaries
2
+
3
+ The API is a small dependency-inversion boundary. A runtime owns environment-specific work; a plugin owns one transformation; both depend on the same stable contract.
4
+
5
+ ```text
6
+ runtime
7
+ loads and normalizes CWL + metadata
8
+ constructs options and TranspilerContext
9
+ discovers plugin by runtime-specific means
10
+ │
11
+ ▼
12
+ TranspilerPlugin.execute
13
+ │
14
+ ▼
15
+ plugin
16
+ validates domain support
17
+ generates target-specific side effects
18
+ returns None or raises PluginError
19
+ ```
20
+
21
+ ## Why the registration is data
22
+
23
+ `@transpiler_plugin` turns a function into an immutable `PluginRegistration`. A host can inspect metadata and the options model without constructing a stateful plugin class. The execution function remains independent of Click, HTTP servers, workers, and notebooks.
24
+
25
+ The `TranspilerPlugin` protocol also permits other implementations. Structural typing avoids forcing inheritance, while `PluginRegistration` provides the convenient standard implementation.
26
+
27
+ ## Why the context is immutable
28
+
29
+ The runtime prepares a normalized snapshot containing source identity, an
30
+ optional selected-process ID, a mapping of parsed CWL processes, metadata, and a
31
+ resolver. Freezing the context model prevents a plugin from reassigning shared
32
+ invocation fields. Plugin output belongs in plugin-owned side effects, not
33
+ mutations to the context.
34
+
35
+ ## Why discovery is absent
36
+
37
+ Discovery couples packages to deployment policy: entry-point groups, enablement, naming, ordering, and duplicate handling. Keeping it out of this package lets a CLI, web service, notebook, or worker use the same plugin contract with a suitable adapter.
38
+
39
+ This means “custom plugin” has two layers:
40
+
41
+ 1. Implement and export an object satisfying `TranspilerPlugin` using this package.
42
+ 2. Connect that object using the chosen runtime's separately documented mechanism.
43
+
44
+ The first layer is portable. The second is intentionally host-specific.
45
+
46
+ ## Why execution returns `None`
47
+
48
+ The current contract treats generation as side-effecting work and imposes no universal artifact representation. A plugin might write a directory, call an external generator, update a service, or emit several related files. Artifact discovery, atomic publication, and cleanup policy therefore remain plugin/runtime concerns rather than API return values.
@@ -0,0 +1,27 @@
1
+ # Failure semantics
2
+
3
+ The exception split answers one question for a runtime: did the requested transformation fail because the domain request is unsupported, or because execution machinery broke?
4
+
5
+ ## Failure versus execution error
6
+
7
+ `PluginFailureError` is a negative domain result. The plugin recognized the request, applied its rules, and determined that it cannot produce the target. The same input and options should normally fail again until the user changes them or the plugin gains support.
8
+
9
+ `PluginExecutionError` means the plugin intended to support the request but could not complete it. The cause may be transient, such as an unavailable service, or persistent, such as a bug or broken installation. The type alone does not promise that retrying is safe.
10
+
11
+ This distinction is about semantics, not blame. A missing user-selected file may be a domain failure, while a missing template shipped inside the plugin is an execution error, even though both can originate as `FileNotFoundError`.
12
+
13
+ ## What the types do not decide
14
+
15
+ Neither class carries a retry flag, error code, details dictionary, or affected artifacts. The API also does not map the types to terminal exit codes, HTTP statuses, logs, or user-interface severity.
16
+
17
+ A runtime may use the distinction as one input to those decisions, but must define its own policy. In particular, it should not blindly retry `PluginExecutionError`: `execute` has side effects and the API makes no idempotency or transaction guarantee.
18
+
19
+ ## Why causal chaining matters
20
+
21
+ Wrapping a low-level exception provides stable public semantics and a useful plugin-level message. Python's `raise NewError(...) from error` preserves the original error as `__cause__`, allowing diagnostic tooling to retain the exact technical reason.
22
+
23
+ An existing `PluginError` has already crossed that classification boundary. Rewrapping it can accidentally turn a domain refusal into a technical fault, so it should normally be re-raised unchanged.
24
+
25
+ ## Validation is a separate phase
26
+
27
+ Pydantic `ValidationError` generally means a host could not construct `options_model` or `TranspilerContext`. Plugin execution has not yet produced either domain result. Once execution begins, document-specific compatibility checks belong to the plugin and should use `PluginFailureError`; failures of generation machinery should use `PluginExecutionError`.
@@ -0,0 +1,49 @@
1
+ # Define and validate options
2
+
3
+ Set `options_model` to a Pydantic `BaseModel` subclass. This keeps the transport representation—CLI strings, JSON, or worker messages—outside the plugin's execution logic.
4
+
5
+ ## Reject misspelled fields
6
+
7
+ ```python
8
+ from pathlib import Path
9
+ from typing import Literal
10
+
11
+ from pydantic import BaseModel, ConfigDict, Field
12
+
13
+
14
+ class Options(BaseModel):
15
+ model_config = ConfigDict(extra="forbid")
16
+
17
+ output: Path
18
+ dialect: Literal["stable", "experimental"] = "stable"
19
+ workers: int = Field(default=1, ge=1)
20
+ ```
21
+
22
+ Use Pydantic validators for shape, type, range, and relationships that can be checked without the resolved document. A host normally constructs this model before calling `execute`.
23
+
24
+ ## Use no options
25
+
26
+ ```python
27
+ from transpiler_mate.api import EmptyOptions, TranspilerContext, transpiler_plugin
28
+
29
+
30
+ @transpiler_plugin(
31
+ name="fixed-target",
32
+ description="Generate the fixed target format",
33
+ options_model=EmptyOptions,
34
+ )
35
+ def plugin(context: TranspilerContext, options: EmptyOptions) -> None:
36
+ ...
37
+ ```
38
+
39
+ `EmptyOptions` is not an invitation to accept arbitrary configuration: its `extra="forbid"` setting rejects every unknown field.
40
+
41
+ ## Separate option validation from domain validation
42
+
43
+ - Invalid types, missing option fields, forbidden extra fields, and numeric constraints should produce Pydantic `ValidationError` while constructing the options model.
44
+ - A well-formed option that cannot be honored for this particular CWL document should cause `PluginFailureError` during execution.
45
+ - A valid option that fails because an external tool crashes should cause `PluginExecutionError` during execution.
46
+
47
+ For example, validate that `workers >= 1` in the model. If `dialect="stable"` is valid in general but the current document uses an experimental CWL feature, raise `PluginFailureError` from `execute`.
48
+
49
+ Do not catch a `ValidationError` merely to relabel it as a plugin error unless the validation occurs inside execution and you can add meaningful domain context. Runtime behavior for top-level option validation is outside this API.
@@ -0,0 +1,121 @@
1
+ # Develop and package a plugin
2
+
3
+ Use this guide as a production checklist for a custom plugin.
4
+
5
+ ## Declare the dependency
6
+
7
+ Give the plugin its own distribution and depend on the API package rather than on a particular CLI or server:
8
+
9
+ ```toml
10
+ [project]
11
+ name = "transpiler-mate-my-target"
12
+ version = "0.1.0"
13
+ requires-python = ">=3.10"
14
+ dependencies = ["transpiler-mate-api>=1,<2"]
15
+ ```
16
+
17
+ Pin a major-version range you test. Add target SDKs, template engines, or serializers as your plugin's own dependencies.
18
+
19
+ ## Choose an options model
20
+
21
+ For a configurable plugin, create a Pydantic model:
22
+
23
+ ```python
24
+ from pathlib import Path
25
+
26
+ from pydantic import BaseModel, ConfigDict
27
+
28
+
29
+ class Options(BaseModel):
30
+ model_config = ConfigDict(extra="forbid")
31
+
32
+ output_directory: Path
33
+ overwrite: bool = False
34
+ ```
35
+
36
+ For a plugin with no parameters, use the provided `EmptyOptions`. It also rejects unexpected fields.
37
+
38
+ ## Implement a stateless function
39
+
40
+ ```python
41
+ from transpiler_mate.api import TranspilerContext, transpiler_plugin
42
+
43
+
44
+ @transpiler_plugin(
45
+ name="my-target",
46
+ description="Generate files for My Target",
47
+ options_model=Options,
48
+ )
49
+ def plugin(context: TranspilerContext, options: Options) -> None:
50
+ for process in context.processes:
51
+ generate(process, options.output_directory, options.overwrite)
52
+ ```
53
+
54
+ Keep run-specific mutable state local to `execute`. A runtime may retain and reuse the registration object; the public contract makes no single-use or concurrency guarantee.
55
+
56
+ The execution signature is exact in intent:
57
+
58
+ ```python
59
+ def execute(context: TranspilerContext, options: OptionsT) -> None: ...
60
+ ```
61
+
62
+ - Read the parsed CWL processes from the ID-to-process mapping in
63
+ `context.document`, or iterate over `context.processes` when the IDs are not
64
+ needed.
65
+ - Use `context.get_processes_by_type(ProcessType)` when the plugin accepts only
66
+ a particular CWL process type. Top-level union aliases such as
67
+ `cwl_utils.parser.Workflow` select that type across supported CWL versions.
68
+ Supply `process_ids` to restrict the lookup, or set `fail_if_empty=False`
69
+ when no match is a valid outcome.
70
+ - Use `context.resolved_process` when the plugin requires the process selected
71
+ by `context.process_id`. Access raises `PluginExecutionError` if the source
72
+ did not select a process or if the selected ID is absent from `document`.
73
+ - Read normalized software metadata from `context.metadata`.
74
+ - Use `context.resolver` when you deliberately need another source.
75
+ - Produce results through side effects. The contract does not define a returned artifact list.
76
+
77
+ ## Export the registration
78
+
79
+ ```python
80
+ # src/my_target/__init__.py
81
+ from my_target.plugin import plugin
82
+
83
+ __all__ = ["plugin"]
84
+ ```
85
+
86
+ The decorated value is a `PluginRegistration` and structurally implements `TranspilerPlugin`. A host can import it and inspect `name`, `description`, `options_model`, and `execute`.
87
+
88
+ ## Integrate with a runtime
89
+
90
+ Stop at the runtime boundary and consult that runtime's documentation. This repository does not specify:
91
+
92
+ - a package naming scheme;
93
+ - an entry-point group;
94
+ - a module-level variable name;
95
+ - plugin uniqueness rules;
96
+ - CLI option conversion;
97
+ - activation, ordering, or discovery.
98
+
99
+ If a runtime asks for a `TranspilerPlugin`, pass the exported registration. If it asks for an entry point or adapter, configure exactly the group or wrapper that runtime documents.
100
+
101
+ ## Make writes robust
102
+
103
+ Validate the complete domain input before producing files where practical. For multi-file output, write to a staging directory and publish only after generation succeeds. If execution fails, remove only temporary artifacts the current invocation owns; never broadly delete an output directory.
104
+
105
+ Return normally on success. Use the exception policy in [Report failures correctly](report-failures.md) for failures.
106
+
107
+ ## Verify the contract
108
+
109
+ At minimum, test:
110
+
111
+ - registration metadata and `options_model`;
112
+ - valid and invalid options;
113
+ - single-entry and multi-entry process mappings;
114
+ - successful `resolved_process` selection and the missing/unknown
115
+ `process_id` errors, if the plugin uses that property;
116
+ - every supported domain rejection as `PluginFailureError`;
117
+ - technical dependency failures as `PluginExecutionError`;
118
+ - the exception message and preserved cause;
119
+ - absence or cleanup of partial output.
120
+
121
+ See [Test a plugin](test-a-plugin.md) for patterns.
@@ -0,0 +1,64 @@
1
+ # Report failures correctly
2
+
3
+ Raise the exception that tells the host whether the plugin rejected the requested transformation or malfunctioned while trying to perform it.
4
+
5
+ ## Raise `PluginFailureError` for expected domain rejection
6
+
7
+ ```python
8
+ from transpiler_mate.api import PluginFailureError
9
+
10
+
11
+ if not supports(process):
12
+ raise PluginFailureError(
13
+ f"process {process.id!r} uses scatter, which this target does not support"
14
+ )
15
+ ```
16
+
17
+ Use it when the plugin is operating correctly and has enough information to give a deterministic, actionable refusal. Typical cases are unsupported CWL constructs, an incompatible option/document combination, a user-selected destination that already exists when overwrite is disabled, or missing domain data required for generation.
18
+
19
+ ## Raise `PluginExecutionError` for technical failure
20
+
21
+ ```python
22
+ from transpiler_mate.api import PluginExecutionError
23
+
24
+
25
+ try:
26
+ completed = run_generator(command)
27
+ except OSError as error:
28
+ raise PluginExecutionError("could not start the target generator") from error
29
+
30
+ if completed.returncode != 0:
31
+ raise PluginExecutionError(
32
+ f"target generator exited with status {completed.returncode}"
33
+ )
34
+ ```
35
+
36
+ Use it when a supported operation could not complete because machinery failed: a subprocess could not start or crashed, generated output could not be written, a required service became unavailable, or an internal invariant was violated.
37
+
38
+ ## Preserve errors that are already classified
39
+
40
+ ```python
41
+ from transpiler_mate.api import PluginError, PluginExecutionError
42
+
43
+
44
+ try:
45
+ generate()
46
+ except PluginError:
47
+ raise
48
+ except Exception as error:
49
+ raise PluginExecutionError("generation failed") from error
50
+ ```
51
+
52
+ Catch narrowly whenever possible. If a boundary catch is necessary, catch `Exception`, not `BaseException`, so cancellation signals such as `KeyboardInterrupt` and `SystemExit` still propagate. Use `raise ... from error` to keep the original traceback.
53
+
54
+ ## Write useful messages
55
+
56
+ State the failed operation, relevant subject, and a remedy when known:
57
+
58
+ ```text
59
+ process 'align': scatter method 'dotproduct' is unsupported; use 'nested_crossproduct'
60
+ ```
61
+
62
+ Do not include credentials, access tokens, complete environment dumps, or sensitive source contents. Do not assume whether the host shows the message in a terminal, JSON response, notebook, or worker log.
63
+
64
+ For a complete circumstance table, see the [exception contract](../reference/exceptions.md).
@@ -0,0 +1,36 @@
1
+ # Resolve another CWL source
2
+
3
+ The runtime places a `TranspilerContextResolver` in every context. Use it when a plugin must load another CWL location using the same normalization policy as the host.
4
+
5
+ ```python
6
+ from transpiler_mate.api import (
7
+ PluginError,
8
+ PluginExecutionError,
9
+ TranspilerContext,
10
+ )
11
+
12
+
13
+ def load_library(context: TranspilerContext, location: str) -> TranspilerContext:
14
+ try:
15
+ return context.resolver.resolve(location)
16
+ except PluginError:
17
+ raise
18
+ except Exception as error:
19
+ raise PluginExecutionError(
20
+ f"could not resolve supporting CWL source {location!r}"
21
+ ) from error
22
+ ```
23
+
24
+ Pass a location string accepted by the runtime. Although `TranspilerContext.source` is always an `AnyUrl`, the resolver protocol deliberately accepts `str` so a runtime can define its own location syntax and relative-resolution behavior.
25
+
26
+ Do not instantiate a context resolver or reload `context.source` just to access the current document. The runtime has already prepared:
27
+
28
+ - `context.document`, mapping process IDs to parsed `Process` objects;
29
+ - `context.processes`, an iterable view of the mapping values;
30
+ - `context.process_id`, the optional fragment identifier selected by the
31
+ source;
32
+ - `context.resolved_process`, which returns that selection or raises
33
+ `PluginExecutionError` when no valid process was selected;
34
+ - `context.metadata`, normalized `SoftwareApplication` metadata.
35
+
36
+ The resolver may raise exceptions defined by its runtime. Preserve an existing `PluginError`; wrap an unexpected lower-level exception only at a boundary where your plugin can add useful operation and location context. Ask the target runtime whether it already normalizes resolver failures before adding a wrapper.