| 1 |
Contributing |
| 2 |
============ |
| 3 |
|
| 4 |
.. note:: **Abstract** |
| 5 |
|
| 6 |
This document describes the development process of {kiwi} |
| 7 |
and how you can be part of it. This description applies |
| 8 |
to version |version|. |
| 9 |
|
| 10 |
.. toctree:: |
| 11 |
:maxdepth: 1 |
| 12 |
|
| 13 |
contributing/kiwi_from_python |
| 14 |
contributing/kiwi_plugin_architecture |
| 15 |
contributing/scripts_testing |
| 16 |
contributing/schema_extensions.rst |
| 17 |
|
| 18 |
The Basics |
| 19 |
---------- |
| 20 |
|
| 21 |
The core appliance builder is developed in Python and follows the test- |
| 22 |
driven development rules. |
| 23 |
|
| 24 |
If you want to implement a bigger feature, consider opening an issue on |
| 25 |
GitHub first to discuss the changes. Or, join the discussion in the |
| 26 |
`#kiwi` channel on `Matrix <https://matrix.to/#kiwi:matrix.org>`_. |
| 27 |
|
| 28 |
Fork the upstream repository |
| 29 |
---------------------------- |
| 30 |
|
| 31 |
1. On GitHub, navigate to: https://github.com/OSInside/kiwi. |
| 32 |
|
| 33 |
2. In the top-right corner of the page, click :command:`Fork`. |
| 34 |
|
| 35 |
Create a local clone of the forked repository |
| 36 |
--------------------------------------------- |
| 37 |
|
| 38 |
.. code:: shell-session |
| 39 |
|
| 40 |
$ git clone https://github.com/YOUR-USERNAME/kiwi |
| 41 |
|
| 42 |
$ git remote add upstream https://github.com/OSInside/kiwi.git |
| 43 |
|
| 44 |
Install Required Operating System Packages |
| 45 |
------------------------------------------ |
| 46 |
|
| 47 |
{kiwi} requires additional packages at runtime that are not |
| 48 |
provided by `pip`. Those will be pulled in by installing |
| 49 |
the following package: |
| 50 |
|
| 51 |
* kiwi-systemdeps |
| 52 |
|
| 53 |
The package is provided on the Open Build Service in the |
| 54 |
`Virtualization:Appliances:Builder |
| 55 |
<https://download.opensuse.org/repositories/Virtualization:/Appliances:/Builder>`__ |
| 56 |
project. For manual inspection of the packages |
| 57 |
that are pulled in from the above `kiwi-systemdeps` package, please refer |
| 58 |
to the `package/python-kiwi-spec-template` spec file from the checked- |
| 59 |
out Git repository. |
| 60 |
|
| 61 |
Create a Python Virtual Development Environment |
| 62 |
----------------------------------------------- |
| 63 |
|
| 64 |
The following commands initialize and activate a development |
| 65 |
environment for Python 3: |
| 66 |
|
| 67 |
.. code:: shell-session |
| 68 |
|
| 69 |
$ poetry install --all-extras |
| 70 |
|
| 71 |
.. note:: |
| 72 |
|
| 73 |
To create the python virtual env for another version of |
| 74 |
Python, e.g. 3.11, call the following prior the poetry install |
| 75 |
:: |
| 76 |
|
| 77 |
$ poetry env use python3.11 |
| 78 |
|
| 79 |
The command above automatically creates the application script |
| 80 |
called :command:`kiwi-ng`, which allows you to run {kiwi} from the |
| 81 |
Python sources inside the virtual environment using Poetry: |
| 82 |
|
| 83 |
.. code:: shell-session |
| 84 |
|
| 85 |
$ poetry run kiwi-ng --help |
| 86 |
|
| 87 |
Running the Unit Tests |
| 88 |
---------------------- |
| 89 |
|
| 90 |
Before submitting your changes via a pull request, ensure that all tests |
| 91 |
pass and that the code has the required test coverage via the command: |
| 92 |
|
| 93 |
.. code:: shell-session |
| 94 |
|
| 95 |
$ make check |
| 96 |
$ make test |
| 97 |
|
| 98 |
Create a Branch for each Feature or Bugfix |
| 99 |
------------------------------------------ |
| 100 |
|
| 101 |
Code changes should be done in an extra Git branch. This allows for |
| 102 |
creating GitHub pull requests in a clean way. See also: `Collaborating with |
| 103 |
issues and pull requests |
| 104 |
<https://help.github.com/en/categories/collaborating-with-issues-and-pull-requests>`_. |
| 105 |
|
| 106 |
.. code:: shell-session |
| 107 |
|
| 108 |
$ git checkout -b my-topic-branch |
| 109 |
|
| 110 |
Make and commit your changes. |
| 111 |
|
| 112 |
.. note:: |
| 113 |
|
| 114 |
You can make multiple commits, which is generally useful to |
| 115 |
give your changes a clear structure and to allow us to better |
| 116 |
review your work. |
| 117 |
|
| 118 |
.. note:: |
| 119 |
|
| 120 |
Your work is important and must be signed to ensure the integrity of |
| 121 |
the repository and the code. Thus, we recommend setting up a signing key |
| 122 |
as documented in :ref:`Signing_Git_Patches`. |
| 123 |
|
| 124 |
.. code:: shell-session |
| 125 |
|
| 126 |
$ git commit -S -a |
| 127 |
|
| 128 |
Once everything is done, push your local branch to your forked repository and |
| 129 |
create a pull request into the upstream repository. |
| 130 |
|
| 131 |
.. code:: shell-session |
| 132 |
|
| 133 |
$ git push origin my-topic-branch |
| 134 |
|
| 135 |
Thank you much for contributing to {kiwi}. Your time and work effort are very |
| 136 |
much appreciated! |
| 137 |
|
| 138 |
AI policy |
| 139 |
--------- |
| 140 |
|
| 141 |
{kiwi} has a policy of human-centric development. Only humans can be authors |
| 142 |
and are ultimately responsible for the quality of their contributions. |
| 143 |
That said, assisted development with "AI" tools (particularly contemporary |
| 144 |
LLM-based tools) is permitted with the restriction that such usage is clearly |
| 145 |
labeled with the `Assisted-by:` trailer in the pull request and commit message. |
| 146 |
The format of the trailer is as such: `Assisted-by: <Tool>:<model-id>`. |
| 147 |
|
| 148 |
Examples of such trailers: |
| 149 |
|
| 150 |
+----------------+---------------------------------------+ |
| 151 |
| Tool | Trailer | |
| 152 |
+================+=======================================+ |
| 153 |
| Claude | `Assisted-by: Claude:claude-opus-4-6` | |
| 154 |
| Gemini | `Assisted-by: Gemini:gemini-2.5-pro` | |
| 155 |
| GitHub Copilot | `Assisted-by: Copilot:gpt-4o` | |
| 156 |
| ChatGPT | `Assisted-by: ChatGPT:gpt-4o` | |
| 157 |
+----------------+---------------------------------------+ |
| 158 |
|
| 159 |
The trailers are required for the following scenarios: |
| 160 |
|
| 161 |
- AI wrote or generated code that ended up in the commit |
| 162 |
- AI substantially modified or refactored existing code |
| 163 |
- AI generated an implementation that the contributor then adapted |
| 164 |
|
| 165 |
It is **not** required for the following scenarios: |
| 166 |
|
| 167 |
- AI was used for **research only** - asking questions, understanding APIs, |
| 168 |
exploring approaches - but the human wrote all the code |
| 169 |
- AI performed purely **mechanical tasks** like formatting, running commands, |
| 170 |
or committing |
| 171 |
|
| 172 |
All submitted changes must be at least self-reviewed and all other guidelines |
| 173 |
continue to apply (follow code style, pass tests, make tests for new functionality, |
| 174 |
etc.) |
| 175 |
|
| 176 |
Intentional obfuscation of AI tooling usage is grounds for rejection and may result |
| 177 |
in being blocked from future contributions. |
| 178 |
|
| 179 |
Coding Style |
| 180 |
------------ |
| 181 |
|
| 182 |
{kiwi} follows the general PEP8 guidelines with the following exceptions: |
| 183 |
|
| 184 |
- We do not use free functions at all. Even utility functions must be part |
| 185 |
of a class but should be either prefixed with the `@classmethod` or |
| 186 |
`@staticmethod` decorators (whichever is more appropriate). |
| 187 |
|
| 188 |
- Do not set module and class-level variables; put these into the class's |
| 189 |
`__init__` method. |
| 190 |
|
| 191 |
Documentation |
| 192 |
~~~~~~~~~~~~~ |
| 193 |
|
| 194 |
{kiwi} uses `Sphinx <https://www.sphinx-doc.org/en/master/>`_ for the API, |
| 195 |
user documentation, and man pages. |
| 196 |
|
| 197 |
.. code:: shell-session |
| 198 |
|
| 199 |
$ make docs |
| 200 |
|
| 201 |
API documentation is created from type hints. Even though python is |
| 202 |
not a strong typed language we value if all parameters and return |
| 203 |
values uses proper type hints. |
| 204 |
|
| 205 |
.. code:: python |
| 206 |
|
| 207 |
class Example: |
| 208 |
""" |
| 209 |
**Example class** |
| 210 |
|
| 211 |
This class has a single responsibility and provides... |
| 212 |
""" |
| 213 |
def __init__(self, names: List[str], set_names: bool = False): |
| 214 |
""" |
| 215 |
Initialize instance of Example with a list of some |
| 216 |
example names. If param_w_default is set to True the |
| 217 |
instance is initialized with an empty name list |
| 218 |
""" |
| 219 |
self.some_names = names if set_names else [] |
| 220 |
|
| 221 |
def is_retired(self, age: int = 0) -> bool: |
| 222 |
""" |
| 223 |
A method that implements... |
| 224 |
""" |
| 225 |
return len(age) > 70 |
| 226 |
|
| 227 |
Try to stick to the following guidelines when documenting source code: |
| 228 |
|
| 229 |
- Classes should be documented directly in their main docstring and not in |
| 230 |
`__init__`. |
| 231 |
|
| 232 |
- Document function parameters unless their name makes it clear |
| 233 |
|
| 234 |
- Only public methods should be documented; private methods don't have to be, |
| 235 |
unless they are complex and it is not easy to grasp what they do (which |
| 236 |
should be avoided anyway). |
| 237 |
|
| 238 |
Please also document any user-facing changes that you are implementing |
| 239 |
(e.g., adding a new build type) in the user documentation, which can be |
| 240 |
found in `doc/source`. |
| 241 |
|
| 242 |
Additional Information |
| 243 |
---------------------- |
| 244 |
|
| 245 |
The following sections provide further information about the repository |
| 246 |
integrity, version, package, and documentation management. |
| 247 |
|
| 248 |
.. _Signing_Git_Patches: |
| 249 |
|
| 250 |
Signing Git Patches |
| 251 |
~~~~~~~~~~~~~~~~~~~ |
| 252 |
|
| 253 |
To ensure the integrity of the repository and the codebase, patches sent |
| 254 |
for inclusion should be signed with a GPG key. |
| 255 |
|
| 256 |
To prepare Git to sign commits, follow these instructions: |
| 257 |
|
| 258 |
#. Create a key suitable for signing (it is not recommended to use |
| 259 |
existing keys to not mix it with your email environment): |
| 260 |
|
| 261 |
.. code:: shell-session |
| 262 |
|
| 263 |
$ gpg2 --expert --full-gen-key |
| 264 |
|
| 265 |
#. Either choose an RSA key for signing (option `(4)`) or an ECC key for |
| 266 |
signing (option `(10)`). For an RSA key, choose a key size of 4096 bits, |
| 267 |
and for an ECC key, choose Curve 25519 (option `(1)`). Enter a reasonable |
| 268 |
validity period (we recommend 2 to 5 years). Complete the key generation |
| 269 |
by entering your name and email address. |
| 270 |
|
| 271 |
#. Add the key ID to your git configuration by running the following |
| 272 |
:command:`git config` commands: |
| 273 |
|
| 274 |
.. code:: shell-session |
| 275 |
|
| 276 |
$ git config --local user.signingkey $YOUR_SIGN_KEY_ID |
| 277 |
$ git config --local commit.gpgSign true |
| 278 |
|
| 279 |
Omitting the `--local` flag will make these settings global for all |
| 280 |
repositories (they will be added to :file:`~/.gitconfig`). You can find |
| 281 |
your signkey's ID via: |
| 282 |
|
| 283 |
.. code:: shell-session |
| 284 |
|
| 285 |
$ gpg2 --list-keys --keyid-format long $YOUR_EMAIL |
| 286 |
pub rsa4096/AABBCCDDEEFF0011 2019-04-26 [S] [expires: 2021-04-16] |
| 287 |
AAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBB |
| 288 |
uid [ultimate] YOU <$YOUR_EMAIL> |
| 289 |
|
| 290 |
The key's ID in this case would be `AABBCCDDEEFF0011`. Note that your |
| 291 |
sign key will have only a `[S]` after the creation date, not a `[SC]` |
| 292 |
(then you are looking at your ordinary GPG key that can also encrypt). |
| 293 |
|
| 294 |
Bumping the Version |
| 295 |
~~~~~~~~~~~~~~~~~~~ |
| 296 |
|
| 297 |
The {kiwi} project follows the `Semantic Versioning <https://semver.org>`_ |
| 298 |
scheme. We use the :command:`bumpversion` tool for consistent versioning. |
| 299 |
|
| 300 |
Follow these instructions to bump the major, minor, or patch part of the |
| 301 |
{kiwi} version. Ensure that your repository is clean (i.e., no modified and |
| 302 |
unknown files exist) before running :command:`bumpversion`. |
| 303 |
|
| 304 |
* For backward-compatible bug fixes: |
| 305 |
|
| 306 |
.. code:: shell-session |
| 307 |
|
| 308 |
$ bumpversion patch |
| 309 |
|
| 310 |
* For additional functionality in a backward-compatible manner. When |
| 311 |
changed, the patch level is reset to zero: |
| 312 |
|
| 313 |
.. code:: shell-session |
| 314 |
|
| 315 |
$ bumpversion minor |
| 316 |
|
| 317 |
* For incompatible API changes. When changed, the patch and minor |
| 318 |
levels are reset to zero: |
| 319 |
|
| 320 |
.. code:: shell-session |
| 321 |
|
| 322 |
$ bumpversion major |
| 323 |
|
| 324 |
Creating an RPM Package |
| 325 |
~~~~~~~~~~~~~~~~~~~~~~~ |
| 326 |
|
| 327 |
We provide a template for an RPM spec file in |
| 328 |
:file:`package/python-kiwi-spec-template` alongside a `rpmlint` |
| 329 |
configuration file and an automatically updated |
| 330 |
:file:`python-kiwi.changes`. |
| 331 |
|
| 332 |
To create the necessary files to build an RPM package via `rpmbuild`, run: |
| 333 |
|
| 334 |
.. code:: shell-session |
| 335 |
|
| 336 |
$ make build |
| 337 |
|
| 338 |
The sources are collected in the :file:`dist/` directory. These can be |
| 339 |
directly built with :command:`rpmbuild`, :command:`fedpkg`, or submitted |
| 340 |
to the Open Build Service using :command:`osc`. |