From: Alexey ALERT Rubashёff Date: Thu, 15 Jan 2026 08:03:13 +0000 (+0200) Subject: Make pre-commit configuration cross-platform compatible using uv (#2971) X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=acf3a1382b173521e87796fad1915370854dda46;p=music-assistant-server.git Make pre-commit configuration cross-platform compatible using uv (#2971) chore: update pre-commit hooks and enforce LF line endings - Add configuration to enforce LF line endings for all text files. - Update pre-commit hooks to use `uv run` instead of `scripts/run-in-env.sh` and reorder `gen_requirements_all` to run first. - Uses LF line endings in gen_requirements_all. --- diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8dc92787 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Force LF line endings for all text files +* text=auto eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c9d83886..3e4b0d4a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,102 +1,119 @@ -repos: - - repo: local - hooks: - - id: ruff-check - name: 🐶 Ruff Linter - language: system - types: [python] - entry: scripts/run-in-env.sh ruff check --fix - require_serial: true - stages: [pre-commit, pre-push, manual] - - id: ruff-format - name: 🐶 Ruff Formatter - language: system - types: [python] - entry: scripts/run-in-env.sh ruff format - require_serial: true - stages: [pre-commit, pre-push, manual] - - id: check-ast - name: 🐍 Check Python AST - language: system - types: [python] - entry: scripts/run-in-env.sh check-ast - - id: check-case-conflict - name: 🔠 Check for case conflicts - language: system - entry: scripts/run-in-env.sh check-case-conflict - - id: check-docstring-first - name: ℹ️ Check docstring is first - language: system - types: [python] - entry: scripts/run-in-env.sh check-docstring-first - - id: check-executables-have-shebangs - name: 🧐 Check that executables have shebangs - language: system - types: [text, executable] - entry: scripts/run-in-env.sh check-executables-have-shebangs - stages: [pre-commit, pre-push, manual] - - id: check-json - name: { Check JSON files - language: system - types: [json] - entry: scripts/run-in-env.sh check-json - files: ^(music_assistant/.+/manifest\.json)|(tests/providers/.+/fixtures/.+\.json)$ - - id: check-merge-conflict - name: 💥 Check for merge conflicts - language: system - types: [text] - entry: scripts/run-in-env.sh check-merge-conflict - - id: check-symlinks - name: 🔗 Check for broken symlinks - language: system - types: [symlink] - entry: scripts/run-in-env.sh check-symlinks - - id: check-toml - name: ✅ Check TOML files - language: system - types: [toml] - entry: scripts/run-in-env.sh check-toml - - id: codespell - name: ✅ Check code for common misspellings - language: system - types: [text] - entry: scripts/run-in-env.sh codespell - - id: detect-private-key - name: 🕵️ Detect Private Keys - language: system - types: [text] - entry: scripts/run-in-env.sh detect-private-key - - id: end-of-file-fixer - name: ⮐ Fix End of Files - language: system - types: [text] - entry: scripts/run-in-env.sh end-of-file-fixer - stages: [pre-commit, pre-push, manual] - - id: no-commit-to-branch - name: 🛑 Don't commit to stable branch - language: system - entry: scripts/run-in-env.sh no-commit-to-branch - pass_filenames: false - always_run: true - args: - - --branch=stable - - id: trailing-whitespace - name: ✄ Trim Trailing Whitespace - language: system - types: [text] - entry: scripts/run-in-env.sh trailing-whitespace-fixer - stages: [pre-commit, pre-push, manual] - - id: mypy - name: mypy - entry: scripts/run-in-env.sh mypy - language: script - types: [python] - require_serial: true - pass_filenames: false - - id: gen_requirements_all - name: gen_requirements_all - entry: scripts/run-in-env.sh python3 -m scripts.gen_requirements_all - pass_filenames: false - language: script - types: [text] - files: ^(music_assistant/.+/manifest\.json|pyproject\.toml|\.pre-commit-config\.yaml|scripts/gen_requirements_all\.py)$ +repos: + - repo: local + hooks: + # gen_requirements_all modifies files so it has to be first + - id: gen_requirements_all + name: gen_requirements_all + entry: uv run -m scripts.gen_requirements_all + pass_filenames: false + language: system + types: [text] + files: ^(music_assistant/.+/manifest\.json|pyproject\.toml|\.pre-commit-config\.yaml|scripts/gen_requirements_all\.py)$ + + - id: ruff-check + name: 🐶 Ruff Linter + language: system + types: [python] + entry: uv run ruff check --fix + require_serial: true + stages: [pre-commit, pre-push, manual] + + - id: ruff-format + name: 🐶 Ruff Formatter + language: system + types: [python] + entry: uv run ruff format + require_serial: true + stages: [pre-commit, pre-push, manual] + + - id: check-ast + name: 🐍 Check Python AST + language: system + types: [python] + entry: uv run check-ast + + - id: check-case-conflict + name: 🔠 Check for case conflicts + language: system + entry: uv run check-case-conflict + + - id: check-docstring-first + name: ℹ️ Check docstring is first + language: system + types: [python] + entry: uv run check-docstring-first + + - id: check-executables-have-shebangs + name: 🧐 Check that executables have shebangs + language: system + types: [text, executable] + entry: uv run check-executables-have-shebangs + stages: [pre-commit, pre-push, manual] + + - id: check-json + name: { Check JSON files + language: system + types: [json] + entry: uv run check-json + files: ^(music_assistant/.+/manifest\.json)|(tests/providers/.+/fixtures/.+\.json)$ + + - id: check-merge-conflict + name: 💥 Check for merge conflicts + language: system + types: [text] + entry: uv run check-merge-conflict + + - id: check-symlinks + name: 🔗 Check for broken symlinks + language: system + types: [symlink] + entry: uv run check-symlinks + + - id: check-toml + name: ✅ Check TOML files + language: system + types: [toml] + entry: uv run check-toml + + - id: codespell + name: ✅ Check code for common misspellings + language: system + types: [text] + entry: uv run codespell + + - id: detect-private-key + name: 🕵️ Detect Private Keys + language: system + types: [text] + entry: uv run detect-private-key + + - id: end-of-file-fixer + name: ⮐ Fix End of Files + language: system + types: [text] + entry: uv run end-of-file-fixer + stages: [pre-commit, pre-push, manual] + + - id: no-commit-to-branch + name: 🛑 Don't commit to stable branch + language: system + entry: uv run no-commit-to-branch + pass_filenames: false + always_run: true + args: + - --branch=stable + + - id: trailing-whitespace + name: ✄ Trim Trailing Whitespace + language: system + types: [text] + entry: uv run trailing-whitespace-fixer + stages: [pre-commit, pre-push, manual] + + - id: mypy + name: mypy + entry: uv run mypy + language: system + types: [python] + require_serial: true + pass_filenames: false diff --git a/scripts/gen_requirements_all.py b/scripts/gen_requirements_all.py index c5b23a22..ec9c5227 100644 --- a/scripts/gen_requirements_all.py +++ b/scripts/gen_requirements_all.py @@ -80,7 +80,8 @@ def main() -> int: for req_key in sorted(final_requirements): req_str = final_requirements[req_key] content += f"{req_str}\n" - Path("requirements_all.txt").write_text(content) + # Always use LF line endings for cross-platform compatibility + Path("requirements_all.txt").write_text(content, newline="\n") return 0