From 1d675d206dc67fb2335d27ec2989117ef9ada8e0 Mon Sep 17 00:00:00 2001 From: pdina Date: Wed, 1 May 2024 10:42:24 +0200 Subject: [PATCH] Minor documentation refinements (#311) --- README.md | 8 ++--- docs/application/applications.md | 16 +++++----- docs/application/levels.md | 10 +++--- docs/application/settings.md | 19 ++++++------ docs/configurations/jwt.md | 4 +-- docs/configurations/openapi/config.md | 8 ++--- docs/configurations/staticfiles.md | 2 +- docs/index.md | 10 +++--- docs/routing/router.md | 31 +++++++++---------- docs/routing/routes.md | 6 ++-- .../app/permissions_and_middlewares.py | 2 +- .../settings/settings_config/example1.py | 2 +- docs_src/configurations/template/settings.py | 2 +- docs_src/settings/custom/base.py | 2 +- docs_src/settings/custom/development.py | 4 +-- docs_src/settings/custom/production.py | 2 +- docs_src/settings/custom/testing.py | 2 +- esmerald/conf/global_settings.py | 10 ++++-- esmerald/core/directives/env.py | 6 ++-- .../core/directives/operations/runserver.py | 11 ++++--- esmerald/parsers.py | 2 +- 21 files changed, 84 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index b1eaa09e..2a0be723 100644 --- a/README.md +++ b/README.md @@ -185,11 +185,11 @@ custom or enterprise, fits within Esmerald ecosystem without scalability issues. ## Settings Like every other framework, when starting an application, a lot of [settings](./application/settings.md) can/need to be -passed to the main object and this can be very dauting and hugly to maintain and see. +passed to the main object and this can be very dauting and ugly to maintain and see. Esmerald comes with the [settings](./application/settings.md) in mind. A set of defaults that can be overridden by your very own settings -module but not limited to it as you can still use the classic approach of passing everything into a +module but not limited to it, as you can still use the classic approach of passing everything into a Esmerald instance directly when instantiating. **Example of classic approach**: @@ -251,7 +251,7 @@ from esmerald import EsmeraldAPISettings from esmerald.conf.enums import EnvironmentType class Development(EsmeraldAPISettings): - app_name: bool = 'My app in dev' + app_name: str = 'My app in dev' environment: str = EnvironmentType.DEVELOPMENT ``` @@ -485,7 +485,7 @@ app = Esmerald(routes=[Include('src.urls')]) ## Run the application -As mentioned before, we recomment uvicorn for production but it's not mandatory. +As mentioned before, we recommend uvicorn for production but it's not mandatory. **Using uvicorn**: diff --git a/docs/application/applications.md b/docs/application/applications.md index 4d55f024..41a9079b 100644 --- a/docs/application/applications.md +++ b/docs/application/applications.md @@ -27,7 +27,7 @@ of its functionality. Because the swagger and redoc can only do so much, for example with the `username = request.path_params["username"]` **you won't be able to test it via docs**. -**The best way of doing it is by calling the API directly via any prefered client or browser.** +**The best way of doing it is by calling the API directly via any preferred client or browser.** In other words, the path param can be captured using the Request.path_params, but cannot be tested from the Swagger UI. @@ -50,12 +50,12 @@ Via Insomnia: ### Instantiating the application -Creating an appliation instance can be done in different ways and with a great plus of using the +Creating an application instance can be done in different ways and with a great plus of using the [settings](./settings.md) for a cleaner approach. **Parameters**: -* **debug** - Boolean indicating if a debug tracebacks should be returns on errors. Basically, debug mode, +* **debug** - Boolean indicating if debug tracebacks should be returned on errors. Basically, debug mode, very useful for development. * **title** - The title for the application. Used for OpenAPI. * **app_name** - The application name. Used also for OpenAPI. @@ -83,7 +83,7 @@ or Lilya Middleware< internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/). * **dependencies** - A dictionary of string and [Inject](.././dependencies.md) instances enable application level dependency injection. -* **exception handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler +* **exception_handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions. * **csrf_config** - If [CSRFConfig](../configurations/csrf.md) is set it will enable the CSRF built-in middleware. @@ -96,7 +96,7 @@ application static files configuration. engine from the configuration object. * **session_config** - If [SessionConfig](../configurations/session.md) is set it will enable the session built-in middleware. -* **response_class** - Custom subclass of [Response](../responses.md) to be used as application application response +* **response_class** - Custom subclass of [Response](../responses.md) to be used as application response class. * **response_cookies** - List of [cookie](../datastructures.md) objects. * **response_headers** - Mapping dictionary of header objects. @@ -105,14 +105,14 @@ class. * **scheduler_tasks** - A python dictionary with key and pair values as strings mapping the [scheduler tasks](../scheduler/scheduler.md). * **scheduler_configurations** - A python dictionary with key and pair values as strings mapping the extra configuations of [scheduler tasks](../scheduler/handler.md). -* **enable_scheduler** - Flag indicating if the appliaction `scheduler` should be enabled or not. Defaults to `False`. +* **enable_scheduler** - Flag indicating if the application `scheduler` should be enabled or not. Defaults to `False`. * **timezone** - The application default timezone. Defaults to `UTC`. * **on_shutdown** - A list of callables to run on application shutdown. Shutdown handler callables do not take any arguments, and may be be either standard functions, or async functions. * **on_startup** - A list of callables to run on application startup. Startup handler callables do not take any arguments, and may be be either standard functions, or async functions. -* **lifepan** - The lifespan context function is a newer style that replaces on_startup / on_shutdown handlers. +* **lifespan** - The lifespan context function is a newer style that replaces on_startup / on_shutdown handlers. Use one or the other, not both. * **tags** - List of tags to include in the OpenAPI schema. * **include_in_schema** - Boolean flag to indicate if should be schema included or not. @@ -149,7 +149,7 @@ To access the application settings there are different ways: ### State and application instance -You can store arbitraty extra state on the application instance using the [State](../datastructures.md) instance. +You can store arbitrary extra state on the application instance using the [State](../datastructures.md) instance. Example: diff --git a/docs/application/levels.md b/docs/application/levels.md index 8aae176d..9cd860ef 100644 --- a/docs/application/levels.md +++ b/docs/application/levels.md @@ -3,7 +3,7 @@ An Esmerald application is composed by levels and those levels can be [Gateway](../routing/routes.md#gateway), [WebSocketGateway](../routing/routes.md#websocketgateway), [Include](../routing/routes.md#include), [handlers](../routing/handlers.md) or even **another Esmerald** or -[ChildEsmerald](../routing/router.md#child-esmerald-application) +[ChildEsmerald](../routing/router.md#child-esmerald-application). There are some levels in the application, let's use an example. @@ -41,8 +41,8 @@ also **first level** as independent instance. 1. [Handler](../routing/handlers.md) - The **second level**, inside the Gateway. !!! Warning - A `ChildEsmerald` is an independent instance that is plugged into a main `Esmerald` application but since - it is like another `Esmerald` object that also means the `ChildEsmerald` does not take precedent over the top-level + A `ChildEsmerald` is an independent instance that is plugged into a main `Esmerald` application, but since + it is like another `Esmerald` object, that also means the `ChildEsmerald` does not take precedence over the top-level application, instead, treats its own [Gateway](../routing/routes.md#gateway), [WebSocketGateway](../routing/routes.md#websocketgateway), [Include](../routing/routes.md#include), [handlers](../routing/handlers.md) or even another `Esmerald` or @@ -50,8 +50,8 @@ also **first level** as independent instance. ## Exceptions -`ChildEsmerald` as per **warning** above has its own rules but there are always exceptions to any almost every rule. -Although it is an independent instance with its own rules this is not applied to **every** parameter. +`ChildEsmerald`, as per **warning** above, has its own rules, but there are always exceptions to any almost every rule. +Although it is an independent instance with its own rules, this is not applied to **every** parameter. [Middlewares](../middleware/middleware.md) and [Permissions](../permissions.md) are actually global and the rules of precedence can be applied between an `Esmerald` instance and the corresponding `ChildEsmerald` apps. diff --git a/docs/application/settings.md b/docs/application/settings.md index b3ee63ff..fb852e24 100644 --- a/docs/application/settings.md +++ b/docs/application/settings.md @@ -2,14 +2,14 @@ Every application in a way or another needs settings for the uniqueness of the project itself. -When the complexity of a project increases and there are settings spread across the codebase it is when the things +When the complexity of a project increases and there are settings spread across the codebase, it is when the things start to get messy. One great framework, Django, has the settings in place but because of the legacy codebase and the complexity of almost 20 years of development of the framework, those became a bit bloated and hard to maintain. Inspired by Django and by the experience of 99% of the developed applications using some sort of settings -(by environment, by user...), Esmerald comes equiped to handle exactly with that natively and using +(by environment, by user...), Esmerald comes equipped to handle exactly with that natively and using [Pydantic](https://pydantic-docs.helpmanual.io/visual_studio_code/#basesettings-and-ignoring-pylancepyright-errors) to leverage those. @@ -23,11 +23,11 @@ There are two ways of using the settings object within an Esmerald application. * Using the **ESMERALD_SETTINGS_MODULE** * Using the **[settings_module](#the-settings_module)** -Each one of them has particular use cases but they also work together is perfect harmony. +Each one of them has particular use cases but they also work together in perfect harmony. ## EsmeraldAPISettings and the application -When starting a Esmerald instance if no parameters are provided, it will automatically load the defaults from the +When starting a Esmerald instance, if no parameters are provided, it will automatically load the defaults from the system settings object, the `EsmeraldAPISettings`. === "No parameters" @@ -50,7 +50,7 @@ For that reason custom settings are needed. **All the custom settings should be inherited from the `EsmeraldAPISettings`**. -Let's assume we have three environment for one application: `production`, `testing`, `development` and a base settings +Let's assume we have three environments for one application: `production`, `testing`, `development` and a base settings file that contains common settings across the three environments. === "Base" @@ -87,8 +87,7 @@ to each. ## Esmerald Settings Module -Esmerald by default is looking for a `ESMERALD_SETTINGS_MODULE` environment variable to execute any custom settings, -if nothing is provided then it will execute the application defaults. +Esmerald by default is looking for a `ESMERALD_SETTINGS_MODULE` environment variable to execute any custom settings. If nothing is provided, then it will execute the application defaults. === "Without ESMERALD_SETTINGS_MODULE" @@ -120,7 +119,7 @@ and loads it in lazy mode. ## The settings_module This is a great tool to make your Esmerald applications 100% independent and modular. There are cases -where you simply want to plug an existing esmerald application into another and that same esmerald application +where you simply want to plug an existing Esmerald application into another and that same Esmerald application already has unique settings and defaults. The `settings_module` is a parameter available in every single `Esmerald` instance as well as `ChildEsmerald`. @@ -303,7 +302,7 @@ The application will: 2. Will start with a middleware `HTTPSRedirectMiddleware`. Starting the application with the above settings will make sure that has an initial `HTTPSRedirectMiddleware` and `debug` -set with values **but** what happens if you use the settings + parameters on instantiation? +set with values, **but** what happens if you use the settings + parameters on instantiation? ```python from esmerald import Esmerald @@ -321,7 +320,7 @@ values in the moment of instantiating an `Esmerald` object, those will become th **Declaring parameters in the instance will always precede the values from your settings**. -The reason why you should be using settings it is because will make your codebase more organised and easier +The reason why you should be using settings is because it will make your codebase more organised and easier to maintain. !!! Check diff --git a/docs/configurations/jwt.md b/docs/configurations/jwt.md index b5ac4f74..d56f587a 100644 --- a/docs/configurations/jwt.md +++ b/docs/configurations/jwt.md @@ -53,7 +53,7 @@ token = Token(exp=..., iat=..., sub=...) The parameters are pretty standard from Python JOSE so you can feel -confortable with. +comfortable with. ### Generate a Token (encode) @@ -141,7 +141,7 @@ There is a lot here happening but basically what are we doing? * Checking for `token` in the header. * Checking if the `token_type` is of `access_token` (default name from the JWTConfig and can be whatever you want) and raises -an exception if its not `access_token`. +an exception if it's not `access_token`. * Returns the `AuthResult` object with the details of the retrieved user. The middleware also contains a wrapper called `AuthMiddleware`. This will be used later on in the views of the user. diff --git a/docs/configurations/openapi/config.md b/docs/configurations/openapi/config.md index af54f09d..3e948e7e 100644 --- a/docs/configurations/openapi/config.md +++ b/docs/configurations/openapi/config.md @@ -1,6 +1,6 @@ # OpenAPIConfig -OpenAPIConfig is a simple configuration with basic fields for the auto-genmerated documentation from Esmerald. +OpenAPIConfig is a simple configuration with basic fields for the auto-generated documentation from Esmerald. Prior to version 2, there were two pieces for the documentation but now it is simplified with a simple one. @@ -19,7 +19,7 @@ is up to you. ## OpenAPIConfig and application -The `OpenAPIConfig` contains a bunch of simple fields that are needed to to serve the documentation +The `OpenAPIConfig` contains a bunch of simple fields that are needed to serve the documentation and those can be easily overwritten. Currently, by default, the URL for the documentation are: @@ -43,13 +43,13 @@ It is very simple actually. This will create your own `OpenAPIConfig` and pass it to the Esmerald application but what about changing the current default `/docs` path? -Let's use a an example for clarification. +Let's use an example for clarification. ```python {!> ../docs_src/configurations/openapi/apiview.py !} ``` -From now on the url to access the `swagger` and `redoc` will be: +From now on the url to access `swagger`, `redoc` and `stoplight` will be: * **Swagger** - `/another-url/swagger`. * **Redoc** - `/another-url/redoc`. diff --git a/docs/configurations/staticfiles.md b/docs/configurations/staticfiles.md index 0401b172..4c37f736 100644 --- a/docs/configurations/staticfiles.md +++ b/docs/configurations/staticfiles.md @@ -4,7 +4,7 @@ StaticFilesConfig is simple set of configurations that when passed enables the b When a StaticFilesConfig object is passed to an application instance, it will enable the static files serving. !!! Check - StaticFiles are considereed an `app` and they are pure Lilya app so using Lilya StaticFiles + StaticFiles are considered an `app` and they are pure Lilya app, so using Lilya StaticFiles will also work with Esmerald. ## StaticFilesConfig and application diff --git a/docs/index.md b/docs/index.md index eb72e0fc..1bc2129a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -191,11 +191,11 @@ custom or enterprise, fits within Esmerald ecosystem without scalability issues. ## Settings Like every other framework, when starting an application, a lot of [settings](./application/settings.md) can/need to be -passed to the main object and this can be very dauting and hugly to maintain and see. +passed to the main object and this can be very dauting and ugly to maintain and see. Esmerald comes with the [settings](./application/settings.md) in mind. A set of defaults that can be overridden by your very own settings -module but not limited to it as you can still use the classic approach of passing everything into a +module but not limited to it, as you can still use the classic approach of passing everything into a Esmerald instance directly when instantiating. **Example of classic approach**: @@ -258,7 +258,7 @@ from esmerald import EsmeraldAPISettings from esmerald.conf.enums import EnvironmentType class Development(EsmeraldAPISettings): - app_name: bool = 'My app in dev' + app_name: str = 'My app in dev' environment: str = EnvironmentType.DEVELOPMENT ``` @@ -308,7 +308,7 @@ Those are special objects that allow all the magic of Esmerald to happen. msg = await socket.receive_json() assert msg assert socket - await socket.close( + await socket.close() app = Esmerald(routes=[ @@ -404,7 +404,7 @@ of objects to be passed into one single object. This can be particulary useful t ## Run the application -As mentioned before, we recomment uvicorn for production but it is not mandatory. +As mentioned before, we recommend uvicorn for production but it is not mandatory. **Using uvicorn**: diff --git a/docs/routing/router.md b/docs/routing/router.md index 2b21df5b..f485b1b1 100644 --- a/docs/routing/router.md +++ b/docs/routing/router.md @@ -5,9 +5,8 @@ The Router is the main object that links the whole Esmerald to the [Gateway](./r ## Router class -The router class is composed by many attributes that are by default populated within the application but Esmerald -also allows to add extra [custom routers](#custom-router) as well but another way is to add a -[ChildEsmerald](#child-esmerald-application) app. +The router class is composed by many attributes that are, by default, populated within the application. However, Esmerald +also allows to add extra [custom routers](#custom-router), or alternatively, you can add a [ChildEsmerald](#child-esmerald-application) app. ```python {!> ../docs_src/routing/router/router_class.py!} @@ -32,15 +31,15 @@ All the parameters and defaults are available in the [Router Reference](../refer ## Custom Router Let's assume there are specific **customer** submodules inside a `customers` dedicated file. -There are two way of separating the routes within the application, using [Include](./routes.md#include), +There are three ways of separating the routes within the application, using [Include](./routes.md#include), a [ChildEsmerald](#child-esmerald-application) or by creating another router. Let's focus on the latter. ```python hl_lines="28-35" title="/application/apps/routers/customers.py" {!> ../docs_src/routing/router/customers.py!} ``` -Above you create the `/application/apps/routers/customers.py` with all the information you need. It does not need -to be in one file, you can have a entirely seperate package just to manage the customer, it is up to you. +Above, you created the `/application/apps/routers/customers.py` with all the information you need. It does not need +to be in one file, you can have a entirely separate package just to manage the customer, it is up to you. Now you need to add the new custom router into the main application. @@ -98,13 +97,13 @@ You can add as many `ChildEsmerald` as you desire, there are no limits. {!> ../docs_src/routing/router/childesmerald/nested.py!} ``` -The example above, it is showing that you could even add the same application within nested includes and for each -include you can add specific unique [permissions](../permissions.md), [middlewares](../middleware/middleware.md), -[exception handlers](../exception-handlers.md) and [dependencies](../dependencies.md) which are available on each -instance of the `Include`. The options are endeless. +The example above shows that you could even add the same application within nested includes, and for each +include, you can add specific unique [permissions](../permissions.md), [middlewares](../middleware/middleware.md), +[exception handlers](../exception-handlers.md) and [dependencies](../dependencies.md), which are available on each +instance of the `Include`. The options are endless. !!! Note - In terms of organisation, `ChildEsmerald` has a clean approach to the isolation of responsabilities and allow + In terms of organisation, `ChildEsmerald` has a clean approach to the isolation of responsabilities and allows treating every individual module separately and simply adding it in to the main application in the form of [Include](./routes.md#include). @@ -134,12 +133,12 @@ The `Router` object has some available functionalities that can be useful. requests (HTTP and Websockets). * **middleware** - A list of middleware to run for every request. The middlewares of a Include will be checked from top-down. -* **interceptors** - A list of [interceptors](../interceptors.md). -or Lilya Middleware as they are both converted +* **interceptors** - A list of [interceptors](../interceptors.md) +or Lilya Middleware, as they are both converted internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/). * **dependencies** - A dictionary of string and [Inject](../dependencies.md) instances enable application level dependency injection. -* **exception handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler +* **exception_handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions. @@ -162,7 +161,7 @@ or Lilya Middleware< internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/). * **dependencies** - A dictionary of string and [Inject](../dependencies.md) instances enable application level dependency injection. -* **exception handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler +* **exception_handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions. @@ -187,7 +186,7 @@ or Lilya Middleware< internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/). * **dependencies** - A dictionary of string and [Inject](../dependencies.md) instances enable application level dependency injection. -* **exception handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler +* **exception_handlers** - A dictionary of [exception types](../exceptions.md) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions. * **include_in_schema** - Boolean if this ChildEsmerald should be included in the schema. diff --git a/docs/routing/routes.md b/docs/routing/routes.md index 0ce507f0..53c8abb5 100644 --- a/docs/routing/routes.md +++ b/docs/routing/routes.md @@ -9,12 +9,12 @@ components and packages and imported also inside complex design systems. Esmerald handles with those cases without any kind of issues at all. Lilya routing system alone wasn't enough to serve all the complexities and cases for all sort of -different APIs and systems so Esmerald created its own. +different APIs and systems, so Esmerald created its own. ## Gateway -A Gateway is an extension of the Route really but adds their own logic and handling capabilities as well as its own -validations without compromising the core. +A Gateway is an extension of the Route, really, but adds its own logic and handling capabilities, as well as its own +validations, without compromising the core. ### Gateway and application diff --git a/docs_src/application/app/permissions_and_middlewares.py b/docs_src/application/app/permissions_and_middlewares.py index ccfc55b5..d11cfe26 100644 --- a/docs_src/application/app/permissions_and_middlewares.py +++ b/docs_src/application/app/permissions_and_middlewares.py @@ -99,7 +99,7 @@ async def websocket_endpoint(self, socket: WebSocket) -> None: ) jwt_config = JWTConfig( - signing_key=settings.secret_key_key_key, + signing_key=settings.secret_key, ) diff --git a/docs_src/application/settings/settings_config/example1.py b/docs_src/application/settings/settings_config/example1.py index 0d8de5bb..f7d0f888 100644 --- a/docs_src/application/settings/settings_config/example1.py +++ b/docs_src/application/settings/settings_config/example1.py @@ -7,7 +7,7 @@ class ChildEsmeraldSettings(EsmeraldAPISettings): secret_key: str = "a child secret" -## Create a ChildEsmerald application +# Create a ChildEsmerald application child_app = ChildEsmerald(routes=[...], settings_module=ChildEsmeraldSettings) # Create an Esmerald application diff --git a/docs_src/configurations/template/settings.py b/docs_src/configurations/template/settings.py index 23f81945..aeab6565 100644 --- a/docs_src/configurations/template/settings.py +++ b/docs_src/configurations/template/settings.py @@ -7,7 +7,7 @@ class CustomSettings(EsmeraldAPISettings): @property - def template_config(self) -> "TemplateConfig": + def template_config(self) -> TemplateConfig: """ Initial Default configuration for the StaticFilesConfig. This can be overwritten in another setting or simply override diff --git a/docs_src/settings/custom/base.py b/docs_src/settings/custom/base.py index 791c966d..3e2ffa53 100644 --- a/docs_src/settings/custom/base.py +++ b/docs_src/settings/custom/base.py @@ -10,7 +10,7 @@ class AppSettings(EsmeraldAPISettings): # The default is already production but for this example # we set again the variable - environment: bool = EnvironmentType.PRODUCTION + environment: str = EnvironmentType.PRODUCTION debug: bool = False reload: bool = False diff --git a/docs_src/settings/custom/development.py b/docs_src/settings/custom/development.py index 1e8e8836..72674eb0 100644 --- a/docs_src/settings/custom/development.py +++ b/docs_src/settings/custom/development.py @@ -21,11 +21,11 @@ async def close_database(): ... class DevelopmentSettings(AppSettings): # the environment can be names to whatever you want. - environment: bool = EnvironmentType.DEVELOPMENT + environment: str = EnvironmentType.DEVELOPMENT debug: bool = True reload: bool = True - def __init__(self, *args: Any, **kwds: Any) -> Any: + def __init__(self, *args: Any, **kwds: Any): super().__init__(*args, **kwds) logging_level = logging.DEBUG if self.debug else logging.INFO loggers = ("uvicorn.asgi", "uvicorn.access", "esmerald") diff --git a/docs_src/settings/custom/production.py b/docs_src/settings/custom/production.py index 2174be79..50b5fa8b 100644 --- a/docs_src/settings/custom/production.py +++ b/docs_src/settings/custom/production.py @@ -14,7 +14,7 @@ async def close_database(): ... class ProductionSettings(AppSettings): # the environment can be names to whatever you want. - environment: bool = EnvironmentType.PRODUCTION + environment: str = EnvironmentType.PRODUCTION debug: bool = True reload: bool = False diff --git a/docs_src/settings/custom/testing.py b/docs_src/settings/custom/testing.py index 2543cd76..96d7dedb 100644 --- a/docs_src/settings/custom/testing.py +++ b/docs_src/settings/custom/testing.py @@ -14,7 +14,7 @@ async def close_database(): ... class TestingSettings(AppSettings): # the environment can be names to whatever you want. - environment: bool = EnvironmentType.TESTING + environment: str = EnvironmentType.TESTING debug: bool = True reload: bool = False diff --git a/esmerald/conf/global_settings.py b/esmerald/conf/global_settings.py index a8447ba4..378bcf3e 100644 --- a/esmerald/conf/global_settings.py +++ b/esmerald/conf/global_settings.py @@ -9,7 +9,13 @@ from esmerald import __version__ from esmerald.conf.enums import EnvironmentType -from esmerald.config import CORSConfig, CSRFConfig, OpenAPIConfig, SessionConfig, StaticFilesConfig +from esmerald.config import ( + CORSConfig, + CSRFConfig, + OpenAPIConfig, + SessionConfig, + StaticFilesConfig, +) from esmerald.config.asyncexit import AsyncExitConfig from esmerald.datastructures import Secret from esmerald.interceptors.types import Interceptor @@ -820,7 +826,7 @@ def template_config(self) -> Optional["TemplateConfig"]: class AppSettings(EsmeraldAPISettings): @property - def template_config(self) -> "TemplateConfig": + def template_config(self) -> TemplateConfig: TemplateConfig(directory='templates', engine=MakoTemplateEngine) ``` """ diff --git a/esmerald/core/directives/env.py b/esmerald/core/directives/env.py index 7a6cded2..8ad3f266 100644 --- a/esmerald/core/directives/env.py +++ b/esmerald/core/directives/env.py @@ -31,7 +31,7 @@ class Scaffold: @dataclass class DirectiveEnv: """ - Loads an arbitraty application into the object + Loads an arbitrary application into the object and returns the App. """ @@ -77,7 +77,9 @@ def _get_folders(self, path: Path) -> typing.List[str]: """ return [directory.path for directory in os.scandir(path) if directory.is_dir()] - def _find_app_in_folder(self, path: Path, cwd: Path) -> typing.Union[Scaffold, None]: + def _find_app_in_folder( + self, path: Path, cwd: Path + ) -> typing.Union[Scaffold, None]: """ Iterates inside the folder and looks up to the DISCOVERY_FILES. """ diff --git a/esmerald/core/directives/operations/runserver.py b/esmerald/core/directives/operations/runserver.py index b341d6d4..04f0e58a 100644 --- a/esmerald/core/directives/operations/runserver.py +++ b/esmerald/core/directives/operations/runserver.py @@ -77,8 +77,8 @@ def runserver( Alternatively, if none is passed, Esmerald will perform the application discovery. - It is strongly advised not to run this command in any pther environment but developmentyping. - This was designed to facilitate the development environment and should not be used in pr + It is strongly advised not to run this command in any other environment but development. + This was designed to facilitate the development environment and should not be used in production. How to run: `esmerald runserver` """ @@ -93,12 +93,15 @@ def runserver( try: import uvicorn except ImportError: - raise DirectiveError(detail="Uvicorn needs to be installed to run Esmerald.") from None + raise DirectiveError( + detail="Uvicorn needs to be installed to run Esmerald." + ) from None app = env.app settings = app.settings message = terminal.write_info( - f"Starting {settings.environment} server @ {host}", colour=OutputColour.BRIGHT_CYAN + f"Starting {settings.environment} server @ {host}", + colour=OutputColour.BRIGHT_CYAN, ) terminal.rule(message, align="center") diff --git a/esmerald/parsers.py b/esmerald/parsers.py index 698d9c07..f10e32c5 100644 --- a/esmerald/parsers.py +++ b/esmerald/parsers.py @@ -51,7 +51,7 @@ class BaseModelExtra(BaseModel): class ArbitraryBaseModel(BaseModel): """ - ArbitratyBaseModel that allows arbitrary_types_allowed to be passed. + ArbitraryBaseModel that allows arbitrary_types_allowed to be passed. """ model_config = ConfigDict(arbitrary_types_allowed=True)