Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staging to main #54

Merged
merged 12 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,35 @@ jobs:
- name: Checkout repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Install poetry, isort, black
run: pipx install poetry isort black
- name: Install poetry
run: pipx install poetry

- name: View poetry, isort, black versions
run: |
poetry --version
isort --version-number
black --version
- name: View poetry
run: poetry --version

- name: 🐍 Set up Python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c
with:
python-version: 3.12
cache: "poetry"

- name: Add Poe the Poet plugin
run: poetry self add 'poethepoet[poetry_plugin]'

- name: Install dependencies
run: poetry install --no-root
run: poetry install --no-root --with dev,lint,test

- name: Python Lint (isort/black)
run: |
isort --check-only --quiet .
black --check .
- name: Python Format (autoflake/isort/black)
run: poetry poe formatters

- name: Python Lint (pylint)
run: poetry poe pylint

- name: Python Typecheck (mypy)
run: poetry poe typings

- name: Run tests
run: poetry run pytest -rpP
run: poetry poe tests

build:
name: 🐳 Build and publish docker images
Expand Down
35 changes: 26 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
# Pre-commit hooks
repos:
# Execute external scripts
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
hooks:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.0
# Execute local scripts
- repo: local
hooks:
- id: black
language_version: python3.12
- id: run-formatter
name: Run formatter
entry: poetry poe formatters
language: system
pass_filenames: false
stages: [pre-commit, pre-push]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
language_version: python3.12
- id: run-linter
name: Run linter
entry: poetry poe pylint
language: system
pass_filenames: false
stages: [pre-commit, pre-push]
- id: run-typings
name: Run typings
entry: poetry poe typings
language: system
pass_filenames: false
stages: [pre-commit, pre-push]
- id: run-tests
name: Run tests
entry: poetry poe tests
language: system
pass_filenames: false
stages: [pre-push]
10 changes: 10 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=

[MESSAGES CONTROL]
# https://pylint.readthedocs.io/en/latest/user_guide/checkers/features.html
disable=all,E0401,E0611,E1101,E1102,E1123
enable=F,E
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.2
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.python",
"Gruntfuggly.todo-tree"
]
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
}
},
"editor.formatOnSave": true,
"isort.args": ["--profile", "black"]
"black-formatter.args": ["--line-length", "120", "--target-version", "py312"],
"isort.args": ["--settings-file", "${workspaceFolder}/pyproject.toml"],
"pylint.args": ["--rcfile", "${workspaceFolder}/.pylintrc"],
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
8 changes: 4 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.1-slim
FROM python:3.12.2-slim

# Set the working directory to /code.
WORKDIR /code
Expand All @@ -16,7 +16,7 @@ RUN pip install --no-cache-dir poetry

# Use Poetry to install dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root
&& poetry install --no-interaction --no-ansi --no-root --with dev,lint,test

# Make port 8081 available to the world outside this container
EXPOSE 8081
Expand All @@ -26,6 +26,6 @@ HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
CMD curl -f http://localhost:8081/health || exit 1

# Run the uvicorn command, telling it to use the app object imported from app.main.
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8081", "--reload", "--reload-exclude", "app/test_main.py"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8081", "--reload", "--reload-exclude", "tests/*.py"]

# CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8081" "--reload", "--reload-exclude", "app/test_main.py"]
# CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8081" "--reload", "--reload-exclude", "tests/*.py"]
4 changes: 2 additions & 2 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://fastapi.tiangolo.com/deployment/docker/#docker-image-with-poetry

# First stage
FROM python:3.12.1-slim as requirements-stage
FROM python:3.12.2-slim as requirements-stage

# Set /tmp as the current working directory.
WORKDIR /tmp
Expand All @@ -16,7 +16,7 @@ COPY ./pyproject.toml ./poetry.lock* /tmp/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

# This is the final stage, anything here will be preserved in the final container image.
FROM python:3.12.1-slim
FROM python:3.12.2-slim

# Install gcc and other dependencies
RUN apt-get update && apt-get install -y \
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://fastapi.tiangolo.com/deployment/docker/#docker-image-with-poetry

# First stage
FROM python:3.12.1-slim as requirements-stage
FROM python:3.12.2-slim as requirements-stage

# Set /tmp as the current working directory.
WORKDIR /tmp
Expand All @@ -16,7 +16,7 @@ COPY ./pyproject.toml ./poetry.lock* /tmp/
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

# This is the final stage, anything here will be preserved in the final container image.
FROM python:3.12.1-slim
FROM python:3.12.2-slim

# Install gcc and other dependencies
RUN apt-get update && apt-get install -y \
Expand Down
58 changes: 39 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ Table of Contents:
- [Python virtual environment](#python-virtual-environment)
- [Installing dependencies](#installing-dependencies)
- [Virtual environment sanity check](#virtual-environment-sanity-check)
- [Poe the Poet poetry plugin](#poe-the-poet-poetry-plugin)
- [Installing git hooks](#installing-git-hooks)
- [Running the project](#running-the-project)
- [Running the project](#running-the-project)
- [Running tests](#running-tests)
- [Docker](#docker)
- [App only](#app-only)
- [With Supabase](#with-supabase)
- [Interactive API docs](#interactive-api-docs)
- [Running tests](#running-tests)
- [Contribution Guidelines](#contribution-guidelines)
- [Deployment](#deployment)

Expand All @@ -38,13 +39,14 @@ Table of Contents:

In `/docker`, create a copy of `.env.example` as `.env`.


### Python virtual environment

#### Installing dependencies

```sh
poetry config virtualenvs.in-project true # OPTIONAL
poetry install --sync --no-root
poetry install --sync --no-root --with dev,lint,test
```

**Note**: Ensure that the python interpreter in your IDE is set to the newly created virtual environment by poetry. If you have not modified poetry configuration, you can find the virtual environment location as stated [here](https://python-poetry.org/docs/configuration/#cache-directory).
Expand All @@ -58,19 +60,43 @@ poetry install --sync --no-root
- Run `poetry shell` <u> ***OR*** </u>
- Execute the `/Scripts/Activate` script from the virtual environment located [here](https://python-poetry.org/docs/configuration/#cache-directory).

#### Installing git hooks

Run this command in the python environment.
#### Poe the Poet poetry plugin

```sh
poetry self add 'poethepoet[poetry_plugin]'
```

1. Check available tasks:
```sh
poetry poe
```
2. Execute a task:
```sh
poetry poe <task-name>
```
For example, running the project formatters:
```sh
poetry poe formatters
```

#### Installing git hooks

```sh
pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-commit
poetry poe git-hooks-setup
```

#### Running the project
### Running the project

- Open up a terminal in your IDE.
- Run `python run.py` to start the server.
- Open your browser at `http://localhost:8081`.
- Open your browser at [`http://localhost:8081`](http://localhost:8081).

### Running tests

```sh
poetry poe tests
```

### Docker

Expand All @@ -84,7 +110,7 @@ pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-c
```sh
docker run --name backend-dev --publish 8081:8081 backend-dev --detach
```
- Open your browser at `http://localhost/8081`.
- Open your browser at [`http://localhost:8081`](http://localhost:8081).

#### With Supabase

Expand All @@ -94,23 +120,17 @@ pre-commit install --hook-type commit-msg --hook-type pre-push --hook-type pre-c
docker compose --file compose.dev.yaml up --detach
```
- Open your browser at
- `http://localhost/8081` for app
- `http://localhost/8000` for supabase dashboard
- [`http://localhost:8081`](http://localhost:8081) for app
- [`http://localhost:8000`](http://localhost:8000) for supabase dashboard
- Username: `supabase`
- Password: `this_password_is_insecure_and_should_be_updated`

For other docker commands, see [useful_commands.md](./useful_commands.md)

### Interactive API docs

- Once the server is running, open your browser at `http://localhost/docs`.
- Alternate docs can be found at `http://localhost/redoc`, provided by [redoc](https://github.com/Redocly/redoc).

### Running tests

```sh
poetry run pytest -rpP
```
- Once the server is running, open your browser at [`http://localhost/docs`](http://localhost/docs).
- Alternate docs can be found at [`http://localhost/redoc`](http://localhost/redoc), provided by [redoc](https://github.com/Redocly/redoc).

### Contribution Guidelines

Expand Down
4 changes: 3 additions & 1 deletion app/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Built-in
from datetime import datetime


METADATA_DESCRIPTION = """
Slick Telemetry backend written in python with fastf1. 🏎

Expand Down Expand Up @@ -31,4 +33,4 @@
MIN_SUPPORTED_SESSION = 1
MAX_SUPPORTED_SESSION = 5

DEFAULT_SESSION_FOR_RESULTS = 5 # race
DEFAULT_SESSION = 5 # race
Loading
Loading