Skip to content

Commit

Permalink
Update 'Ruff' to latest version and fix any linting issues (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
seapagan authored Dec 15, 2024
1 parent 6c07d0c commit c33dc97
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Linting
uses: chartboost/ruff-action@v1
- uses: astral-sh/ruff-action@v2
with:
args: check
- name: Check Formatting
uses: chartboost/ruff-action@v1
with:
args: format --check
args: " check --output-format=concise"
- run: ruff format --check
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
Expand Down
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 39.20.1
hooks:
- id: renovate-config-validator
files: ^renovate\.json$
# - repo: https://github.com/renovatebot/pre-commit-hooks
# rev: 39.69.2
# hooks:
# - id: renovate-config-validator
# files: ^renovate\.json$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.3
hooks:
- id: ruff
args: ["--output-format=concise"]
name: "lint with ruff"
- id: ruff-format
name: "format with ruff"
Expand All @@ -35,7 +36,7 @@ repos:

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.2
rev: 0.5.9
hooks:
# Update the uv lockfile
- id: uv-lock
Expand Down
6 changes: 3 additions & 3 deletions app/api_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Optional

import typer
from rich import print # pylint: disable=W0622
from rich import print as rprint
from rich.panel import Panel

from app.commands import custom, db, dev, docs, test, user
Expand All @@ -15,7 +15,7 @@
def cli_header() -> None:
"""Show a common header for all commands."""
name, _, _ = get_api_details()
print(
rprint(
Panel(
f"[bold]{name} configuration tool[/bold] {get_api_version()}",
highlight=True,
Expand All @@ -40,7 +40,7 @@ def main(
name, desc, _ = get_api_details()
output = f"[bold]{name}[/bold] v{get_api_version()}\n{desc}"

print(
rprint(
Panel(
output,
title="Version",
Expand Down
38 changes: 19 additions & 19 deletions app/commands/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import rtoml
import typer
from jinja2 import Template
from rich import print # pylint: disable=W0622
from rich import print as rprint

from app.config.helpers import (
LICENCES,
Expand Down Expand Up @@ -50,14 +50,14 @@ def init() -> None:
with get_config_path().open("w", encoding="UTF-8") as file:
file.write(out)
except OSError as err:
print(f"Cannot Write the metadata : {err}")
rprint(f"Cannot Write the metadata : {err}")
raise typer.Exit(2) from err


try:
from app.config.metadata import custom_metadata
except ModuleNotFoundError as exc:
print(
rprint(
"[red]The metadata file could not be found, it may have been deleted.\n"
"Recreating with defaults, please re-run the command."
)
Expand Down Expand Up @@ -166,27 +166,27 @@ def metadata() -> None:
datetime.datetime.now(tz=datetime.timezone.utc).today().year
)

print("\nYou have entered the following data:")
print(f"[green]Title : [/green]{data['title']}")
print(f"[green]Name : [/green]{data['name']}")
print(f"[green]Description : [/green]{data['desc']}")
print(f"[green]Version : [/green]{data['version']}")
print(f"[green]Repository : [/green]{data['repo']}")
print(f"[green]License : [/green]{data['license']['name']}")
print(f"[green]Author : [/green]{data['author']}")
print(f"[green]Email : [/green]{data['email']}")
print(f"[green]Website : [/green]{data['website']}")
print(f"[green](C) Year : [/green]{data['this_year']}")
rprint("\nYou have entered the following data:")
rprint(f"[green]Title : [/green]{data['title']}")
rprint(f"[green]Name : [/green]{data['name']}")
rprint(f"[green]Description : [/green]{data['desc']}")
rprint(f"[green]Version : [/green]{data['version']}")
rprint(f"[green]Repository : [/green]{data['repo']}")
rprint(f"[green]License : [/green]{data['license']['name']}")
rprint(f"[green]Author : [/green]{data['author']}")
rprint(f"[green]Email : [/green]{data['email']}")
rprint(f"[green]Website : [/green]{data['website']}")
rprint(f"[green](C) Year : [/green]{data['this_year']}")

if click.confirm("\nIs this Correct?", abort=True, default=True):
# write the metadata
print("\n[green]-> Writing out Metadata .... ", end="")
rprint("\n[green]-> Writing out Metadata .... ", end="")
out = Template(TEMPLATE).render(data)
try:
with get_config_path().open(mode="w", encoding="UTF-8") as file:
file.write(out)
except OSError as err:
print(f"Cannot Write the metadata : {err}")
rprint(f"Cannot Write the metadata : {err}")
sys.exit(2)

# update the pyproject.toml file
Expand All @@ -202,7 +202,7 @@ def metadata() -> None:

rtoml.dump(config, get_toml_path(), pretty=False)
except OSError as err:
print(f"Cannot update the pyproject.toml file : {err}")
rprint(f"Cannot update the pyproject.toml file : {err}")
sys.exit(3)
print("Done!")
print("\n[cyan]-> Remember to RESTART the API if it is running.\n")
rprint("Done!")
rprint("\n[cyan]-> Remember to RESTART the API if it is running.\n")
20 changes: 10 additions & 10 deletions app/commands/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import typer
from alembic import command
from alembic.config import Config
from rich import print # pylint: disable=W0622
from rich import print as rprint

app = typer.Typer(no_args_is_help=True, rich_markup_mode="rich")

Expand All @@ -31,13 +31,13 @@ def init(
If the database already exists, it will be dropped and recreated.
"""
if force:
print("\nInitialising Database ... ", end="")
rprint("\nInitialising Database ... ", end="")

command.downgrade(ALEMBIC_CFG, "base")
command.upgrade(ALEMBIC_CFG, "head")
print(DONE_MSG)
rprint(DONE_MSG)
else:
print("[cyan]Operation Cancelled.")
rprint("[cyan]Operation Cancelled.")


@app.command()
Expand All @@ -57,21 +57,21 @@ def drop(
This will delete all data from your Database!.
"""
if force:
print("\nDropping all tables ... ", end="")
rprint("\nDropping all tables ... ", end="")

command.downgrade(ALEMBIC_CFG, "base")
print(DONE_MSG)
rprint(DONE_MSG)
else:
print("[cyan]Operation Cancelled.")
rprint("[cyan]Operation Cancelled.")


@app.command()
def upgrade() -> None:
"""Apply the latest Database Migrations."""
print("\nUpgrading Database ... ", end="")
rprint("\nUpgrading Database ... ", end="")

command.upgrade(ALEMBIC_CFG, "head")
print(DONE_MSG)
rprint(DONE_MSG)


@app.command()
Expand All @@ -89,6 +89,6 @@ def revision(
The revision will be created in the `alembic/versions` directory, and is
autogenerated based on the current state of the database.
"""
print()
rprint()
command.revision(ALEMBIC_CFG, message=message, autogenerate=True)
command.upgrade(ALEMBIC_CFG, "head")
4 changes: 2 additions & 2 deletions app/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional # nosec

import typer
from rich import print # pylint: disable=W0622
from rich import print as rprint

app = typer.Typer()

Expand All @@ -29,7 +29,7 @@ def serve(
This will auto-refresh on any changes to the source in real-time.
"""
print("\n[cyan] -> Running a development server.\n")
rprint("\n[cyan] -> Running a development server.\n")
cmd_line = (
f"uvicorn app.main:app --port={port} --host={host} "
f"{'--reload' if reload else ''}"
Expand Down
4 changes: 2 additions & 2 deletions app/commands/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import typer
from fastapi.openapi.utils import get_openapi
from rich import print # pylint: disable=W0622
from rich import print as rprint

from app.main import app as main_app

Expand All @@ -27,7 +27,7 @@ def openapi(
You can also specify a filename using `--filename`.
"""
openapi_file = Path(prefix, filename)
print(
rprint(
"Generating OpenAPI schema at [bold]"
f"{openapi_file.resolve()}[/bold]\n"
)
Expand Down
10 changes: 5 additions & 5 deletions app/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import typer
from asyncpg.exceptions import InvalidCatalogNameError, InvalidPasswordError
from rich import print # pylint: disable=W0622
from rich import print as rprint
from sqlalchemy.ext.asyncio import create_async_engine

from app.config.settings import get_settings
Expand Down Expand Up @@ -33,14 +33,14 @@ async def prepare_database() -> None:
def setup() -> None:
"""Populate the test databases."""
try:
print("Migrating the test database ... ", end="")
rprint("Migrating the test database ... ", end="")
asyncio.run(prepare_database())
print("Done!")
rprint("Done!")
except (
InvalidCatalogNameError,
ConnectionRefusedError,
InvalidPasswordError,
) as exc:
print(f"\n[red] -> Error: {exc}")
print("Failed to migrate the test database.")
rprint(f"\n[red] -> Error: {exc}")
rprint("Failed to migrate the test database.")
raise typer.Exit(1) from exc
Loading

0 comments on commit c33dc97

Please sign in to comment.