Skip to content

Commit

Permalink
align linting and formating with netbox
Browse files Browse the repository at this point in the history
  • Loading branch information
mlebreuil committed Feb 8, 2025
1 parent cab25f2 commit 8a81ba5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 39 deletions.
50 changes: 22 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
20 changes: 9 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8a81ba5

Please sign in to comment.