Skip to content

Commit

Permalink
chore: Upgrade python/pytest + migrate to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ducdetronquito committed Nov 12, 2024
1 parent 66f6767 commit af94349
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 244 deletions.
7 changes: 7 additions & 0 deletions .config/mise/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tools]
python = "3.11"
poetry = "latest"

[env]
_.file = '../../.env'
_.python.venv = { path = "../../.venv", create = false }
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
.pytest_cache
.ruff_cache
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

52 changes: 38 additions & 14 deletions .github/workflows/pullrequest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,71 @@ on:
- "master"

jobs:

releasetag:
uses: ZeroGachis/.github/.github/workflows/releasetag.yml@v4

build:
uses: ZeroGachis/.github/.github/workflows/build-image.yml@v1
needs: releasetag
uses: ZeroGachis/.github/.github/workflows/build-image.yml@v4
with:
image_name: nurse
dockerfile_context: .
vault_enabled: false
tailscale_enabled: false
regitry_url: ghcr.io
build-args: |
REQUIREMENTS=dev
secrets: inherit

static-metrics:
needs:
needs:
[
build,
build,
]
uses: ZeroGachis/.github/.github/workflows/run-docker.yml@v1
uses: ZeroGachis/.github/.github/workflows/run-docker.yml@v4
with:
image_url: ${{ needs.build.outputs.image-url }}
workdir: /home/src/nurse
tailscale_enabled: false
vault_enabled: false
workdir: /app
run_command: |
flake8 .
ruff check --diff ./
ruff format --check --diff ./
secrets: inherit


# unit-tests:
# needs:
# [
# build,
# ]
# uses: ZeroGachis/.github/.github/workflows/run-pytest.yml@v4
# with:
# image_url: ${{ needs.build.outputs.image-url }}
# workdir: /app
# directory_to_test: tests/
# env_django_settings_module: todo-make-this-optional
# secrets: inherit

unit-tests:
needs:
needs:
[
build,
build,
]
uses: ZeroGachis/.github/.github/workflows/run-docker-with-db.yml@v1
uses: ZeroGachis/.github/.github/workflows/run-docker.yml@v4
with:
image_url: ${{ needs.build.outputs.image-url }}
workdir: /home/src/nurse
tailscale_enabled: false
vault_enabled: false
workdir: /app
run_command: |
pytest --verbose
enable_test_report: false
pytest
secrets: inherit

detroy:
if: always()
needs:
[
releasetag,
build,
unit-tests,
static-metrics,
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ env/
dist/
nurse.egg-info/
pip-wheel-metadata/
.venv/

# Python
__pycache__/
Expand All @@ -23,3 +24,10 @@ __pycache__/

# Asdf
.tool-versions

# Dev env variables
.env

# Coverage
.coverage
reports/
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fail_fast: true
repos:
- repo: local
hooks:
- id: ruff-check
name: Ruff check
entry: poetry run ruff check
args: [--fix]
language: system
types: [file, python]
- id: ruff-format
name: Ruff format
entry: poetry run ruff format
language: system
types: [file, python]
28 changes: 8 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
FROM python:3.11-bookworm
FROM 007065811408.dkr.ecr.eu-west-3.amazonaws.com/python-3-11:1

RUN \
apt-get -y update \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app

RUN pip3 install --upgrade pip \
&& pip3 install -U setuptools
COPY pyproject.toml poetry.lock poetry.toml ./

RUN pip install poetry
# Poetry complains if no README.md exists
RUN touch README.md

COPY poetry.lock /home/src/nurse/poetry.lock
COPY pyproject.toml /home/src/nurse/pyproject.toml
RUN POETRY_NO_INTERACTION=1 poetry install

WORKDIR /home/src/nurse
COPY . .

ARG REQUIREMENTS=common
ENV REQUIREMENTS $REQUIREMENTS
RUN mkdir requirements
RUN poetry export -f requirements.txt --without-hashes > requirements/$REQUIREMENTS.txt
RUN poetry export -f requirements.txt --without-hashes --with dev > requirements/dev.txt

RUN pip3 install -r requirements/$REQUIREMENTS.txt

COPY . /home/src/nurse
CMD ["bash"]
CMD ["bash"]
9 changes: 3 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
version: '3.0'

services:

nurse:
build:
context: .
args:
- REQUIREMENTS=dev
tty: true
working_dir: /home/src/nurse
working_dir: /app
volumes:
- ./.:/home/src/nurse
- ./.:/app
- /app/.venv
2 changes: 1 addition & 1 deletion nurse/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_service(service_catalog: ServiceCatalog, decorated_obj, param_to_inject:
service = service_catalog._services.get(service_type)
if not service:
raise DependencyError(
f"Dependency `{service_type}` for `{param_to_inject}` was not found."
f"Dependency `{service_type.__name__}` for `{param_to_inject}` was not found."
)

return service
Loading

0 comments on commit af94349

Please sign in to comment.