Skip to content

Commit

Permalink
Ignore mypy errors for pydantic env argument
Browse files Browse the repository at this point in the history
Ignore mypy errors for pydantic env argument
  • Loading branch information
francbartoli committed Dec 26, 2023
1 parent ba367f8 commit 8319143
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 45 deletions.
138 changes: 93 additions & 45 deletions app/config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class GlobalConfig(BaseSettings):
# This variable will be loaded from the .env file. However, if there is a
# shell environment variable having the same name, that will take precedence.

ENV_STATE: Optional[str] = pydantic.Field(None, env="ENV_STATE")
HOST: Optional[str] = pydantic.Field(None, env="HOST")
PORT: Optional[str] = pydantic.Field(None, env="PORT")
ENV_STATE: Optional[str] = pydantic.Field(None, env="ENV_STATE") # type: ignore
HOST: Optional[str] = pydantic.Field(None, env="HOST") # type: ignore
PORT: Optional[str] = pydantic.Field(None, env="PORT") # type: ignore

model_config = SettingsConfigDict(
env_file=".env",
Expand All @@ -29,75 +29,123 @@ class GlobalConfig(BaseSettings):
class DevConfig(GlobalConfig):
"""Development configurations."""

ROOT_PATH: Optional[str] = pydantic.Field(None, env="DEV_ROOT_PATH")
ROOT_PATH: Optional[str] = pydantic.Field(None, env="DEV_ROOT_PATH") # type: ignore
AWS_LAMBDA_DEPLOY: Optional[bool] = pydantic.Field(
None, env="DEV_AWS_LAMBDA_DEPLOY"
)
LOG_PATH: Optional[str] = pydantic.Field(None, env="DEV_LOG_PATH")
LOG_FILENAME: Optional[str] = pydantic.Field(None, env="DEV_LOG_FILENAME")
LOG_LEVEL: Optional[str] = pydantic.Field(None, env="DEV_LOG_LEVEL")
LOG_ENQUEUE: Optional[bool] = pydantic.Field(None, env="DEV_LOG_ENQUEUE")
LOG_ROTATION: Optional[str] = pydantic.Field(None, env="DEV_LOG_ROTATION")
LOG_RETENTION: Optional[str] = pydantic.Field(None, env="DEV_LOG_RETENTION")
LOG_FORMAT: Optional[str] = pydantic.Field(None, env="DEV_LOG_FORMAT")
OPA_ENABLED: Optional[bool] = pydantic.Field(None, env="DEV_OPA_ENABLED")
OPA_URL: Optional[str] = pydantic.Field(None, env="DEV_OPA_URL")
APP_URI: Optional[str] = pydantic.Field(None, env="DEV_APP_URI")
) # type: ignore
LOG_PATH: Optional[str] = pydantic.Field(None, env="DEV_LOG_PATH") # type: ignore
LOG_FILENAME: Optional[str] = pydantic.Field(
None, env="DEV_LOG_FILENAME"
) # type: ignore
LOG_LEVEL: Optional[str] = pydantic.Field(None, env="DEV_LOG_LEVEL") # type: ignore
LOG_ENQUEUE: Optional[bool] = pydantic.Field(
None, env="DEV_LOG_ENQUEUE"
) # type: ignore
LOG_ROTATION: Optional[str] = pydantic.Field(
None, env="DEV_LOG_ROTATION"
) # type: ignore
LOG_RETENTION: Optional[str] = pydantic.Field(
None, env="DEV_LOG_RETENTION"
) # type: ignore
LOG_FORMAT: Optional[str] = pydantic.Field(
None, env="DEV_LOG_FORMAT"
) # type: ignore
OPA_ENABLED: Optional[bool] = pydantic.Field(
None, env="DEV_OPA_ENABLED"
) # type: ignore
OPA_URL: Optional[str] = pydantic.Field(None, env="DEV_OPA_URL") # type: ignore
APP_URI: Optional[str] = pydantic.Field(None, env="DEV_APP_URI") # type: ignore
OIDC_WELL_KNOWN_ENDPOINT: Optional[str] = pydantic.Field(
None, env="DEV_OIDC_WELL_KNOWN_ENDPOINT"
)
OIDC_CLIENT_ID: Optional[str] = pydantic.Field(None, env="DEV_OIDC_CLIENT_ID")
) # type: ignore
OIDC_CLIENT_ID: Optional[str] = pydantic.Field(
None, env="DEV_OIDC_CLIENT_ID"
) # type: ignore
OIDC_CLIENT_SECRET: Optional[str] = pydantic.Field(
None, env="DEV_OIDC_CLIENT_SECRET"
)
API_KEY_ENABLED: Optional[bool] = pydantic.Field(None, env="DEV_API_KEY_ENABLED")
) # type: ignore
API_KEY_ENABLED: Optional[bool] = pydantic.Field(
None, env="DEV_API_KEY_ENABLED"
) # type: ignore
PYGEOAPI_KEY_GLOBAL: Optional[str] = pydantic.Field(
None, env="DEV_PYGEOAPI_KEY_GLOBAL"
)
PYGEOAPI_BASEURL: Optional[str] = pydantic.Field(None, env="DEV_PYGEOAPI_BASEURL")
PYGEOAPI_CONFIG: Optional[str] = pydantic.Field(None, env="DEV_PYGEOAPI_CONFIG")
PYGEOAPI_OPENAPI: Optional[str] = pydantic.Field(None, env="DEV_PYGEOAPI_OPENAPI")
) # type: ignore
PYGEOAPI_BASEURL: Optional[str] = pydantic.Field(
None, env="DEV_PYGEOAPI_BASEURL"
) # type: ignore
PYGEOAPI_CONFIG: Optional[str] = pydantic.Field(
None, env="DEV_PYGEOAPI_CONFIG"
) # type: ignore
PYGEOAPI_OPENAPI: Optional[str] = pydantic.Field(
None, env="DEV_PYGEOAPI_OPENAPI"
) # type: ignore
FASTGEOAPI_CONTEXT: Optional[str] = pydantic.Field(
None, env="DEV_FASTGEOAPI_CONTEXT"
)
) # type: ignore

model_config = SettingsConfigDict(env_prefix="DEV_")


class ProdConfig(GlobalConfig):
"""Production configurations."""

ROOT_PATH: Optional[str] = pydantic.Field(None, env="PROD_ROOT_PATH")
ROOT_PATH: Optional[str] = pydantic.Field(
None, env="PROD_ROOT_PATH"
) # type: ignore
AWS_LAMBDA_DEPLOY: Optional[bool] = pydantic.Field(
None, env="PROD_AWS_LAMBDA_DEPLOY"
)
LOG_PATH: Optional[str] = pydantic.Field(None, env="PROD_LOG_PATH")
LOG_FILENAME: Optional[str] = pydantic.Field(None, env="PROD_LOG_FILENAME")
LOG_LEVEL: Optional[str] = pydantic.Field(None, env="PROD_LOG_LEVEL")
LOG_ENQUEUE: Optional[bool] = pydantic.Field(None, env="PROD_LOG_ENQUEUE")
LOG_ROTATION: Optional[str] = pydantic.Field(None, env="PROD_LOG_ROTATION")
LOG_RETENTION: Optional[str] = pydantic.Field(None, env="PROD_LOG_RETENTION")
LOG_FORMAT: Optional[str] = pydantic.Field(None, env="PROD_LOG_FORMAT")
OPA_ENABLED: Optional[bool] = pydantic.Field(None, env="PROD_OPA_ENABLED")
OPA_URL: Optional[str] = pydantic.Field(None, env="PROD_OPA_URL")
APP_URI: Optional[str] = pydantic.Field(None, env="PROD_APP_URI")
) # type: ignore
LOG_PATH: Optional[str] = pydantic.Field(None, env="PROD_LOG_PATH") # type: ignore
LOG_FILENAME: Optional[str] = pydantic.Field(
None, env="PROD_LOG_FILENAME"
) # type: ignore
LOG_LEVEL: Optional[str] = pydantic.Field(
None, env="PROD_LOG_LEVEL"
) # type: ignore
LOG_ENQUEUE: Optional[bool] = pydantic.Field(
None, env="PROD_LOG_ENQUEUE"
) # type: ignore
LOG_ROTATION: Optional[str] = pydantic.Field(
None, env="PROD_LOG_ROTATION"
) # type: ignore
LOG_RETENTION: Optional[str] = pydantic.Field(
None, env="PROD_LOG_RETENTION"
) # type: ignore
LOG_FORMAT: Optional[str] = pydantic.Field(
None, env="PROD_LOG_FORMAT"
) # type: ignore
OPA_ENABLED: Optional[bool] = pydantic.Field(
None, env="PROD_OPA_ENABLED"
) # type: ignore
OPA_URL: Optional[str] = pydantic.Field(None, env="PROD_OPA_URL") # type: ignore
APP_URI: Optional[str] = pydantic.Field(None, env="PROD_APP_URI") # type: ignore
OIDC_WELL_KNOWN_ENDPOINT: Optional[str] = pydantic.Field(
None, env="PROD_OIDC_WELL_KNOWN_ENDPOINT"
)
OIDC_CLIENT_ID: Optional[str] = pydantic.Field(None, env="PROD_OIDC_CLIENT_ID")
) # type: ignore
OIDC_CLIENT_ID: Optional[str] = pydantic.Field(
None, env="PROD_OIDC_CLIENT_ID"
) # type: ignore
OIDC_CLIENT_SECRET: Optional[str] = pydantic.Field(
None, env="PROD_OIDC_CLIENT_SECRET"
)
API_KEY_ENABLED: Optional[bool] = pydantic.Field(None, env="PROD_API_KEY_ENABLED")
) # type: ignore
API_KEY_ENABLED: Optional[bool] = pydantic.Field(
None, env="PROD_API_KEY_ENABLED"
) # type: ignore
PYGEOAPI_KEY_GLOBAL: Optional[str] = pydantic.Field(
None, env="PROD_PYGEOAPI_KEY_GLOBAL"
)
PYGEOAPI_BASEURL: Optional[str] = pydantic.Field(None, env="PROD_PYGEOAPI_BASEURL")
PYGEOAPI_CONFIG: Optional[str] = pydantic.Field(None, env="PROD_PYGEOAPI_CONFIG")
PYGEOAPI_OPENAPI: Optional[str] = pydantic.Field(None, env="PROD_PYGEOAPI_OPENAPI")
) # type: ignore
PYGEOAPI_BASEURL: Optional[str] = pydantic.Field(
None, env="PROD_PYGEOAPI_BASEURL"
) # type: ignore
PYGEOAPI_CONFIG: Optional[str] = pydantic.Field(
None, env="PROD_PYGEOAPI_CONFIG"
) # type: ignore
PYGEOAPI_OPENAPI: Optional[str] = pydantic.Field(
None, env="PROD_PYGEOAPI_OPENAPI"
) # type: ignore
FASTGEOAPI_CONTEXT: Optional[str] = pydantic.Field(
None, env="PROD_FASTGEOAPI_CONTEXT"
)
) # type: ignore

model_config = SettingsConfigDict(env_prefix="PROD_")

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ show_missing = true
fail_under = 100

[tool.mypy]
exclude = ".venv"
strict = true
warn_unreachable = true
pretty = true
Expand Down

0 comments on commit 8319143

Please sign in to comment.