Skip to content

Commit

Permalink
Fix ordering python imports
Browse files Browse the repository at this point in the history
  • Loading branch information
francbartoli committed Apr 6, 2024
1 parent 6e521e4 commit ef8816b
Show file tree
Hide file tree
Showing 24 changed files with 121 additions and 55 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ repos:
language: system
types: [python]
args: [--py37-plus]
- id: reorder-python-imports
name: Reorder python imports
entry: reorder-python-imports
language: system
types: [python]
args: [--application-directories=app]
- id: trailing-whitespace
name: Trim Trailing Whitespace
entry: trailing-whitespace-fixer
Expand All @@ -56,3 +50,9 @@ repos:
rev: v2.4.1
hooks:
- id: prettier
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args: ["--force-single-line", "--line-length=100", "--profile=black"]
1 change: 1 addition & 0 deletions app/auth/auth_interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Auth interface module."""

from abc import ABC
from abc import abstractmethod
from typing import Dict
Expand Down
10 changes: 6 additions & 4 deletions app/auth/auth_jwks.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""Auth JWKS module."""

import typing
from dataclasses import dataclass
from dataclasses import field

import httpx
from app.auth.auth_interface import AuthInterface
from app.auth.exceptions import Oauth2Error
from app.config.logging import create_logger
from authlib.jose import errors
from authlib.jose import JsonWebKey
from authlib.jose import JsonWebToken
from authlib.jose import JWTClaims
from authlib.jose import KeySet
from authlib.jose import errors
from starlette.requests import Request
from starlette.responses import RedirectResponse

from app.auth.auth_interface import AuthInterface
from app.auth.exceptions import Oauth2Error
from app.config.logging import create_logger

# from cachetools import cached
# from cachetools import TTLCache

Expand Down
8 changes: 3 additions & 5 deletions app/auth/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from openapi_pydantic.v3.v3_0_3 import Response
"""Authentication models module."""

from openapi_pydantic.v3.v3_0_3 import Response

unauthorized = {
"401": Response(
description="Unauthorized response",
message="Unauthenticated"
)
"401": Response(description="Unauthorized response", message="Unauthenticated")
}
4 changes: 3 additions & 1 deletion app/auth/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""OAuth2 provider module."""

import re
from abc import ABC
from abc import abstractmethod
from typing import List
from typing import Optional

from app.auth.auth_interface import AuthInterface
from starlette.requests import Request

from app.auth.auth_interface import AuthInterface


class Injectable(ABC):
"""Define interface for injectables."""
Expand Down
1 change: 1 addition & 0 deletions app/config/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App configuration module."""

from functools import lru_cache
from typing import Optional

Expand Down
9 changes: 5 additions & 4 deletions app/config/auth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Authn and Authz module."""
from app.auth.auth_jwks import JWKSAuthentication
from app.auth.auth_jwks import JWKSConfig
from app.auth.oauth2 import Oauth2Provider
from app.config.app import configuration as cfg

from fastapi_opa import OPAConfig
from fastapi_opa.auth import OIDCAuthentication
from fastapi_opa.auth import OIDCConfig

from app.auth.auth_jwks import JWKSAuthentication
from app.auth.auth_jwks import JWKSConfig
from app.auth.oauth2 import Oauth2Provider
from app.config.app import configuration as cfg

# The hostname of your Open Policy Agent instance
opa_host = cfg.OPA_URL
Expand Down
4 changes: 3 additions & 1 deletion app/config/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Logging module."""

import logging
import sys
from pathlib import Path

from loguru import logger

from app.config.app import configuration as cfg
from app.schemas.logging import LoggerModel
from app.schemas.logging import LoggingBase
from loguru import logger


class InterceptHandler(logging.Handler):
Expand Down
26 changes: 13 additions & 13 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
"""Main module."""

import os
import sys
from pathlib import Path
from typing import Any

import loguru
import uvicorn
from app.config.app import configuration as cfg
from app.config.logging import create_logger
from app.middleware.oauth2 import Oauth2Middleware
from app.middleware.pygeoapi import OpenapiSecurityMiddleware
from app.utils.app_exceptions import app_exception_handler
from app.utils.app_exceptions import AppExceptionError
from app.utils.pygeoapi_exceptions import PygeoapiEnvError
from app.utils.pygeoapi_exceptions import PygeoapiLanguageError
from app.utils.request_exceptions import http_exception_handler
from app.utils.request_exceptions import request_validation_exception_handler
from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from fastapi_opa import OPAMiddleware
Expand All @@ -24,13 +15,22 @@
from openapi_pydantic.v3.v3_0_3 import OAuthFlow
from openapi_pydantic.v3.v3_0_3 import OAuthFlows
from openapi_pydantic.v3.v3_0_3 import SecurityScheme
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.middleware.cors import CORSMiddleware

from pygeoapi.l10n import LocaleError
from pygeoapi.openapi import generate_openapi_document
from pygeoapi.provider.base import ProviderConnectionError
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.middleware.cors import CORSMiddleware

from app.config.app import configuration as cfg
from app.config.logging import create_logger
from app.middleware.oauth2 import Oauth2Middleware
from app.middleware.pygeoapi import OpenapiSecurityMiddleware
from app.utils.app_exceptions import AppExceptionError
from app.utils.app_exceptions import app_exception_handler
from app.utils.pygeoapi_exceptions import PygeoapiEnvError
from app.utils.pygeoapi_exceptions import PygeoapiLanguageError
from app.utils.request_exceptions import http_exception_handler
from app.utils.request_exceptions import request_validation_exception_handler

if cfg.LOG_LEVEL == "debug":
logger.remove()
Expand Down
9 changes: 5 additions & 4 deletions app/middleware/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""OAuth2 middleware module."""

import asyncio
import re
from typing import List
from typing import Optional

from app.auth.exceptions import Oauth2Error
from app.auth.oauth2 import Oauth2Provider
from app.config.app import configuration as cfg
from app.config.logging import create_logger
from fastapi.responses import JSONResponse
from starlette.requests import Request
from starlette.responses import RedirectResponse
Expand All @@ -16,6 +13,10 @@
from starlette.types import Scope
from starlette.types import Send

from app.auth.exceptions import Oauth2Error
from app.auth.oauth2 import Oauth2Provider
from app.config.app import configuration as cfg
from app.config.logging import create_logger

logger = create_logger("app.middleware.oauth2")

Expand Down
7 changes: 4 additions & 3 deletions app/middleware/pygeoapi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""Openapi middleware module."""

from typing import Any
from typing import Dict
from typing import List

from app.config.app import configuration as cfg
from app.config.logging import create_logger
from app.pygeoapi.openapi import augment_security
from openapi_pydantic.v3.v3_0_3 import SecurityScheme
from starlette.datastructures import Headers
from starlette.datastructures import MutableHeaders
Expand All @@ -15,6 +13,9 @@
from starlette.types import Scope
from starlette.types import Send

from app.config.app import configuration as cfg
from app.config.logging import create_logger
from app.pygeoapi.openapi import augment_security

logger = create_logger("app.middleware.pygeoapi")

Expand Down
7 changes: 4 additions & 3 deletions app/pygeoapi/openapi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Override vanilla openapi module."""

from typing import List

from app.auth.models import unauthorized
from app.config.app import configuration as cfg
from app.config.logging import create_logger
from openapi_pydantic.v3.v3_0_3 import OpenAPI
from openapi_pydantic.v3.v3_0_3 import SecurityScheme
from pydantic_core import ValidationError

from app.auth.models import unauthorized
from app.config.app import configuration as cfg
from app.config.logging import create_logger

logger = create_logger("app.pygeoapi.openapi")

Expand Down
1 change: 1 addition & 0 deletions app/schemas/logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logging module."""

from pathlib import Path

from pydantic import BaseModel
Expand Down
1 change: 1 addition & 0 deletions app/utils/app_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""App exceptions module."""

from fastapi import Request
from starlette.responses import JSONResponse

Expand Down
2 changes: 1 addition & 1 deletion app/utils/get_list_of_app_exceptions_for_frontend.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""App exceptions for frontend module."""

from app.config.logging import create_logger
from app.utils.app_exceptions import AppException


logger = create_logger(
name="app.utils.get_list_of_app_exceptions_for_frontend",
)
Expand Down
1 change: 1 addition & 0 deletions app/utils/request_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Request exceptions module."""

from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
from starlette.exceptions import HTTPException
Expand Down
2 changes: 1 addition & 1 deletion app/utils/service_result.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Service result module."""

import inspect

from app.config.logging import create_logger
from app.utils.app_exceptions import AppExceptionError


logger = create_logger("app.utils.service_result")


Expand Down
12 changes: 6 additions & 6 deletions cli.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Command-line interface."""

import os
from pathlib import Path

import typer
from app.config.app import configuration as cfg
from app.pygeoapi.openapi import augment_security
from app.utils.pygeoapi_exceptions import PygeoapiEnvError
from app.utils.pygeoapi_exceptions import PygeoapiLanguageError
from openapi_pydantic.v3.v3_0_3 import OAuthFlow
from openapi_pydantic.v3.v3_0_3 import OAuthFlows
from openapi_pydantic.v3.v3_0_3 import SecurityScheme
from rich.console import Console

from pygeoapi.l10n import LocaleError
from pygeoapi.openapi import generate_openapi_document
from pygeoapi.provider.base import ProviderConnectionError
from rich.console import Console

from app.config.app import configuration as cfg
from app.pygeoapi.openapi import augment_security
from app.utils.pygeoapi_exceptions import PygeoapiEnvError
from app.utils.pygeoapi_exceptions import PygeoapiLanguageError

log_console = Console()
err_console = Console(stderr=True, style="bold red")
Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Nox sessions."""

import os
import shutil
import sys
Expand Down
Loading

0 comments on commit ef8816b

Please sign in to comment.