diff --git a/.github/workflows/file_format.py b/.github/workflows/file_format.py new file mode 100755 index 0000000..d74589c --- /dev/null +++ b/.github/workflows/file_format.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys + +if len(sys.argv) < 2: + print("Invalid usage of file_format.py, it should be called with a path to one or multiple files.") + sys.exit(1) + +BOM = b"\xef\xbb\xbf" + +changed = [] +invalid = [] + +for file in sys.argv[1:]: + try: + with open(file, "rt", encoding="utf-8") as f: + original = f.read() + except UnicodeDecodeError: + invalid.append(file) + continue + + if original == "": + continue + + EOL = "\n" + revamp = EOL.join([line.rstrip("\n\r\t ") for line in original.splitlines(True)]).rstrip(EOL) + EOL + + new_raw = revamp.encode(encoding="utf-8") + if new_raw.startswith(BOM): + new_raw = new_raw[len(BOM) :] + + with open(file, "rb") as f: + old_raw = f.read() + + if old_raw != new_raw: + changed.append(file) + with open(file, "wb") as f: + f.write(new_raw) + +if changed: + for file in changed: + print(f"FIXED: {file}") + +if invalid: + for file in invalid: + print(f"REQUIRES MANUAL CHANGES: {file}") + sys.exit(1) diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml new file mode 100644 index 0000000..f84b8eb --- /dev/null +++ b/.github/workflows/static_checks.yml @@ -0,0 +1,33 @@ +name: 📊 Static Checks +on: [push, pull_request] + +concurrency: + group: ci-${{ github.actor }}-${{ github.head_ref || github.run_number }}-${{ github.ref }}-static + +jobs: + static-checks: + name: Code style and file formatting + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Install APT dependencies + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libxml2-utils + + - name: Install Python dependencies and general setup + run: | + git config diff.wsErrorHighlight all + + - name: Style checks via pre-commit + uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files + + - name: XML validation via xmllint + run: | + xmllint --noout warehouse.doap data/io.github.flattool.Warehouse.gschema.xml data/io.github.flattool.Warehouse.metainfo.xml.in src/warehouse.gresource.xml diff --git a/.gitignore b/.gitignore index 33951cd..fc04db3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /subprojects/blueprint-compiler +.DS_Store .flatpak .flatpak-builder +.idea/ +.ruff_cache/ .vscode -.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d86859a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +default_language_version: + python: python3 + +exclude: | + (?x)^( + CODE_OF_CONDUCT.md + ) + +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.6 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + exclude: | + (?x)^( + .*\.po$ + ) + additional_dependencies: [tomli] + + - repo: local + hooks: + - id: file-format + name: file-format + language: python + entry: python .github/workflows/file_format.py + types_or: [text] diff --git a/README.md b/README.md index 9bc50fe..17e26b6 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,18 @@ You're all set! Launch the application by clicking its icon in your app menu or ```shell flatpak run io.github.flattool.Warehouse ``` + +## 👥 Contributing + +### Compiling from Source + +TODO + +### Formatting + +Warehouse uses [pre-commit](https://pre-commit.com/) for code formatting. +- Install using `pip install pre-commit` +- Run `pre-commit install` in the Warehouse repository root to set up pre-commit for this repo. +- Run `pre-commit run --all-files` to format all files in the repository. + +If you run into a situation where pre-commit is broken, you can use `git commit --no-verfiy` to skip the pre-commit checks. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..afa5c86 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.ruff] +line-length = 160 + +[tool.ruff.format] +indent-style = "tab" + +[tool.ruff.lint] +ignore = [ + "E401", # Allow multiple imports on one line. + "E402", # Module level import not at top of file (invalid for warehouse because we need gi.require_version above some imports). + "E713", # Test for membership does not have to be "not in". + "E714", # Test for object identity does not have to be "is not". + "F401", # Don't delete unused imports. + "F821", # Undefined name (underscore for translations). +] + +[tool.codespell] +skip = """\ + CODE_OF_CONDUCT.md, + *.po +"""