Debian Codegraph @

doc/source/contributing.rst

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