From 5dc991925c7639c6fdc69957510d0210d7517083 Mon Sep 17 00:00:00 2001 From: Grzegorz Kodrzycki Date: Wed, 24 Jul 2024 14:20:28 +0200 Subject: [PATCH] Small updates README and script --- .github/workflows/lint.yml | 2 +- Makefile | 15 +++++++++++ README.md | 52 +++++++++++++++++++++++++++----------- poetry.lock | 6 ++--- pyproject.toml | 2 +- src/controller/users.py | 2 +- 6 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 52048e7..cc7c815 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,4 +38,4 @@ jobs: - name: Run pylint run: | - poetry run pylint **/*.py + poetry run pylint --recursive y . diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5f30a9 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: lint black isort pylint + +lint: black isort pylint + +black: + @echo "LINTING WITH BLACK" + @poetry run black . + +isort: + @echo "LINTING WITH ISORT" + @poetry run isort . + +pylint: + @echo "LINTING WITH PYLINT" + @poetry run pylint --recursive y . diff --git a/README.md b/README.md index cff201c..f961be9 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,31 @@ A simple Python project to get you started with web development and testing usin - Docker Compose - Poetry +## Overview +- [Getting started](#getting-started) + - [Clone the repository](#clone-the-repository) + - [Basic env](#ask-for-the-env-file-to-the-project-owner-or-use-postgres-default-values-in-the-env-file) +- [Setup](#setup) + - [Virtual environment](#create-a-virtual-environment-and-install-the-dependencies) + - [Docker setup](#build-the-docker-image-and-run-the-containers) + - [Testing](#testing) + - [Stopping containers](#stop-the-containers) +- [Database](#database) + - [Database changes](#creating-or-updating-tables-in-database) + - [Migrations](#creating-migrations) +- [Linting](#linting) +- [Github actions](#github-actions) +- [License](#license) + ## Getting Started -### Clone the repository +#### Clone the repository ```bash git clone https://github.com/yourusername/hackathon-starter.git cd hackathon-starter ``` -### Ask for the `.env` file to the project owner, or use postgres default values in the `.env` file: +#### Ask for the `.env` file to the project owner, or use postgres default values in the `.env` file: ```bash DB_USER=postgres @@ -26,49 +42,55 @@ DB_HOST=db DB_NAME=postgres DB_PORT=5432 ``` - -### Create a virtual environment and install the dependencies +### Setup +#### Create a virtual environment and install the dependencies ```bash poetry shell ``` -### Build the Docker image and run the containers +#### Build the Docker image and run the containers ```bash docker compose up --build ``` -### Testing +#### Testing ```bash pytest test/test_api.py # to test the API -docker exec hackathon-starter_web_1 poetry run pytest tests/test_database.py # to test the database inside the container +docker exec hackathon-starter-web-1 poetry run pytest tests/test_database.py # to test the database inside the container ``` -### Stop the containers +Or run all tests with `docker exec -it hackathon-starter-web-1 pytest +` + +#### Stop the containers ```bash docker compose down ``` - -### Creating or updating tables in database +### Database +#### Creating or updating tables in database To create new table in database just create needed class in `src/model/tables.py` similar to `Example` class. \ If you want to change table, just look for your table in `src/model/tables.py` and do needed changes. \ After creating or updating tables create new migration. -### Creating migrations +#### Creating migrations To create new migration simply run ``` alembic revision --autogenerate -m "example comment" alembic upgrade head ``` -### Linting +#### Linting We are using following tools: -* black - to run use `black ` -* isort - to run use `isort ` +* black - to run use `make black` +* isort - to run use `make isort` +* pylint - to run use `make pylint` + +If you want to lint every file using all at once you can also run `make lint` -### GitHub Actions +#### GitHub Actions This project uses GitHub Actions for CI. The workflow is defined in `.github/workflows/main.yml`. It sets up a Python environment, installs the dependencies, runs Docker Compose, and runs the tests. diff --git a/poetry.lock b/poetry.lock index e245fb4..dfa0277 100644 --- a/poetry.lock +++ b/poetry.lock @@ -546,13 +546,13 @@ files = [ [[package]] name = "importlib-metadata" -version = "8.0.0" +version = "8.1.0" description = "Read metadata from Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "importlib_metadata-8.0.0-py3-none-any.whl", hash = "sha256:15584cf2b1bf449d98ff8a6ff1abef57bf20f3ac6454f431736cd3e660921b2f"}, - {file = "importlib_metadata-8.0.0.tar.gz", hash = "sha256:188bd24e4c346d3f0a933f275c2fec67050326a856b9a359881d7c2a697e8812"}, + {file = "importlib_metadata-8.1.0-py3-none-any.whl", hash = "sha256:3cd29f739ed65973840b068e3132135ce954c254d48b5b640484467ef7ab3c8c"}, + {file = "importlib_metadata-8.1.0.tar.gz", hash = "sha256:fcdcb1d5ead7bdf3dd32657bb94ebe9d2aabfe89a19782ddc32da5041d6ebfb4"}, ] [package.dependencies] diff --git a/pyproject.toml b/pyproject.toml index 9d4e353..0d49b45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ line-length = 120 profile = "black" [tool.pylint] -ignore = ["alembic"] +ignore = ["alembic","__init__.py"] max-line-length = 120 [tool.pylint.messages_control] diff --git a/src/controller/users.py b/src/controller/users.py index bc3fb4f..4c87e33 100644 --- a/src/controller/users.py +++ b/src/controller/users.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException, Request +from fastapi import APIRouter from fastapi.templating import Jinja2Templates from src.model.users import User