Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Reason given by maintainers: deprecated

SiLA2CodeGenerator

This package supplies a code generator that creates a working server and client prototype based on feature definition files and a service description file.

The codegenerator supports the SiLA2 server/client developer in two major tasks:

  1. it converts the Feature Description File (FDL/XML) into a Protobuf .proto file

  2. it generates a completely running SiLA server/client ( in simulation mode), where only the real/hardware specific code needs to be added/subclassed to the generated prototype code.

s.Tutorial for a fast introduction

Features

  • .proto file generation out of FeatureDescription Files FDL/XML

  • .proto file compilation

  • complete server/client generation out of a project directory, containing a service_description file (s.hello_sila_project)

  • support for Service/Device detection

  • support for Service/Device feature detection

  • switching between simulation and real (hardware) mode (+)

  • default / standard Features (SiLAService, Sim, runcontrol, deviceinfo, …) (+)

  • default error handling (+)

  • sila-python-django support (+)

(+) under development

Installation

To install this library execute the following commands.

pip install -r requirements.txt
pip install .

This will also install the sila2lib package, if it is not installed yet. Since the packages from the requirements.txt file do no version check, you will have to run pip install --upgrade -r requirements.txt to force an upgrade to a new version.

It is highly recommended to work in the python3 virtual environment (default proposal of the installer): This ensures that the system Python setup is not affected. To activate the virtual environment, type

source [venv]/bin/activate

to deactivate it again, simply type (mind: here is no path required)

deactivate

Run

The code can be run using the command silacodegenerator. Use silacodegenerator --help to get an overview over the accepted arguments. The most common use will be

silacodegenerator --build <path/to/project/dir>

which, creates the .proto files, compiles them to the gRPC libraries and then builds server, client, servicer and implementation prototypes.

Templates

A strength of this CodeGenerator is the extensive usage of template files to generate the prototypes. Templates can be found in the package source under the templates directory. To chose which template to apply, call the code generator with the --template <template-name> flag.

Available templates are:

  • run-inline: Based on the previous implementations. This templates generates calls to commands and properties of all features inside a run() method of the client class.

  • run-method: For each command call and property the client implements its own method, effectively giving easy access to these data to a script from the outside. run() is still used to validate the connection to the server and retrieve basic server capabilities.

If you want to implement your own template, it is recommended to copy one existing template and then modify it. To use it during the build process, run the code generator with the flag --template-dir <path/to/template/directory>, which will overwrite the --template <..> flag and use the given directory as template source instead.

Example

The examples directory contains the hello_sila2_project. Building this project with the following command run inside the examples sub-directory will result in a new directory in the same folder which is named after the service name from the corresponding service description file.

.../examples> silacodegenerator --build hello_sila2_project

The new folder should have the following structure

HelloSiLA2
 + meta                             # the meta information, i.e. the FDL, proto
                                    #   and service description file
 + GreetingProvider
   # Additional information
   __init__.py                      # make this folder a python package
   # Implementations of the server, edit those for the actual implementation
   GreetingProvider_real.py         # the prototype for the real case
   GreetingProvider_simulation.py   # the prototype for the simulation case
   # Servicer
   GreetingProvoder_servicer.py     # The servicer that serves as a bridge between the
                                    #   server and the corresponding implementation
     + gRPC
      __init__.py                   # make this folder a python package
      # The auto-generated stub files.
      #     Do not Edit!
      GreetingProvider_pb2.py
      GreetingProvider_pb2-grpc.py

Proto file generation

If you only want to convert a SiLA2 Feature Description File (FDL) into a .proto file:

silacodegenerator [feature_descripton_file.xml]

This will result in a proto file with the output filename feature_descripton_file.proto

The output proto filename can be set with the -p option.

Example:

python3 silacodegenerator.py -f [feature_descripton_file.xml] -p my_protofilename.proto

Testing

To validate that the basic machinery is working correctly, please run the unittests:

cd [dir of codegenerator]

python -m unittest

Notes

  • While in prior implementations the change between Simulation and Real mode relied on the Server and the inject_implementation() method of the servicer, this is now complete the responsibility of the servicer. It thus accepts the simulation_mode parameter at initialisation, and will thus either load the <Feature>Simulation or <Feature>Real implementation.

Metadata

Release files for sila2codegenerator 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sila2codegenerator 0.2.0
File Size Uploaded Provenance
sila2codegenerator-0.2.0.tar.gz 24.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sila2codegenerator 0.2.0
File Interpreter ABI Platform
sila2codegenerator-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 109.0 kB

Release files / sila2codegenerator-0.2.0.tar.gz

Download URL sila2codegenerator-0.2.0.tar.gz
Size 24.7 kB
Tags Source
SHA-256 checksum
How to use checksums
18f828c2e457d1adf5cb69b09f6673ae79f8d222195dfe6ce7efccd0ecfd8c7a
BLAKE2b-256 checksum
How to use checksums
4891f058cfbfd810266999c91995699178490bbfb88e58e84f3d0a87257759cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9

Release files / sila2codegenerator-0.2.0-py3-none-any.whl

Download URL sila2codegenerator-0.2.0-py3-none-any.whl
Size 84.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
135703a7a6a6bf21f3f74f9f028d15d935a4dbe89f42236d2ce5544f1ec3d71f
BLAKE2b-256 checksum
How to use checksums
fe53ecf4d5ad84e07cde864fd285753ba39207ecb69b40ac66da695089e6db66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9

Security for sila2codegenerator 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page