-
-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ExternalTool exportable (#21258)
This MR wires `ExternalTool`s into the export machinery. It exposes them under a separate cli arg `--bin`. Although it uses some of the same machinery as `--resolve`, there are several differences that I think support a separate flag (and some separate internal): 1. `ExternalTool`s don't have a resolve. They therefore must not show up for generating lockfiles. We have to implement this separation interally, so we should probably surface that. 2. They would be invoked directly (instead of `source dist/export/.../activate`) 3. We can put them all in a folder "dist/export/bin" so people can get them all Closes #21251 Bikeshedding: - [x] Do we like `--bin` (yes) - [x] Is putting all the bins in the same dir what we want (yes, we want a "bin" folder with all the binaries. But we have to put each binary's digest in its own folder to prevent collisions of supporting files) - [-] Do we want to make all TemplatedExternalTools exportable? We could extend Subsystem.rules and add the UnionRule there (deferred from this MR) --------- Co-authored-by: Huon Wilson <wilson.huon@gmail.com>
- Loading branch information
Showing
42 changed files
with
879 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/docs/writing-plugins/common-plugin-tasks/allowing-tool-export.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: Making a tool exportable | ||
sidebar_position: 10 | ||
--- | ||
|
||
How to make a tool exportable with the `export` goal. | ||
|
||
--- | ||
|
||
Backends that implement the `export` goal can indicate binaries that should be exported. These will have their contents exported to a subfolder in the `dist/bins` directory, and the binary itself will be linked in `dist/bin`. | ||
|
||
## Downloadable Tools | ||
|
||
Subclasses of `ExternalTool` (including `TemplatedExternalTool`) have the logic for exporting implemented. Tools are marked for export as follows: | ||
|
||
1. Implement `ExternalTool.generate_exe` if the default is not correct. For instance, a tool downloaded might include a binary, a readme, and a license. This method will point to the binary within the downloaded files. | ||
|
||
2. Register a `UnionRule` with `ExportableTool`. For example, `UnionRule(ExportableTool, FortranLint)` | ||
|
||
## Implementing for new backends | ||
|
||
Backends need to implement: | ||
|
||
1. A subclass of `ExportRequest` | ||
|
||
```python | ||
@dataclass(frozen=True) | ||
class ExportExternalToolRequest(ExportRequest): | ||
pass | ||
``` | ||
|
||
2. A rule from this subclass to `ExportResults` | ||
|
||
```python | ||
@rule | ||
async def export_external_tools( | ||
request: ExportExternalToolRequest, export: ExportSubsystem | ||
) -> ExportResults: | ||
``` | ||
|
||
3. Inside of that rule, fill the `ExportResult.exported_binaries` field. | ||
|
||
```python | ||
ExportResult( | ||
description=f"Export tool {req.resolve}", | ||
reldir=dest, | ||
digest=downloaded_tool.digest, | ||
resolve=req.resolve, | ||
exported_binaries=(ExportedBinary(name=Path(exe).name, path_in_export=exe),), | ||
) | ||
``` | ||
|
||
4. For every tool, mark it for export registering a `UnionRule` with `ExportableTool`. | ||
|
||
```python | ||
def rules(): | ||
return [ | ||
..., | ||
`UnionRule(ExportableTool, FortranLint)`, | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.