Skip to content

Commit

Permalink
Small updates README and script
Browse files Browse the repository at this point in the history
  • Loading branch information
gkodrzycki committed Jul 24, 2024
1 parent 141940a commit 9d7e64f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
- name: Run pylint
run: |
poetry run pylint **/*.py
poetry run pylint --recursive y .
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lint:
bash lint.sh .
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <path to file>`
* isort - to run use `isort <path to file>`
* pylint - to run use `pylint <path to file>`

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.
Expand Down
6 changes: 6 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo "LINTING WITH BLACK"
poetry run black $1
echo "LINTING WITH ISORT"
poetry run isort $1
echo "LINTING WITH pylint"
poetry run pylint --recursive y $1
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/controller/users.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9d7e64f

Please sign in to comment.