Skip to content

Commit cf626bb

Browse files
authored
Update Linting and Formatting to use Ruff instead (#273)
1 parent edf1f46 commit cf626bb

72 files changed

Lines changed: 993 additions & 893 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/FUNDING.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# These are supported funding model platforms
22

3-
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3+
github: seapagan
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
6-
ko_fi: # Replace with a single Ko-fi username
6+
ko_fi: grantramsay
77
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
88
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
99
liberapay: # Replace with a single Liberapay username
1010
issuehunt: # Replace with a single IssueHunt username
1111
otechie: # Replace with a single Otechie username
1212
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13-
custom: ['https://www.buymeacoffee.com/seapagan']
13+
custom: ["https://www.buymeacoffee.com/seapagan"]

.github/workflows/ruff.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Linting
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
ruff:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Linting
11+
uses: chartboost/ruff-action@v1
12+
with:
13+
args: check
14+
- name: Check Formatting
15+
uses: chartboost/ruff-action@v1
16+
with:
17+
args: format --check

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Tests
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: ["main", "develop"]
66
pull_request:
7-
branches: ["main"]
7+
branches: ["main", "develop"]
88
workflow_dispatch:
99

1010
jobs:
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: ["3.9", "3.10", "3.11"]
16+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1717

1818
services:
1919
postgres:

.markdownlint.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"MD014": false,
3-
"MD046": false
3+
"MD046": false,
4+
"MD033": {
5+
"allowed_elements": [
6+
"swagger-ui"
7+
]
8+
}
49
}

.pre-commit-config.yaml

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,60 @@ repos:
66
hooks:
77
- id: check-yaml
88
args: [--unsafe]
9-
- id: end-of-file-fixer
109
- id: trailing-whitespace
11-
- repo: https://github.com/psf/black
12-
rev: 23.10.1
13-
hooks:
14-
- id: black
15-
args: [--line-length=80]
16-
- repo: https://github.com/PyCQA/flake8
17-
rev: 6.1.0
18-
hooks:
19-
- id: flake8
20-
args: [--max-line-length=80]
21-
additional_dependencies: [flake8-docstrings, flake8-pyproject]
22-
# files: ^my_appname/|^test_suite_name/
23-
- repo: https://github.com/pycqa/isort
24-
rev: 5.12.0
10+
- id: check-toml
11+
- id: check-merge-conflict
12+
- id: end-of-file-fixer
13+
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.1.4
2516
hooks:
26-
- id: isort
27-
args: [--profile=black, --line-length=80]
17+
- id: ruff
18+
name: "lint with ruff"
19+
- id: ruff-format
20+
name: "format with ruff"
21+
2822
- repo: https://github.com/jackdewinter/pymarkdown
2923
rev: v0.9.14
3024
hooks:
3125
- id: pymarkdown
32-
exclude: ^.github/|^docs/
33-
args: [-d, "MD014", scan]
34-
- repo: https://github.com/pycqa/pydocstyle
35-
rev: 6.3.0
26+
name: "check markdown"
27+
exclude: ^.github/|CHANGELOG
28+
args: [-d, "MD046", scan]
29+
30+
- repo: https://github.com/pre-commit/mirrors-mypy
31+
rev: "v1.6.1" # Use the sha / tag you want to point at
3632
hooks:
37-
- id: pydocstyle
38-
additional_dependencies: ["pydocstyle[toml]"]
39-
exclude: ^app/migrations/|__init__.py
40-
- repo: https://github.com/PyCQA/bandit
41-
rev: 1.7.5
42-
hooks:
43-
- id: bandit
44-
args: ["--silent", "-c", "pyproject.toml", "-r"]
45-
additional_dependencies: ["bandit[toml]"]
33+
- id: mypy
34+
name: "run mypy"
35+
4636
- repo: https://github.com/python-poetry/poetry
4737
rev: "1.7.0"
4838
hooks:
4939
- id: poetry-check
40+
name: "check poetry files"
5041
# - id: poetry-lock
5142
- id: poetry-export
43+
name: "export production dependencies"
5244
args:
5345
[
5446
"--without-hashes",
5547
"-f",
5648
"requirements.txt",
5749
"-o",
5850
"requirements.txt",
51+
"--without",
52+
"dev",
53+
]
54+
- id: poetry-export
55+
name: "export development dependencies"
56+
args:
57+
[
58+
"--without-hashes",
59+
"-f",
60+
"requirements.txt",
61+
"-o",
62+
"requirements-dev.txt",
63+
"--with",
64+
"dev",
5965
]

.vscode/settings.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
"source.fixAll": true,
55
"source.organizeImports": true
66
},
7-
"editor.defaultFormatter": "ms-python.black-formatter"
7+
"editor.defaultFormatter": "charliermarsh.ruff"
88
},
99
"autoDocstring.startOnNewLine": true,
1010
"beautify.language": {
1111
"html": ["htm", "html", "django-html"]
1212
},
13-
"black-formatter.args": ["--line-length=80"],
1413
"editor.formatOnPaste": false,
1514
"editor.formatOnSave": true,
1615
"emmet.includeLanguages": {
@@ -27,28 +26,33 @@
2726
},
2827
"files.eol": "\n",
2928
"files.exclude": {
29+
"**/.cache": true,
30+
"**/.mypy_cache": true,
31+
"**/.pytest_cache": true,
32+
"**/.ruff_cache": true,
3033
"**/__pycache__": true
3134
},
32-
"flake8.args": ["--max-line-length=80"],
3335
"git.alwaysSignOff": true,
3436
"git.enableCommitSigning": true,
3537
"html.format.indentHandlebars": true,
3638
"html.format.templating": true,
37-
"isort.args": ["--profile", "black", "--src=${workspaceFolder}"],
3839
"material-icon-theme.languages.associations": {
3940
"jinja-html": "django"
4041
},
41-
"pylint.args": ["--load-plugins", "pylint-pydantic", "pylint-pytest"],
42+
"mypy-type-checker.importStrategy": "useBundled",
43+
"mypy-type-checker.reportingScope": "workspace",
4244
"python.analysis.autoImportCompletions": true,
4345
"python.analysis.autoImportUserSymbols": true,
4446
"python.analysis.extraPaths": [],
4547
"python.analysis.indexing": true,
4648
"python.analysis.stubPath": "/home/seapagan/stubs",
47-
"python.analysis.typeCheckingMode": "basic",
49+
"python.analysis.typeCheckingMode": "off",
4850
"python.languageServer": "Pylance",
4951
"python.pythonPath": "./.venv/bin/python",
5052
"python.testing.pytestArgs": ["tests"],
5153
"python.testing.pytestEnabled": true,
5254
"python.testing.unittestEnabled": false,
53-
"ruff.organizeImports": false
55+
"ruff.fixAll": false,
56+
"ruff.organizeImports": true,
57+
"mypy-type-checker.args": ["--strict"]
5458
}

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Grant Ramsay
3+
Copyright (c) 2022 - 2023 Grant Ramsay
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

TODO.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
- Add a `logout` route to immediately invalidate the users token and refresh
1414
token. This will need a database to be kept of invalidated tokens (which can
1515
periodically be auto-purged of tokens that would be time-expired anyway.)
16-
- Allow to resend a registration email
16+
- Allow to resend a registration email (part of the code is already there for
17+
this, but was not functioning properly so disabled).
1718
- Send an email to the **User** when they change their password or update their
1819
profile, are Banned/Unbanned and to **Admins** when important events happen.
1920
- Update current and future email templates with actual content, and change
@@ -45,6 +46,8 @@
4546
- option to remove the customization functionality from the CLI. Useful once you
4647
have customized the template and don't want to give the end-user the ability to
4748
change it easily.
49+
- ctrl-c on the `custom metadata` command should not bring up a Rich
50+
stack-trace, but exit cleanly.
4851

4952
## Documentation
5053

api-admin

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#! /bin/env python
22
"""Run administrative tasks for the Template system."""
3+
from typing import Optional
4+
35
import typer
46
from rich import print # pylint: disable=W0622
57
from rich.panel import Panel
@@ -10,7 +12,7 @@ from app.config.helpers import get_api_details, get_api_version
1012
app = typer.Typer(add_completion=False, no_args_is_help=True)
1113

1214

13-
def cli_header():
15+
def cli_header() -> None:
1416
"""Show a common header for all commands."""
1517
name, _, _ = get_api_details()
1618
print(
@@ -25,14 +27,14 @@ def cli_header():
2527

2628
@app.callback(invoke_without_command=True)
2729
def main(
28-
version: bool = typer.Option(
30+
version: Optional[bool] = typer.Option(
2931
False,
3032
"--version",
3133
"-v",
3234
help="Show the version and exit.",
3335
is_eager=True,
34-
)
35-
):
36+
),
37+
) -> None:
3638
"""Run administrative tasks for the FastAPI Template system."""
3739
if version:
3840
name, desc, _ = get_api_details()
@@ -46,16 +48,27 @@ def main(
4648
border_style="green",
4749
)
4850
)
49-
raise typer.Exit()
51+
raise typer.Exit
5052
cli_header()
5153

5254

53-
app.add_typer(dev.app, name="serve")
54-
app.add_typer(user.app, name="user", help="Add or modify users.")
55+
app.add_typer(
56+
dev.app,
57+
name="serve",
58+
)
59+
app.add_typer(
60+
user.app,
61+
name="user",
62+
help="Add or modify users.",
63+
)
5564
app.add_typer(
5665
custom.app, name="custom", help="Customize the Application Metadata."
5766
)
58-
app.add_typer(db.app, name="db", help="Control the Database.")
67+
app.add_typer(
68+
db.app,
69+
name="db",
70+
help="Control the Database.",
71+
)
5972
app.add_typer(
6073
docs.app, name="docs", help="Generate and upload API documentation."
6174
)

app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""This is the main module for the application.
2+
3+
It is usually ran from 'uvicorn' as a 'FastAPI' application.
4+
"""

0 commit comments

Comments
 (0)