Skip to content

Latest commit

 

History

History

backend

Wayat Backend

Run the application

In this section you will find an overview on how to execute and configure the project.

Dependencies

Dependencies are automatically managed by Poetry

To install dependencies run

poetry install

in same folder where your .toml file is located. Poetry will take care of:

  • Installing the required Python interpreter
  • Installing all the libraries and modules
  • Creating the virtual environment for you

Refer to this link to configure Poetry on PyCharm

Running on local

You can launch the uvicorn server programmatically running directly the main.py file.

python main.py

It is also possible to start the uvicorn live directly server with the command:

uvicorn main:api --reload
  • main: the file main.py (the Python "module").
  • app: the object created inside of main.py with the line app = FastAPI().
  • --reload: make the server restart after code changes. Only use for development.

Run Tests with coverage

You can run all test scenarios using:

python -m coverage run -m unittest

To display the coverage results:

coverage report

or with a nicer report as html page:

coverage html

Run Type Checking tests

mypy app 

Environment Configuration

You can use Pydantic Settings to handle the settings or configurations for your application, with all the power of Pydantic models. The project uses Dependency Injection for managing dependencies across the application and easy mocking for testing.

Create an .env file for each environment configuration. The use of @lru_cache() lets you avoid reading the dotenv file again and again for each request, while allowing you to override it during testing.

Even when using a dotenv file, the application will still read environment variables as well as the dotenv file, environment variables will always take priority over values loaded from a dotenv file.

You can also specify the environment when launching the server. Corresponding .env file will be automatically loaded.

Settings and environment variables are managed by Pydantic, refer to the documentation for more info.

ENV=PROD uvicorn main:app --reload
ENV=PROD python main.py

Host & Port Configuration

The Port and Hosting configuration can be set directly on the .env file if launching the main.py file.

However, this configuration is related with the uvicorn server itself and can also be set with the --port [int] flag.

Refer to the uvicorn documentation for more info.

Logging Configuration

The application uses the default logging module.

To use it inside an specific module init it first with the command:

logger = logging.getLogger(__name__)

You can use the name variable to take the current file name as the default or specify a custom module name manually.

Configure the logging properties in the logging.yaml file. You can find more information in the logging documentation.

Git Management

The Wayat repository has devon4py as a subtree prefixed at wayat/backend. This allows us to bring new changes in the framework to the project easily. To do so, first we need to add devon4py as a remote:

git remote add devon4py https://github.com/devonfw-forge/devon4py.git

Once we have added the remote, we can bring new changes that were made in the `devon4py' repository by running:

git pull -s subtree --allow-unrelated-histories --no-commit --squash devon4py main

This will bring all the changes but won't commit them, so that we can decide what to merge in a new unique commit.