From 751d5b16a9334a679866dd4979dc48cebcbbe415 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 02:13:11 +0100 Subject: [PATCH] Document contributor conventions and add Gitea CI --- .editorconfig | 18 ++++++++++++ .gitattributes | 1 + .gitea/workflows/ci.yml | 53 +++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 61 +++++++++++++++++++++++++++++++++++++++++ docs/development.md | 6 ++++ 5 files changed, 139 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitea/workflows/ci.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7700102 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[*.py] +max_line_length = 79 + +[*.{yml,yaml}] +indent_size = 2 + +[deploy/dovecot/*.conf.example] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..1bf9ee7 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,53 @@ +name: Coulobre Panel CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +permissions: + contents: read + +jobs: + checks: + name: Checks (Python ${{ matrix.python-version }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.12", "3.14"] + env: + COULOBRE_SECRET_KEY: ci-test-only + steps: + - name: Check out source + uses: https://github.com/actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + with: + persist-credentials: false + + - name: Set up Python + uses: https://github.com/actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Install development dependencies + run: python -m pip install -e '.[dev]' + + - name: Install Zstandard for backup fixtures + run: | + sudo apt-get update + sudo apt-get install --yes --no-install-recommends zstd + + - name: Check Python style and shell syntax + run: | + ruff check . + ruff format --check . + sh -n tests/web-node/smoke.sh + + - name: Check Django configuration and migrations + run: | + python manage.py check + python manage.py makemigrations --check --dry-run + + - name: Run tests + run: python manage.py test coulobre diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7167387..3478a7d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,3 +7,64 @@ - Submit changes for review before merging into main. - Write code, comments, technical documentation, and commit messages in English. - Keep credentials, customer data, and local configuration out of commits. + +## Code style + +- Follow PEP 8 with four spaces per indentation level, up to 79 characters + per line of Python, and up to 72 for comments and docstrings. Ruff formats + Python, sorts imports, and checks naming and common mistakes using the + project's Python target. [PEP 8](https://peps.python.org/pep-0008/) +- Use names from the hosting domain, such as `account`, `mailbox`, and + `zone`. Use verbs for actions and name tests after the behavior they + check, such as `test_unmanaged_running_zone_blocks_installation`. +- Explain why a constraint, permission check, or retry exists when the + code alone cannot explain it. Use PEP 257 for docstrings. Document + inputs, results, or side effects when callers need that information. + [PEP 257](https://peps.python.org/pep-0257/) +- Define model fields and managers first, then `Meta`, special methods, + and application methods. Give records displayed to users a meaningful + string representation. Generate a new migration when the schema + changes and review the generated operations. + [Django model style](https://docs.djangoproject.com/en/5.2/internals/contributing/writing-code/coding-style/#model-style) +- Use UTF-8 and LF line endings. Match the EditorConfig indentation for + each file type and follow the enclosing format in service configuration + and deployment examples. [EditorConfig](.editorconfig) + +## Code organization + +- Keep HTTP handling in views and input validation in forms or existing + domain objects. Use the access helpers for tenant scoping and enforce + permissions in the view. Put related writes and quota checks in a + service function with a transaction. + [Access helpers](src/coulobre/hosting/access.py), + [resource requests](src/coulobre/hosting/resource_requests.py) +- Coordinate background provisioning in tasks and contact local services + through the node client. Keep privileged changes in node commands. + Keep manifests compatible with existing nodes and make provisioning + safe to retry with the same request. + [Provisioning tasks](src/coulobre/hosting/tasks.py), + [node client](src/coulobre/hosting/node_client.py) +- Follow the closest existing implementation when extending a resource. + Reuse an existing helper when it already owns the validation or policy. + Extract shared code when the callers genuinely share behavior. +- Test through the entry point the caller uses. Follow neighboring + `test_*.py` modules and cover relevant permission boundaries or retries + when changing those behaviors. + +## Panel copy and templates + +- Use plain English and the same names for resources throughout the + interface. Write button labels as short actions in sentence case, such + as **Request mailbox** or **Publish zone**. +- Tell the reader what happened and, where they can act, what to do next. + For example, “This zone changed before publication. Reload the account + and try again.” Keep credentials and raw service output out of messages + shown in the panel. +- Reuse existing templates and styles for controls, focus states, and + status labels. Keep form inputs labelled and validation errors close to + the field that needs attention. + +## Checks + +Run the development checks before submitting a pull request. Gitea Actions +checks Python 3.12 and 3.14. [Development checks](docs/development.md#checks) diff --git a/docs/development.md b/docs/development.md index 9eb7d8e..560328e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -712,9 +712,15 @@ database and rerun `python manage.py migrate`. Set `COULOBRE_DB_HOST` and ## Checks +Install the `dev` extra and set `COULOBRE_SECRET_KEY` as described above. +Use `ruff check --fix .` to apply safe lint fixes and `ruff format .` to +format Python. Install the `zstd` command to exercise compressed backup +fixtures. Then run the checks from the repository root. + ```sh ruff check . ruff format --check . +sh -n tests/web-node/smoke.sh python manage.py check python manage.py makemigrations --check --dry-run python manage.py test coulobre