]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
docs: add CODING_STYLE.md 3480/head
authorJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 6 Feb 2025 15:06:23 +0000 (16:06 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Fri, 7 Feb 2025 09:02:19 +0000 (10:02 +0100)
docs/CODING_STYLE.md [new file with mode: 0644]

diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md
new file mode 100644 (file)
index 0000000..ea7b7f9
--- /dev/null
@@ -0,0 +1,40 @@
+---
+title: Coding Style
+category: Contributing
+layout: default
+SPDX-License-Identifier: LGPL-2.1-or-later
+---
+
+# Coding Style
+
+## Python Version
+
+- The lowest supported Python version is CPython 3.9.
+
+## Formatting
+
+- Use the accompanying `.editorconfig` or `.dir-locals.el`.
+- For Python files we use the style from `ruff format` with a line length of 109 characters and four spaces
+  indentation.
+- Indentation with tabs is not allowed.
+- When it improves readability, judicious use of `# noqa: E501` comments is allowed.
+- Long lists, including argument lists, should have a trailing comma to force ruff to split all elements on a
+  line of their own.
+- List of commandline arguments should not split the argument of a commandline option and the option. This
+  needs to be enforced with `# fmt: skip` comments, e.g. do
+  ```python
+  cmd = [
+      "--option", "foo",
+  ]  # fmt: skip
+  ```
+  and do NOT do
+  ```python
+  cmd = [
+      "--option",
+      "foo",
+  ]
+  ```
+- When coercing Path-like objects to strings, use `os.fspath`, since this calls the `__fspath__` protocol
+  instead of `__str__`. It also ensures more type-safety, since every Python object supports `__str__`, but
+  not all support `__fspath__` and this gives the typechecker more information what is expected at this
+  point. It also signals the intent to the reader more than a blanket `str()`.