Skip to content

Commit

Permalink
Add pyproject-fmt to quality tools.
Browse files Browse the repository at this point in the history
Closes #8928.
  • Loading branch information
fniessink committed Jun 13, 2024
1 parent 321f2ef commit 051e2cc
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 68 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ jobs:
ci/unittest.sh
ci/quality.sh
unittest_release:
machine:
image: default
steps:
- checkout
- run: |
cd release
python3 -m venv venv
. venv/bin/activate
ci/pip-install.sh
ci/quality.sh
application_tests:
machine:
image: default
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/release-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release script quality

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
cd release
ci/pip-install.sh
- name: Quality
run: |
cd release
ci/quality.sh
8 changes: 7 additions & 1 deletion docs/ci/quality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ run pipx install --force `spec mypy` # --force works around this bug: https://g
run pipx inject mypy `spec pydantic`
run $PIPX_BIN_DIR/mypy src --python-executable=$(which python)

# Pyproject-fmt
run pipx run `spec pyproject-fmt` --check pyproject.toml

# Vale
run pipx run `spec vale` sync
run pipx run `spec vale` --no-wrap src/*.md
Expand All @@ -26,7 +29,10 @@ run pipx run `spec vale` --no-wrap src/*.md
run pipx run `spec pip-audit` --strict --progress-spinner=off -r requirements/requirements.txt -r requirements/requirements-dev.txt

# Safety
run pipx run `spec bandit` --quiet --recursive src/
run pipx run `spec safety` check --bare -r requirements/requirements.txt -r requirements/requirements-dev.txt

# Bandit
run pipx run `spec bandit` --configfile pyproject.toml --quiet --recursive src/

# Vulture
run pipx run `spec vulture` --min-confidence 0 src/ tests/ .vulture_ignore_list.py
124 changes: 72 additions & 52 deletions docs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,96 @@
[project]
name = "docs"
version = "5.13.0"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"furo==2023.9.10",
"gitpython==3.1.43",
"myst-parser==2.0.0",
"pydantic==2.7.4", # Needed for generating the reference docs from the data model
"Sphinx==7.2.6",
"pydantic==2.7.4", # Needed for generating the reference docs from the data model
"sphinx==7.2.6",
"sphinx-copybutton==0.5.2",
"sphinx_design==0.5.0"
"sphinx-design==0.5.0",
]

[project.optional-dependencies]
dev = [
optional-dependencies.dev = [
"coverage==7.3.4",
"pip==24.0",
"pip-tools==7.4.1", # To add hashes to requirements
"pipx==1.6.0",
"pip-tools==7.4.1", # To add hashes to requirements
"unittest-xml-reporting==3.2.0", # Needed to generate JUnit XML output for Sonarcloud.io
"unittest-xml-reporting==3.2.0", # Needed to generate JUnit XML output for Sonarcloud.io
]
tools = [
optional-dependencies.tools = [
"bandit==1.7.9",
"fixit==2.1.0",
"mypy==1.10.0",
"pip-audit==2.7.3",
"pydantic==2.7.4", # Needed because pipx needs to inject Pydantic into the mpyp venv, see ci/quality.sh
"pydantic==2.7.4", # Needed because pipx needs to inject Pydantic into the mpyp venv, see ci/quality.sh
"pyproject-fmt==2.1.3",
"ruff==0.4.8",
"safety==3.2.3",
"vale==3.0.3.0", # Documentation grammar and style checker
"vulture==2.11"
"vale==3.0.3.0", # Documentation grammar and style checker
"vulture==2.11",
]

[tool.ruff]
target-version = "py312"
line-length = 120
src = [
"src",
]
lint.select = [
"ALL",
]
lint.ignore = [
"ANN101", # https://docs.astral.sh/ruff/rules/missing-type-function-argument/ - type checkers can infer the type of `self`, so annotating it is superfluous
"COM812", # https://docs.astral.sh/ruff/rules/missing-trailing-comma/ - this rule may cause conflicts when used with the ruff formatter
"D203", # https://docs.astral.sh/ruff/rules/one-blank-line-before-class/ - prevent warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`
"D213", # https://docs.astral.sh/ruff/rules/multi-line-summary-second-line/ - prevent warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt - not sure of the value of preventing "boolean traps"
"ISC001", # https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/ - this rule may cause conflicts when used with the ruff formatter
"PD", # https://docs.astral.sh/ruff/rules/#pandas-vet-pd - pandas isn't used
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt - pytest isn't used
]
lint.per-file-ignores.".vulture_ignore_list.py" = [
"ALL",
]
lint.per-file-ignores."__init__.py" = [
"D104", # https://docs.astral.sh/ruff/rules/undocumented-public-package/ - don't require doc strings in __init__.py files
]
lint.per-file-ignores."src/conf.py" = [
"INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/ - false positive because this is a configuration file
]
lint.per-file-ignores."src/create_reference_md.py" = [
"INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/ - false positive because this is a script
]
lint.per-file-ignores."tests/**/*.py" = [
"ANN201", # https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function/ - don't require test functions to have return types
]
lint.isort.section-order = [
"future",
"standard-library",
"third-party",
"second-party",
"first-party",
"tests",
"local-folder",
]
lint.isort.sections.second-party = [
"shared",
"shared_data_model",
]
lint.isort.sections.tests = [
"tests",
]

[tool.pyproject-fmt]
column_width = 40 # When to split arrays and dicts into multiple lines
indent = 4
keep_full_version = true # Remove trailing zero's from version specifiers?

[tool.mypy]
plugins = "pydantic.mypy"
ignore_missing_imports = false
Expand All @@ -46,43 +106,3 @@ generate_hashes = true
quiet = true
strip_extras = true
upgrade = true

[tool.ruff]
target-version = "py312"
line-length = 120
src = ["src"]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN101", # https://docs.astral.sh/ruff/rules/missing-type-function-argument/ - type checkers can infer the type of `self`, so annotating it is superfluous
"COM812", # https://docs.astral.sh/ruff/rules/missing-trailing-comma/ - this rule may cause conflicts when used with the ruff formatter
"D203", # https://docs.astral.sh/ruff/rules/one-blank-line-before-class/ - prevent warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`
"D213", # https://docs.astral.sh/ruff/rules/multi-line-summary-second-line/ - prevent warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`
"FBT", # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt - not sure of the value of preventing "boolean traps"
"ISC001", # https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/ - this rule may cause conflicts when used with the ruff formatter
"PD", # https://docs.astral.sh/ruff/rules/#pandas-vet-pd - pandas isn't used
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt - pytest isn't used
]

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "second-party", "first-party", "tests", "local-folder"]

[tool.ruff.lint.isort.sections]
"second-party" = ["shared", "shared_data_model"]
"tests" = ["tests"]

[tool.ruff.lint.per-file-ignores]
".vulture_ignore_list.py" = ["ALL"]
"__init__.py" = [
"D104", # https://docs.astral.sh/ruff/rules/undocumented-public-package/ - don't require doc strings in __init__.py files
]
"src/conf.py" = [
"INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/ - false positive because this is a configuration file
]
"src/create_reference_md.py" = [
"INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/ - false positive because this is a script
]
"tests/**/*.py" = [
"ANN201", # https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function/ - don't require test functions to have return types
]
28 changes: 28 additions & 0 deletions release/ci/quality.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

source ../ci/base.sh

# Ruff
run pipx run `spec ruff` check .
run pipx run `spec ruff` format --check .

# Fixit
run pipx run `spec fixit` lint *.py

# Mypy
run pipx run `spec mypy` --python-executable=$(which python) *.py

# Pyproject-fmt
run pipx run `spec pyproject-fmt` --check pyproject.toml

# pip-audit
run pipx run `spec pip-audit` --strict --progress-spinner=off -r requirements/requirements.txt -r requirements/requirements-dev.txt

# Safety
run pipx run `spec safety` check --bare -r requirements/requirements.txt -r requirements/requirements-dev.txt

# Bandit
run pipx run `spec bandit` --configfile pyproject.toml --quiet --recursive *.py

# Vulture
run pipx run `spec vulture` --min-confidence 0 *.py
53 changes: 48 additions & 5 deletions release/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
[project]
name = "release"
version = "5.13.0"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"bump-my-version==0.22.0",
"gitpython==3.1.43",
]

[project.optional-dependencies]
dev = [
optional-dependencies.dev = [
"pip==24.0",
"pip-tools==7.4.1" # To add hashes to requirements
"pip-tools==7.4.1", # To add hashes to requirements
]
optional-dependencies.tools = [
"bandit==1.7.9",
"fixit==2.1.0",
"mypy==1.10.0",
"pip-audit==2.7.3",
"pydantic==2.7.4", # Needed because pipx needs to inject Pydantic into the mpyp venv, see ci/quality.sh
"pyproject-fmt==2.1.3",
"ruff==0.4.8",
"safety==3.2.3",
"vulture==2.11",
]

[tool.ruff]
target-version = "py312"
line-length = 120
src = [
"src",
]
lint.select = [
"ALL",
]
lint.ignore = [
"COM812", # https://docs.astral.sh/ruff/rules/missing-trailing-comma/ - this rule may cause conflicts when used with the ruff formatter
"D203", # https://docs.astral.sh/ruff/rules/one-blank-line-before-class/ - prevent warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`
"D213", # https://docs.astral.sh/ruff/rules/multi-line-summary-second-line/ - prevent warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`
"ISC001", # https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/ - this rule may cause conflicts when used with the ruff formatter
]

[tool.pyproject-fmt]
indent = 4
keep_full_version = true # Remove trailing zero's from version specifiers?

[tool.bumpversion]
current_version = "5.13.0"
parse = """(?x)
Expand All @@ -33,7 +67,10 @@ commit = true
tag = true

[tool.bumpversion.parts.pre_release_label]
values = ["rc", "final"]
values = [
"rc",
"final",
]
optional_value = "final"

[[tool.bumpversion.files]]
Expand Down Expand Up @@ -76,6 +113,12 @@ glob = "../**/pyproject.toml"
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'

[tool.bandit]
skips = [
"B404", # Consider possible security implications associated with the subprocess module.
"B603", # subprocess call - check for execution of untrusted input.
]

[tool.pip-tools]
allow_unsafe = true
generate_hashes = true
Expand Down
Loading

0 comments on commit 051e2cc

Please sign in to comment.