diff --git a/docs/articles/generate.md b/docs/articles/generate.md index 412a3d3..92ca372 100644 --- a/docs/articles/generate.md +++ b/docs/articles/generate.md @@ -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. diff --git a/src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs b/src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs index fbe420a..620d220 100644 --- a/src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs +++ b/src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs @@ -11,16 +11,23 @@ public GeneratePythonInterfaceCommand() MetadataPathArgument metadataPathArgument = new(); OutputPathOption outputPathOption = new(); + Option 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);