Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ducdetronquito committed Nov 12, 2024
1 parent 66f6767 commit b8b78dc
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 240 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
65 changes: 51 additions & 14 deletions .github/workflows/pullrequest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,84 @@ 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 ./
echo "import nurse"
python -c "import nurse"
env | sort
python -c "import sys; print(sys.path)"
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
echo "root dir"
ls -al
echo "nurse dir"
ls -al nurse
echo "import nurse"
python -c "import nurse"
env | sort
python -c "import sys; print(sys.path)"
echo "tests"
pytest --verbose --cov --junit-xml reports/unit_tests_results.xml tests/
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
27 changes: 15 additions & 12 deletions tests/test_api.py → nurse/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from unittest import TestCase
import nurse
import pytest

from nurse.exceptions import DependencyError
import asyncio


class TestServe:
def setup(self):
class TestServe(TestCase):
def tearDown(self):
super().tearDown()
nurse.clear()

def test_can_inject_a_dependency(self):
Expand Down Expand Up @@ -44,7 +46,9 @@ class Game:
game = Game()
assert game.player.name == "Igor"

def test_cannot_serve_a_dependency_if_it_does_not_subclass_the_provided_interface(self):
def test_cannot_serve_a_dependency_if_it_does_not_subclass_the_provided_interface(
self,
):
class User:
@property
def name(self):
Expand All @@ -67,8 +71,9 @@ def get_name(self):
return self.name


class TestInjectMethod:
def setup(self):
class TestInjectMethod(TestCase):
def tearDown(self):
super().tearDown()
nurse.clear()

def test_methods_with_only_dependency_args(self):
Expand All @@ -95,8 +100,7 @@ def foo(service):
pass

with pytest.raises(
DependencyError,
message="Args `service` must be typed to be injected."
DependencyError, match="Args `service` must be typed to be injected."
):
foo()

Expand All @@ -107,12 +111,11 @@ def foo(service: ServiceDependency):

with pytest.raises(
DependencyError,
message="Dependency `ServiceDependency` for `service` arg was not found."
match="Dependency `ServiceDependency` for `service` was not found.",
):
foo()

def test_async_method(self):

@nurse.inject("service")
async def foo(service: ServiceDependency):
return service.get_name()
Expand All @@ -124,9 +127,9 @@ async def foo(service: ServiceDependency):
assert res == "Leroy Jenkins"


class TestGet:

def setup(self):
class TestGet(TestCase):
def tearDown(self):
super().tearDown()
nurse.clear()

def test_retrieve_service(self):
Expand Down
Loading

0 comments on commit b8b78dc

Please sign in to comment.