Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/articles/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ Custom converters are supplied in a companion `converters` module, which the gen

The `--namespace` option is not available for this target, since the generated module declares no namespace.

The following options are available to configure the generated output.

#### Package
```text
--package
```

Specifies whether to generate the interface as a package. The interface is written as `__init__.py`, together with a `py.typed` marker that declares the package as typed, so the output directory alone determines the import path. An output directory of `src/mypackage/mydevice` produces the `mypackage.mydevice` package, so a device repository needs no re-export module. Without this option the interface is written as a single `device.py` module, and the same output directory produces `mypackage.mydevice.device`.

## Generating device firmware code

Device firmware interface stubs can be generated by providing an additional metadata file, `ios.yml`, describing IO pin configuration. Currently only the [Harp Core ATxmega](https://harp-tech.org/core.atxmega/) is supported.
Expand Down
9 changes: 8 additions & 1 deletion src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ public GeneratePythonInterfaceCommand()
MetadataPathArgument metadataPathArgument = new();
OutputPathOption outputPathOption = new();

Option<bool> packageOption = new("--package")
{
Description = "Generate the interface as a package."
};

Arguments.Add(metadataPathArgument);
Options.Add(packageOption);
Options.Add(outputPathOption);

SetAction(parseResult =>
{
var outputPath = parseResult.GetRequiredValue(outputPathOption);
var metadataPath = parseResult.GetRequiredValue(metadataPathArgument);
var package = parseResult.GetValue(packageOption);

var deviceMetadata = DeviceMetadata.Load(metadataPath.FullName);
var generator = new PythonGenerator(deviceMetadata);
var generator = new PythonGenerator(deviceMetadata, package);
var implementation = generator.GenerateImplementation();
if (GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
Expand Down
Loading