Skip to content

Commit

Permalink
Update Linting and Formatting to use Ruff instead (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
seapagan authored Nov 13, 2023
1 parent edf1f46 commit cf626bb
Show file tree
Hide file tree
Showing 72 changed files with 993 additions and 893 deletions.
6 changes: 3 additions & 3 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: seapagan
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
ko_fi: grantramsay
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.buymeacoffee.com/seapagan']
custom: ["https://www.buymeacoffee.com/seapagan"]
17 changes: 17 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Linting

on: [push, pull_request, workflow_dispatch]

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Linting
uses: chartboost/ruff-action@v1
with:
args: check
- name: Check Formatting
uses: chartboost/ruff-action@v1
with:
args: format --check
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests

on:
push:
branches: ["main"]
branches: ["main", "develop"]
pull_request:
branches: ["main"]
branches: ["main", "develop"]
workflow_dispatch:

jobs:
Expand All @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

services:
postgres:
Expand Down
7 changes: 6 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"MD014": false,
"MD046": false
"MD046": false,
"MD033": {
"allowed_elements": [
"swagger-ui"
]
}
}
66 changes: 36 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,60 @@ repos:
hooks:
- id: check-yaml
args: [--unsafe]
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
args: [--line-length=80]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--max-line-length=80]
additional_dependencies: [flake8-docstrings, flake8-pyproject]
# files: ^my_appname/|^test_suite_name/
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- id: check-toml
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: isort
args: [--profile=black, --line-length=80]
- id: ruff
name: "lint with ruff"
- id: ruff-format
name: "format with ruff"

- repo: https://github.com/jackdewinter/pymarkdown
rev: v0.9.14
hooks:
- id: pymarkdown
exclude: ^.github/|^docs/
args: [-d, "MD014", scan]
- repo: https://github.com/pycqa/pydocstyle
rev: 6.3.0
name: "check markdown"
exclude: ^.github/|CHANGELOG
args: [-d, "MD046", scan]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1" # Use the sha / tag you want to point at
hooks:
- id: pydocstyle
additional_dependencies: ["pydocstyle[toml]"]
exclude: ^app/migrations/|__init__.py
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["--silent", "-c", "pyproject.toml", "-r"]
additional_dependencies: ["bandit[toml]"]
- id: mypy
name: "run mypy"

- repo: https://github.com/python-poetry/poetry
rev: "1.7.0"
hooks:
- id: poetry-check
name: "check poetry files"
# - id: poetry-lock
- id: poetry-export
name: "export production dependencies"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements.txt",
"--without",
"dev",
]
- id: poetry-export
name: "export development dependencies"
args:
[
"--without-hashes",
"-f",
"requirements.txt",
"-o",
"requirements-dev.txt",
"--with",
"dev",
]
18 changes: 11 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"source.fixAll": true,
"source.organizeImports": true
},
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
"autoDocstring.startOnNewLine": true,
"beautify.language": {
"html": ["htm", "html", "django-html"]
},
"black-formatter.args": ["--line-length=80"],
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"emmet.includeLanguages": {
Expand All @@ -27,28 +26,33 @@
},
"files.eol": "\n",
"files.exclude": {
"**/.cache": true,
"**/.mypy_cache": true,
"**/.pytest_cache": true,
"**/.ruff_cache": true,
"**/__pycache__": true
},
"flake8.args": ["--max-line-length=80"],
"git.alwaysSignOff": true,
"git.enableCommitSigning": true,
"html.format.indentHandlebars": true,
"html.format.templating": true,
"isort.args": ["--profile", "black", "--src=${workspaceFolder}"],
"material-icon-theme.languages.associations": {
"jinja-html": "django"
},
"pylint.args": ["--load-plugins", "pylint-pydantic", "pylint-pytest"],
"mypy-type-checker.importStrategy": "useBundled",
"mypy-type-checker.reportingScope": "workspace",
"python.analysis.autoImportCompletions": true,
"python.analysis.autoImportUserSymbols": true,
"python.analysis.extraPaths": [],
"python.analysis.indexing": true,
"python.analysis.stubPath": "/home/seapagan/stubs",
"python.analysis.typeCheckingMode": "basic",
"python.analysis.typeCheckingMode": "off",
"python.languageServer": "Pylance",
"python.pythonPath": "./.venv/bin/python",
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"ruff.organizeImports": false
"ruff.fixAll": false,
"ruff.organizeImports": true,
"mypy-type-checker.args": ["--strict"]
}
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Grant Ramsay
Copyright (c) 2022 - 2023 Grant Ramsay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 4 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- Add a `logout` route to immediately invalidate the users token and refresh
token. This will need a database to be kept of invalidated tokens (which can
periodically be auto-purged of tokens that would be time-expired anyway.)
- Allow to resend a registration email
- Allow to resend a registration email (part of the code is already there for
this, but was not functioning properly so disabled).
- Send an email to the **User** when they change their password or update their
profile, are Banned/Unbanned and to **Admins** when important events happen.
- Update current and future email templates with actual content, and change
Expand Down Expand Up @@ -45,6 +46,8 @@
- option to remove the customization functionality from the CLI. Useful once you
have customized the template and don't want to give the end-user the ability to
change it easily.
- ctrl-c on the `custom metadata` command should not bring up a Rich
stack-trace, but exit cleanly.

## Documentation

Expand Down
29 changes: 21 additions & 8 deletions api-admin
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /bin/env python
"""Run administrative tasks for the Template system."""
from typing import Optional

import typer
from rich import print # pylint: disable=W0622
from rich.panel import Panel
Expand All @@ -10,7 +12,7 @@ from app.config.helpers import get_api_details, get_api_version
app = typer.Typer(add_completion=False, no_args_is_help=True)


def cli_header():
def cli_header() -> None:
"""Show a common header for all commands."""
name, _, _ = get_api_details()
print(
Expand All @@ -25,14 +27,14 @@ def cli_header():

@app.callback(invoke_without_command=True)
def main(
version: bool = typer.Option(
version: Optional[bool] = typer.Option(
False,
"--version",
"-v",
help="Show the version and exit.",
is_eager=True,
)
):
),
) -> None:
"""Run administrative tasks for the FastAPI Template system."""
if version:
name, desc, _ = get_api_details()
Expand All @@ -46,16 +48,27 @@ def main(
border_style="green",
)
)
raise typer.Exit()
raise typer.Exit
cli_header()


app.add_typer(dev.app, name="serve")
app.add_typer(user.app, name="user", help="Add or modify users.")
app.add_typer(
dev.app,
name="serve",
)
app.add_typer(
user.app,
name="user",
help="Add or modify users.",
)
app.add_typer(
custom.app, name="custom", help="Customize the Application Metadata."
)
app.add_typer(db.app, name="db", help="Control the Database.")
app.add_typer(
db.app,
name="db",
help="Control the Database.",
)
app.add_typer(
docs.app, name="docs", help="Generate and upload API documentation."
)
Expand Down
4 changes: 4 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""This is the main module for the application.
It is usually ran from 'uvicorn' as a 'FastAPI' application.
"""
1 change: 1 addition & 0 deletions app/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""This module contains all the CLI commands for the 'api-admin' command."""
Loading

0 comments on commit cf626bb

Please sign in to comment.