From 8a81ba50e05ea0df65678a56e4876e7516a0e19f Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Sat, 8 Feb 2025 21:05:51 +0100 Subject: [PATCH] align linting and formating with netbox --- .pre-commit-config.yaml | 50 ++++++++++++++++++----------------------- CONTRIBUTING.md | 20 ++++++++--------- ruff.toml | 12 ++++++++++ 3 files changed, 43 insertions(+), 39 deletions(-) create mode 100644 ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f8cbd72..c210d6d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,29 +1,23 @@ -ci: - autoupdate_commit_msg: "chore: update pre-commit hooks" - autofix_commit_msg: "style: pre-commit fixes" - repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: double-quote-string-fixer -- repo: https://github.com/psf/black - rev: 24.3.0 - hooks: - - id: black - args: [--line-length=120] - language_version: python3 -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort -- repo: https://github.com/pycqa/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - -- repo: https://github.com/mgedmin/check-manifest - rev: "0.49" - hooks: - - id: check-manifest - stages: [manual] +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.9 + hooks: + - id: ruff + name: "Ruff linter" + args: [ src/netbox_contract/ ] +- repo: local + hooks: + - id: django-check + name: "Django system check" + description: "Run Django's internal check for common problems" + entry: python ../netbox/netbox/manage.py check + language: system + pass_filenames: false + types: [python] + - id: django-makemigrations + name: "Django migrations check" + description: "Check for any missing Django migrations" + entry: python ../netbox/netbox/manage.py makemigrations --check + language: system + pass_filenames: false + types: [python] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4f2baed..beb502b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,20 +20,18 @@ and "help wanted" is open to whoever wants to implement it. ## Coding conventions -Netbox [Style Guide](https://docs.netbox.dev/en/stable/development/style-guide/) -Django [Coding style](https://docs.djangoproject.com/en/4.2/internals/contributing/writing-code/coding-style/) +Netbox [Style Guide](https://netboxlabs.com/docs/netbox/en/stable/development/style-guide/) +Django [Coding style](https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/coding-style/) -For this: -All files will be formated using the [black](https://black.readthedocs.io/en/stable/) auto-formatter. -Configuration is stored in pyproject.toml +## linting -[isort](https://github.com/PyCQA/isort#readme) is used to automate import sorting. +The [ruff](https://docs.astral.sh/ruff/) linter is used to enforce code style. A [pre-commit hook](./getting-started.md#3-enable-pre-commit-hooks) which runs this automatically is included with NetBox. To invoke `ruff` manually, run: + +``` +python3 -m pip install ruff +ruff check src/netbox_contract/ +``` -Linting and PEP8 style enforcement will be done with [Flake8](https://flake8.pycqa.org/en/latest/) which is a wrapper arround: -- PyFlakes -- pycodestyle -- Ned Batchelder’s McCabe script -Configuration is maintained in the .flake8 file (no support for pyproject.toml) The pre-commit Python framework is used to simplify the managment of pre-commit hooks. Config is stored in .pre-commit-config.yaml diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..8f6d69c --- /dev/null +++ b/ruff.toml @@ -0,0 +1,12 @@ +exclude = [ + "netbox/project-static/**" +] +line-length = 120 + +[lint] +extend-select = ["E1", "E2", "E3", "E501", "W"] +ignore = ["F403", "F405"] +preview = true + +[format] +quote-style = "single" \ No newline at end of file