|
1 | 1 | <!-- |
2 | | -SPDX-FileCopyrightText: 2024 Ledger SAS |
| 2 | +SPDX-FileCopyrightText: 2024 - 2025 Ledger SAS |
3 | 3 |
|
4 | 4 | SPDX-License-Identifier: Apache-2.0 |
5 | 5 | --> |
6 | 6 |
|
7 | | -# Ledger python package template repository |
8 | | - |
9 | | -This repository is made in order to be used as a clean |
10 | | -basis to produce python packages to be exported to a pypi repository. |
11 | | - |
12 | | -This repository aim to comply to, at least, PEP420, PEP 517, PEP 621 and PEP 660. |
13 | | - |
14 | | -The goal is to modify the content of the pyledger namespace, |
15 | | -adding your own package name and content, and use the overall python ecosystem |
16 | | -supported in this very repository to build, check and deploy your package. |
17 | | - |
18 | | -## Using Docker |
19 | | - |
20 | | -This package can be fully manipulated (building, testing, deploying) |
21 | | -with the `docker-kulos-nexus.orange.ledgerlabs.net/pythonbot` Docker image. |
22 | | -This can be done through the usual `docker run` or through |
23 | | -the `.devcontainer.json` vscode file for vscode users. |
24 | | - |
25 | | -## Personalising from this template |
26 | | - |
27 | | -This template deploy an empty python package using the `pyledger` python namespace, |
28 | | -in which a `template` custom package is created. This package hold a stub library, |
29 | | -and deploy a custom associated `templatebin` executable automatically (see `pyproject.toml` file). |
30 | | - |
31 | | -The goal here is to update the package name and content based on your need, |
32 | | -keeping all the python related element (CI/CD, build system, linting and so on) |
33 | | -in order to reduce as much as possible to work associated to the build and quality system. |
34 | | - |
35 | | -When creating an effective package repository from this template, you need to: |
36 | | - |
37 | | - 1. Rename the `pyledger/template` directory with a real `pyledger` package name |
38 | | - (other than template), and write a clean content in it. |
39 | | - Just keep the `__version__` definition line in the `__init__.py` file as-is, |
40 | | - as it is automatically updated using vcs information |
41 | | - 1. Replace the occurrences of `template` in `tox.ini` file with your package name |
42 | | - 1. Replace the occurrences of `template` in `pyproject.tom` file with your package name. |
43 | | - This includes the _name_ and _description_ fields, |
44 | | - the _dynamic versioning target_ file path and the _homepage_ |
45 | | - 1. Update (or remove) the `tool.poetry.script` field depending on your needs |
46 | | - (executable(s) needed or not) |
47 | | - 1. Replace `env.PROJECTNAME` variable in the `.github/workflows/main.yml` file |
48 | | - 1. Replace the `tests/test_template.py` with your `pytest` testsuite |
49 | | - |
50 | | -That is all ! The build system is ready and you can use the below commands. |
51 | | - |
52 | | -## Building |
53 | | - |
54 | | -Build the package can be done directly using `poetry`: |
55 | | - |
56 | | -```console |
57 | | -poetry build |
| 7 | +# Outpost Barbican |
| 8 | + |
| 9 | +Barbican is the Outpost OS meta tools for building project, SDK and integration, |
| 10 | +written in python. |
| 11 | + |
| 12 | +## Dependencies |
| 13 | + - Python >= 3.10 |
| 14 | + - Jinja2 >= 3.1.0 |
| 15 | + - jinja-cli >= 1.2.0 |
| 16 | + - jsonschema >= 4.18.0 |
| 17 | + - kconfiglib >= 14.1.0 |
| 18 | + - lief >= 0.13,<0.15 |
| 19 | + - meson >= 1.4.0,<1.5.0 |
| 20 | + - ninja >= 1.11.0 |
| 21 | + - ninja_syntax > 1.7 |
| 22 | + - svd2json >= 0.1.6 |
| 23 | + - dts-utils >= 0.3.0 |
| 24 | + - tomli >= 2.0.1; python_version < '3.11' |
| 25 | + - referencing >= 0.33.0 |
| 26 | + - rich >= 13.6 |
| 27 | + - GitPython >= 3.1.43 |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +A project is describe by a toml configuration file, a dts for the targeted SoC |
| 32 | +and `Kconfig` `dotconfig` for kernel and application(s). |
| 33 | + |
| 34 | +### Configuration |
| 35 | + |
| 36 | +The following is the sample project configuration describing a simple project with |
| 37 | +simple application(s) |
| 38 | + |
| 39 | +```toml |
| 40 | +name = 'HelloWorld Project' |
| 41 | +license = 'Apache-2.0' |
| 42 | +license_file = ['LICENSE.txt'] |
| 43 | +dts = 'dts/sample.dts' |
| 44 | +crossfile = 'cm33-none-eabi-gcc.ini' |
| 45 | +version = 'v0.0.1' |
| 46 | + |
| 47 | +[kernel] |
| 48 | +scm.git.uri = 'https://github.com/outpost-os/sentry-kernel.git' |
| 49 | +scm.git.revision = 'main' |
| 50 | +config = 'configs/sentry/nucleo_u5a5.config' |
| 51 | + |
| 52 | +[runtime] |
| 53 | +scm.git.uri = 'git@github.com:outpost-os/shield.git' |
| 54 | +scm.git.revision = 'main' |
| 55 | +config = 'configs/shield/shield.config' |
| 56 | + |
| 57 | +[application.hello] |
| 58 | +scm.git.uri = 'https://github.com/outpost-os/sample-rust-app.git' |
| 59 | +scm.git.revision = 'main' |
| 60 | +config = 'configs/hello/hello.config' |
| 61 | +build.backend = 'cargo' |
| 62 | +depends = [] |
| 63 | +provides = ['hello.elf'] |
58 | 64 | ``` |
59 | 65 |
|
60 | | -This command performs the following steps: |
61 | | - |
62 | | -* Parse the `pyproject.toml` file, |
63 | | -* Calculate the effective project requirements (`poetry.lock` file), |
64 | | -* Install the build-depends package in a python venv, |
65 | | -* Build the package. |
66 | | - |
67 | | -The result is saved in the `dist/` subdirectory. |
| 66 | +### Download |
68 | 67 |
|
69 | | -## Updating version |
70 | | - |
71 | | -The package version is automatically managed based on semver and vcs versioning and tagging. |
72 | | -This is made through `poetry dynamic versioning`, as set in the `pyproject.toml` file, |
73 | | -in the `tools.poetry-dynamic-versioning` block. |
74 | | - |
75 | | -Updating the version is made using: |
| 68 | +Downloads kernel/runtime and applications describe in `project.toml` to src directory |
76 | 69 |
|
77 | 70 | ```console |
78 | | -poetry dynamic-versioning |
| 71 | +barbican download |
79 | 72 | ``` |
| 73 | +### Update |
80 | 74 |
|
81 | | -This update in the very same time both the `pyproject.toml` and the `_version.py` file version, |
82 | | -based on the current VCS state. The version mapping is using dirty flag and metadata (git hash) infos. |
83 | | -See <https://pypi.org/project/poetry-dynamic-versioning/> for more information. |
84 | | - |
85 | | -## Updating dependencies |
86 | | - |
87 | | -Dependencies are declared in the `pyproject.toml` file (PEP-517), including separated dependency groups |
88 | | -for development cases (typically unit testing, PEP-660). |
89 | | - |
90 | | -When updating the dependency list, the lock file needs to be updated. |
91 | | -This is done using: |
| 75 | +Updates sources if configuration change and/or revision update. |
| 76 | +Package need to be already downloaded to be updated. |
92 | 77 |
|
93 | 78 | ```console |
94 | | -poetry lock |
| 79 | +barbican update |
95 | 80 | ``` |
| 81 | +### Setup |
96 | 82 |
|
97 | | -This command performs the following steps: |
98 | | - |
99 | | -* Parse the `pyproject.toml` |
100 | | -* Recalculate the overall dependency list |
101 | | -* Check potential incompatibilties |
102 | | -* Forge the effective dependencies for various cases (install, development, etc.). |
103 | | - |
104 | | -## Running the overall testsuite |
105 | | - |
106 | | -### Basics |
107 | | - |
108 | | -The testsuite is fully manipulated through Tox (<https://tox.wiki/en/latest/>). |
109 | | -This allows to execute the overall testsuite, linter execution, coverage calculation |
110 | | -and reporting through a fully integrated framework. |
111 | | - |
112 | | -Basic usage: |
| 83 | +Generates jinja build script for project build (i.e. kernel, runtime, application and |
| 84 | +firmware integration). Files are generated in build directory. |
113 | 85 |
|
114 | 86 | ```console |
115 | | -tox run |
| 87 | +barbican setup |
116 | 88 | ``` |
117 | 89 |
|
118 | | -When executing this command, tox execute all the successive steps declared in the `tox.ini` file. |
119 | | - |
120 | | -This includes a linter pass, based on the tools `black`, `mypy` and `flake8`. |
121 | | -Then the `htmlcov` target is executed. This executes the pytest based unit test suite, |
122 | | -associated with `coverage` for the test coverage calculation. |
123 | | -The coverage report is saved as a standalone website in the `htmlcov/` directory, |
124 | | -giving the overall package coverage. |
125 | | - |
126 | | -The Test Suite provide 3 targets that can be executed independently of each others: |
127 | | - |
128 | | -* `lint`: linters execution |
129 | | - * `mypy`: static typing analysis. Report is in `./mypycov` directory |
130 | | - * `flake8`: PEP8 linter validator Report is in `./flakereport` directory |
131 | | - * `black`: python code formatter. Returns diff between your code and the `pycodestyle` model. |
132 | | -* `unittests`: unit testing using `pytest`, without code coverage |
133 | | -* `htmlcov`: unit testing using `coverage` with code coverage. Report is in `./htmlcov` directory. |
134 | | - |
135 | | -This can be done by executing the following: |
| 90 | +### Build |
136 | 91 |
|
137 | 92 | ```console |
138 | | -tox -e lint |
139 | | -tox -e unittests |
140 | | -tox -e htmlcov |
| 93 | +cd output/build |
| 94 | +ninja |
141 | 95 | ``` |
142 | 96 |
|
143 | | -### Using multiple python versions |
| 97 | +## TODO |
144 | 98 |
|
145 | | -If the host has multiple python versions installed, `tox` can execute its testenv |
146 | | -on multiple versions explicitly using the pre-defined environments. |
| 99 | + - SDK generation |
| 100 | + - Pre built C and Rust toolchain in SDK |
147 | 101 |
|
148 | | -For example, executing the tox `testenv` testsuite (corresponding to the unit-testing) |
149 | | -on the Python 3.10 environment can be done using: |
| 102 | +## License |
150 | 103 |
|
151 | | -```console |
152 | | -tox -e py310 |
153 | 104 | ``` |
| 105 | +Copyright 2024 - 2025 Ledger SAS |
154 | 106 |
|
155 | | -ToX always use virtual environments, that are deployed in the `.tox` local directory, |
156 | | -allowing concurrent execution of multiple environments if needed. |
157 | | -All package dependencies are installed in the local virtualenv, without impacting the host. |
| 107 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 108 | +you may not use this file except in compliance with the License. |
| 109 | +You may obtain a copy of the License at |
158 | 110 |
|
159 | | -Forcing ToX to recreate the environment (redeploy the virtual env) is done using the `-r` option. |
| 111 | + http://www.apache.org/licenses/LICENSE-2.0 |
160 | 112 |
|
161 | | -## Publishing |
162 | | - |
163 | | -Publishing the package can be done using poetry's `publish` target, as described in the manual. |
| 113 | +Unless required by applicable law or agreed to in writing, software |
| 114 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 115 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 116 | +See the License for the specific language governing permissions and |
| 117 | +limitations under the License. |
| 118 | +``` |
0 commit comments