Skip to content

Repository files navigation

WLSS backend

badge badge badge badge badge

Backend application for Wish List Sharing Service.

Table of Contents

System requirements

First time setup

Run app

Run linters

Run tests

Working with migrations

Deploy

Troubleshooting


To develop this project you need to have the following software installed.

Before start to setup project you have to meet System requirements.

Go to the project root directory.

  1. Set up local environment:
# Set up git user for this repository
source envs/local/dev/scripts/git/iam.sh

# Create virtual environment and install dependencies.
poetry install --with app,lint,test

# Activate virtual environment.
poetry shell
  1. Upgrade pip within virtual environment:
pip install --upgrade pip

To run application you need to do all steps from First time setup section.

  1. Run services and app:
# Create .env file
source envs/local/dev/env.sh

# Run services.
docker compose --file=envs/local/dev/docker-compose.yml up --detach

# Apply migrations.
WLSS_ENV=local/dev alembic upgrade head

# Run development server.
WLSS_ENV=local/dev uvicorn src.app:app --reload
  1. Check application health status:
curl --request GET http://localhost:8000/health

To run linters you need to do all steps from First time setup section.

Linters order below is a preferred way to run and fix them one by one.

Run any linter you need or all of them at once:

# Run mypy.
mypy

# Run ruff.
ruff check api src tests

# Run flake8.
flake8

# Run pylint.
pylint api src tests

To run tests you need to do all steps from First time setup section.

  1. Run services and tests:
# Create .env file
source envs/local/test/env.sh

# Run services.
docker compose --file=envs/local/test/docker-compose.yml up --detach

# Apply migrations.
WLSS_ENV=local/test alembic upgrade head

# Run pytest.
WLSS_ENV=local/test pytest --cov=api --cov=src

Also you can choose one of the following ways of running tests:

  • Tests with html coverage report:
WLSS_ENV=local/test pytest --cov=api --cov=src ; coverage html
  • Tests with execution contexts in report:
WLSS_ENV=local/test pytest --cov=api --cov=src --cov-context=test ; coverage html --show-contexts --no-skip-covered

Following examples will use local/test environment, but you can use any other value for $WLSS_ENV you need.

  • Generate new migration:
WLSS_ENV=local/test alembic revision --autogenerate -m "migration message"
  • Apply all migrations:
WLSS_ENV=local/test alembic upgrade head
  • Apply migrations up to particular revision:
WLSS_ENV=local/test alembic upgrade 746039e79eb3
  • Downgrade certain number of migrations:
WLSS_ENV=local/test alembic downgrade -2
  • Downgrade migrations to particular revision:
WLSS_ENV=local/test alembic upgrade 746039e79eb3
  • Autoformat revision code if you changed it by hand:
black --line-length=120 migrations

Only users with write access are able to deploy.

  1. Fetch the last version of the deployed/qa tag:
git fetch origin +refs/tags/deployed/qa:refs/tags/deployed/qa
  1. Checkout to branch/commit you want to deploy.

  2. Create and push new version of the deployed/qa tag:

git tag --annotate --force deployed/qa --message ''
git push origin deployed/qa --force

Problem:

For mac users, if you have some issues with pylint's spellchecker, for example:

optparse.OptionValueError: option spelling-dict: invalid value: 'en_US', should be in ['']

Solution:

Install enchant system-wide (see this):

brew install enchant

Or if you have an Apple Siliicon Chip (see this), then you should run:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -x86_64 /usr/local/bin/brew install enchant

and then setting the environment variable:

export PYENCHANT_LIBRARY_PATH=/opt/homebrew/lib/libenchant-2.2.dylib

About

Backend app for WLSS.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

Used by

Contributors

Languages