From c0293c5eff94aa3bf52c4bd410bc0115f14eba32 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 25 Nov 2024 13:31:28 -0800 Subject: [PATCH] Update project templates for new Ruff Update `fastapi_safir_app` and `square_pypi_package` project templates to use Ruff 0.8.0. Remove the unnecessary `response_model` parameter to the default routes, and update the shared Ruff configuration file to account for some diagnostic renamings in Ruff 0.8.0. Remove the docstrings on the default `fastapi_safir_app` routes, following our convention of omitting docstrings and using the explicit route parameters instead for better documentation. --- .../example-uws/.pre-commit-config.yaml | 2 +- .../example-uws/ruff-shared.toml | 6 +++--- .../src/exampleuws/handlers/external.py | 21 ++++++++----------- .../src/exampleuws/handlers/internal.py | 7 +------ .../example/.pre-commit-config.yaml | 2 +- .../example/ruff-shared.toml | 6 +++--- .../example/src/example/handlers/external.py | 21 ++++++++----------- .../example/src/example/handlers/internal.py | 7 +------ .../.pre-commit-config.yaml | 2 +- .../{{cookiecutter.name}}/ruff-shared.toml | 6 +++--- .../handlers/external.py | 21 ++++++++----------- .../handlers/internal.py | 7 +------ .../example/.pre-commit-config.yaml | 2 +- .../example/ruff-shared.toml | 6 +++--- .../.pre-commit-config.yaml | 2 +- .../{{cookiecutter.name}}/ruff-shared.toml | 6 +++--- .../technote_md/testn-000/technote.toml | 2 +- .../technote_rst/testn-000/technote.toml | 2 +- 18 files changed, 52 insertions(+), 76 deletions(-) diff --git a/project_templates/fastapi_safir_app/example-uws/.pre-commit-config.yaml b/project_templates/fastapi_safir_app/example-uws/.pre-commit-config.yaml index 5f049c72..e039ec51 100644 --- a/project_templates/fastapi_safir_app/example-uws/.pre-commit-config.yaml +++ b/project_templates/fastapi_safir_app/example-uws/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/project_templates/fastapi_safir_app/example-uws/ruff-shared.toml b/project_templates/fastapi_safir_app/example-uws/ruff-shared.toml index 599fdec8..8b0e8d07 100644 --- a/project_templates/fastapi_safir_app/example-uws/ruff-shared.toml +++ b/project_templates/fastapi_safir_app/example-uws/ruff-shared.toml @@ -58,9 +58,9 @@ ignore = [ "S607", # using PATH is not a security vulnerability "SIM102", # sometimes the formatting of nested if statements is clearer "SIM117", # sometimes nested with contexts are clearer - "TCH001", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH002", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH003", # we decided to not maintain separate TYPE_CHECKING blocks + "TC001", # we decided to not maintain separate TYPE_CHECKING blocks + "TC002", # we decided to not maintain separate TYPE_CHECKING blocks + "TC003", # we decided to not maintain separate TYPE_CHECKING blocks "TD003", # we don't require issues be created for TODOs "TID252", # if we're going to use relative imports, use them always "TRY003", # good general advice but lint is way too aggressive diff --git a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/external.py b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/external.py index 33b57523..1182a152 100644 --- a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/external.py +++ b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/external.py @@ -10,7 +10,7 @@ from ..config import config from ..models import Index -__all__ = ["get_index", "external_router"] +__all__ = ["external_router"] external_router = APIRouter() """FastAPI router for all external handlers.""" @@ -22,24 +22,21 @@ "Document the top-level API here. By default it only returns metadata" " about the application." ), - response_model=Index, response_model_exclude_none=True, summary="Application metadata", ) async def get_index( logger: Annotated[BoundLogger, Depends(logger_dependency)], ) -> Index: - """GET ``/example-uws/`` (the app's external root). + # Customize this handler to return whatever the top-level resource of your + # application should return. For example, consider listing key API URLs. + # When doing so, also change or customize the response model in + # exampleuws.models.Index. + # + # By convention, the root of the external API includes a field called + # metadata that provides the same Safir-generated metadata as the internal + # root endpoint. - Customize this handler to return whatever the top-level resource of your - application should return. For example, consider listing key API URLs. - When doing so, also change or customize the response model in - `exampleuws.models.Index`. - - By convention, the root of the external API includes a field called - ``metadata`` that provides the same Safir-generated metadata as the - internal root endpoint. - """ # There is no need to log simple requests since uvicorn will do this # automatically, but this is included as an example of how to use the # logger for more complex logging. diff --git a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/internal.py b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/internal.py index ae1f5b19..8096f147 100644 --- a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/internal.py +++ b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/handlers/internal.py @@ -13,7 +13,7 @@ from ..config import config -__all__ = ["get_index", "internal_router"] +__all__ = ["internal_router"] internal_router = APIRouter() """FastAPI router for all internal handlers.""" @@ -27,15 +27,10 @@ " therefore cannot be used by external clients." ), include_in_schema=False, - response_model=Metadata, response_model_exclude_none=True, summary="Application metadata", ) async def get_index() -> Metadata: - """GET ``/`` (the app's internal root). - - By convention, this endpoint returns only the application's metadata. - """ return get_metadata( package_name="example-uws", application_name=config.name, diff --git a/project_templates/fastapi_safir_app/example/.pre-commit-config.yaml b/project_templates/fastapi_safir_app/example/.pre-commit-config.yaml index 5f049c72..e039ec51 100644 --- a/project_templates/fastapi_safir_app/example/.pre-commit-config.yaml +++ b/project_templates/fastapi_safir_app/example/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/project_templates/fastapi_safir_app/example/ruff-shared.toml b/project_templates/fastapi_safir_app/example/ruff-shared.toml index 599fdec8..8b0e8d07 100644 --- a/project_templates/fastapi_safir_app/example/ruff-shared.toml +++ b/project_templates/fastapi_safir_app/example/ruff-shared.toml @@ -58,9 +58,9 @@ ignore = [ "S607", # using PATH is not a security vulnerability "SIM102", # sometimes the formatting of nested if statements is clearer "SIM117", # sometimes nested with contexts are clearer - "TCH001", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH002", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH003", # we decided to not maintain separate TYPE_CHECKING blocks + "TC001", # we decided to not maintain separate TYPE_CHECKING blocks + "TC002", # we decided to not maintain separate TYPE_CHECKING blocks + "TC003", # we decided to not maintain separate TYPE_CHECKING blocks "TD003", # we don't require issues be created for TODOs "TID252", # if we're going to use relative imports, use them always "TRY003", # good general advice but lint is way too aggressive diff --git a/project_templates/fastapi_safir_app/example/src/example/handlers/external.py b/project_templates/fastapi_safir_app/example/src/example/handlers/external.py index fa0c1740..fa1ccd42 100644 --- a/project_templates/fastapi_safir_app/example/src/example/handlers/external.py +++ b/project_templates/fastapi_safir_app/example/src/example/handlers/external.py @@ -10,7 +10,7 @@ from ..config import config from ..models import Index -__all__ = ["get_index", "external_router"] +__all__ = ["external_router"] external_router = APIRouter() """FastAPI router for all external handlers.""" @@ -22,24 +22,21 @@ "Document the top-level API here. By default it only returns metadata" " about the application." ), - response_model=Index, response_model_exclude_none=True, summary="Application metadata", ) async def get_index( logger: Annotated[BoundLogger, Depends(logger_dependency)], ) -> Index: - """GET ``/example/`` (the app's external root). + # Customize this handler to return whatever the top-level resource of your + # application should return. For example, consider listing key API URLs. + # When doing so, also change or customize the response model in + # example.models.Index. + # + # By convention, the root of the external API includes a field called + # metadata that provides the same Safir-generated metadata as the internal + # root endpoint. - Customize this handler to return whatever the top-level resource of your - application should return. For example, consider listing key API URLs. - When doing so, also change or customize the response model in - `example.models.Index`. - - By convention, the root of the external API includes a field called - ``metadata`` that provides the same Safir-generated metadata as the - internal root endpoint. - """ # There is no need to log simple requests since uvicorn will do this # automatically, but this is included as an example of how to use the # logger for more complex logging. diff --git a/project_templates/fastapi_safir_app/example/src/example/handlers/internal.py b/project_templates/fastapi_safir_app/example/src/example/handlers/internal.py index 30bfc8ad..ed956e4e 100644 --- a/project_templates/fastapi_safir_app/example/src/example/handlers/internal.py +++ b/project_templates/fastapi_safir_app/example/src/example/handlers/internal.py @@ -13,7 +13,7 @@ from ..config import config -__all__ = ["get_index", "internal_router"] +__all__ = ["internal_router"] internal_router = APIRouter() """FastAPI router for all internal handlers.""" @@ -27,15 +27,10 @@ " therefore cannot be used by external clients." ), include_in_schema=False, - response_model=Metadata, response_model_exclude_none=True, summary="Application metadata", ) async def get_index() -> Metadata: - """GET ``/`` (the app's internal root). - - By convention, this endpoint returns only the application's metadata. - """ return get_metadata( package_name="example", application_name=config.name, diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/.pre-commit-config.yaml b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/.pre-commit-config.yaml index 5f049c72..e039ec51 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/.pre-commit-config.yaml +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/ruff-shared.toml b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/ruff-shared.toml index 599fdec8..8b0e8d07 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/ruff-shared.toml +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/ruff-shared.toml @@ -58,9 +58,9 @@ ignore = [ "S607", # using PATH is not a security vulnerability "SIM102", # sometimes the formatting of nested if statements is clearer "SIM117", # sometimes nested with contexts are clearer - "TCH001", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH002", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH003", # we decided to not maintain separate TYPE_CHECKING blocks + "TC001", # we decided to not maintain separate TYPE_CHECKING blocks + "TC002", # we decided to not maintain separate TYPE_CHECKING blocks + "TC003", # we decided to not maintain separate TYPE_CHECKING blocks "TD003", # we don't require issues be created for TODOs "TID252", # if we're going to use relative imports, use them always "TRY003", # good general advice but lint is way too aggressive diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/external.py b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/external.py index b88d39c4..338c3083 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/external.py +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/external.py @@ -10,7 +10,7 @@ from ..config import config from ..models import Index -__all__ = ["get_index", "external_router"] +__all__ = ["external_router"] external_router = APIRouter() """FastAPI router for all external handlers.""" @@ -22,24 +22,21 @@ "Document the top-level API here. By default it only returns metadata" " about the application." ), - response_model=Index, response_model_exclude_none=True, summary="Application metadata", ) async def get_index( logger: Annotated[BoundLogger, Depends(logger_dependency)], ) -> Index: - """GET ``/{{ cookiecutter.name | lower }}/`` (the app's external root). + # Customize this handler to return whatever the top-level resource of your + # application should return. For example, consider listing key API URLs. + # When doing so, also change or customize the response model in + # {{ cookiecutter.module_name }}.models.Index. + # + # By convention, the root of the external API includes a field called + # metadata that provides the same Safir-generated metadata as the internal + # root endpoint. - Customize this handler to return whatever the top-level resource of your - application should return. For example, consider listing key API URLs. - When doing so, also change or customize the response model in - `{{ cookiecutter.module_name }}.models.Index`. - - By convention, the root of the external API includes a field called - ``metadata`` that provides the same Safir-generated metadata as the - internal root endpoint. - """ # There is no need to log simple requests since uvicorn will do this # automatically, but this is included as an example of how to use the # logger for more complex logging. diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/internal.py b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/internal.py index be7d1977..8482c5f2 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/internal.py +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/handlers/internal.py @@ -13,7 +13,7 @@ from ..config import config -__all__ = ["get_index", "internal_router"] +__all__ = ["internal_router"] internal_router = APIRouter() """FastAPI router for all internal handlers.""" @@ -27,15 +27,10 @@ " therefore cannot be used by external clients." ), include_in_schema=False, - response_model=Metadata, response_model_exclude_none=True, summary="Application metadata", ) async def get_index() -> Metadata: - """GET ``/`` (the app's internal root). - - By convention, this endpoint returns only the application's metadata. - """ return get_metadata( package_name="{{ cookiecutter.name }}", application_name=config.name, diff --git a/project_templates/square_pypi_package/example/.pre-commit-config.yaml b/project_templates/square_pypi_package/example/.pre-commit-config.yaml index dfa53f73..e4ca1f75 100644 --- a/project_templates/square_pypi_package/example/.pre-commit-config.yaml +++ b/project_templates/square_pypi_package/example/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/project_templates/square_pypi_package/example/ruff-shared.toml b/project_templates/square_pypi_package/example/ruff-shared.toml index 599fdec8..8b0e8d07 100644 --- a/project_templates/square_pypi_package/example/ruff-shared.toml +++ b/project_templates/square_pypi_package/example/ruff-shared.toml @@ -58,9 +58,9 @@ ignore = [ "S607", # using PATH is not a security vulnerability "SIM102", # sometimes the formatting of nested if statements is clearer "SIM117", # sometimes nested with contexts are clearer - "TCH001", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH002", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH003", # we decided to not maintain separate TYPE_CHECKING blocks + "TC001", # we decided to not maintain separate TYPE_CHECKING blocks + "TC002", # we decided to not maintain separate TYPE_CHECKING blocks + "TC003", # we decided to not maintain separate TYPE_CHECKING blocks "TD003", # we don't require issues be created for TODOs "TID252", # if we're going to use relative imports, use them always "TRY003", # good general advice but lint is way too aggressive diff --git a/project_templates/square_pypi_package/{{cookiecutter.name}}/.pre-commit-config.yaml b/project_templates/square_pypi_package/{{cookiecutter.name}}/.pre-commit-config.yaml index dfa53f73..e4ca1f75 100644 --- a/project_templates/square_pypi_package/{{cookiecutter.name}}/.pre-commit-config.yaml +++ b/project_templates/square_pypi_package/{{cookiecutter.name}}/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.8.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/project_templates/square_pypi_package/{{cookiecutter.name}}/ruff-shared.toml b/project_templates/square_pypi_package/{{cookiecutter.name}}/ruff-shared.toml index 599fdec8..8b0e8d07 100644 --- a/project_templates/square_pypi_package/{{cookiecutter.name}}/ruff-shared.toml +++ b/project_templates/square_pypi_package/{{cookiecutter.name}}/ruff-shared.toml @@ -58,9 +58,9 @@ ignore = [ "S607", # using PATH is not a security vulnerability "SIM102", # sometimes the formatting of nested if statements is clearer "SIM117", # sometimes nested with contexts are clearer - "TCH001", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH002", # we decided to not maintain separate TYPE_CHECKING blocks - "TCH003", # we decided to not maintain separate TYPE_CHECKING blocks + "TC001", # we decided to not maintain separate TYPE_CHECKING blocks + "TC002", # we decided to not maintain separate TYPE_CHECKING blocks + "TC003", # we decided to not maintain separate TYPE_CHECKING blocks "TD003", # we don't require issues be created for TODOs "TID252", # if we're going to use relative imports, use them always "TRY003", # good general advice but lint is way too aggressive diff --git a/project_templates/technote_md/testn-000/technote.toml b/project_templates/technote_md/testn-000/technote.toml index 089090f1..8aa7d521 100644 --- a/project_templates/technote_md/testn-000/technote.toml +++ b/project_templates/technote_md/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-11-19T23:58:23Z +date_created = 2024-11-25T21:31:10Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0" diff --git a/project_templates/technote_rst/testn-000/technote.toml b/project_templates/technote_rst/testn-000/technote.toml index 3bc9c4a5..ce19c4bf 100644 --- a/project_templates/technote_rst/testn-000/technote.toml +++ b/project_templates/technote_rst/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-11-19T23:58:23Z +date_created = 2024-11-25T21:31:10Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0"