Skip to content

Commit

Permalink
Merge pull request #44 from lkubb/pre-commit-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb authored Aug 29, 2024
2 parents 181223d + 69d8b76 commit a4b587a
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 177 deletions.
1 change: 1 addition & 0 deletions changelog/+m.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made merge conflict pre-commit hook always run
1 change: 1 addition & 0 deletions changelog/+n.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed nox pre-commit hook to local hook, added support for recent nox versions
1 change: 1 addition & 0 deletions changelog/+p.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated pre-commit hook versions
1 change: 1 addition & 0 deletions changelog/+pinpylint.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pinned pylint version used for linting
1 change: 1 addition & 0 deletions changelog/+pylintconf.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated pylint configuration
1 change: 1 addition & 0 deletions changelog/+pylintpy.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensured pylint lints against the minimum required Python version
1 change: 1 addition & 0 deletions changelog/+relaxpylint.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `relax_pylint` question to suppress some annoying messages, especially with legacy code
1 change: 1 addition & 0 deletions changelog/+saltpylint.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed unused saltpylint dependency
1 change: 1 addition & 0 deletions changelog/+sess.removed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed unnecessary `docs-html` and `gen-api-docs` nox sessions
1 change: 1 addition & 0 deletions changelog/+strictpylint.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased default pylint strictness
1 change: 1 addition & 0 deletions changelog/+uv.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switched nox venv backend to uv, which reduced the time for pre-commit linting and other nox sessions significantly
5 changes: 5 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ copyright_begin:
# Cannot use when: false to set this once automatically during
# creation since the value is not recorded then.

relax_pylint:
type: bool
help: Suppress some Pylint messages that can cause noise or be difficult to solve with legacy code.
default: false

# ===========================================
# | Computed values for less ugly templates |
# ===========================================
Expand Down
12 changes: 12 additions & 0 deletions docs/ref/questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,15 @@ A contact email for Code of Conduct complaints.
The starting year of the copyright range.

**Example**: `2024`

:::{question} relax_pylint
:::
## `relax_pylint`
Suppress some Pylint messages that can cause noise (`consider-using-f-string`)
or be time-intense (`too-many-*`) or difficult
(`redefined-builtin`, `redefined-outer-name`) to solve with legacy code.

Additionally suppresses `unused-argument` in the test suite, often caused
by requesting fixtures in the function signature instead of using
`@pytest.mark.usefixtures`. Note that the decorator does not work on
fixtures requesting other fixtures.
50 changes: 25 additions & 25 deletions project/.pre-commit-config.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict # Check for files that contain merge conflict strings.
- id: trailing-whitespace # Trims trailing whitespace.
- id: check-merge-conflict # Check for files that contain merge conflict strings.
args: [--assume-in-merge]
- id: trailing-whitespace # Trim trailing whitespace.
args: [--markdown-linebreak-ext=md]
- id: mixed-line-ending # Replaces or checks mixed line ending.
- id: mixed-line-ending # Ensure files use UNIX-style newlines only.
args: [--fix=lf]
- id: end-of-file-fixer # Makes sure files end in a newline and only a newline.
- id: check-ast # Simply check whether files parse as valid python.
- id: end-of-file-fixer # Ensure files end with a newline.
- id: check-ast # Check whether files parse as valid Python.

# ----- Formatting ---------------------------------------------------------------------------->
- repo: https://github.com/saltstack/pre-commit-remove-import-headers
Expand All @@ -23,15 +24,15 @@ repos:
- id: check-cli-examples
name: Check CLI examples on execution modules
entry: python .pre-commit-hooks/check-cli-examples.py
language: system
language: python
files: ^src/{{ namespaced_package_path }}/modules/.*\.py$

- repo: local
hooks:
- id: check-docs
name: Check rST doc files exist for modules/states
entry: python .pre-commit-hooks/make-autodocs.py
language: system
language: python
pass_filenames: false

- repo: https://github.com/s0undt3ch/salt-rewrite
Expand All @@ -55,7 +56,7 @@ repos:
args: [--silent, -E, fix_docstrings]

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.16.0
hooks:
- id: pyupgrade
name: Rewrite Code to be Py{{ python_requires[:2] | join(".") }}+
Expand All @@ -74,14 +75,14 @@ repos:
exclude: src/{{ namespaced_package_path }}/(__init__|version).py

- repo: https://github.com/psf/black
rev: 24.2.0
rev: 24.8.0
hooks:
- id: black
args: [-l 100]
exclude: src/{{ namespaced_package_path }}/version.py

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: 1.18.0
hooks:
- id: blacken-docs
args: [--skip-errors]
Expand All @@ -92,15 +93,15 @@ repos:

# ----- Security ------------------------------------------------------------------------------>
- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
rev: 1.7.9
hooks:
- id: bandit
alias: bandit-salt
name: Run bandit against the code base
args: [--silent, -lll, --skip, B701]
exclude: src/{{ namespaced_package_path }}/version.py
- repo: https://github.com/PyCQA/bandit
rev: 1.7.8
rev: 1.7.9
hooks:
- id: bandit
alias: bandit-tests
Expand All @@ -110,31 +111,30 @@ repos:
# <---- Security -------------------------------------------------------------------------------

# ----- Code Analysis ------------------------------------------------------------------------->
- repo: https://github.com/saltstack/mirrors-nox
rev: v2022.11.21

- repo: local
hooks:
- id: nox
alias: lint-src
name: Lint Source Code
language: python
entry: nox -e lint-code-pre-commit --
files: ^((setup|noxfile)|src/.*)\.py$
require_serial: true
args:
- -e
- lint-code-pre-commit
- --
additional_dependencies:
- nox==2024.4.15
- uv==0.4.0 # Makes this hook much faster

- repo: https://github.com/saltstack/mirrors-nox
rev: v2022.11.21
hooks:
- id: nox
alias: lint-tests
name: Lint Tests
language: python
entry: nox -e lint-tests-pre-commit --
files: ^tests/.*\.py$
require_serial: true
args:
- -e
- lint-tests-pre-commit
- --
additional_dependencies:
- nox==2024.4.15
- uv==0.4.0 # Makes this hook much faster

{%- if "github.com" in source_url %}

Expand Down
Loading

0 comments on commit a4b587a

Please sign in to comment.