diff --git a/.bumpversion.toml b/.bumpversion.toml index 51d6fde..e658893 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -20,9 +20,8 @@ setup_hooks = [] pre_commit_hooks = [] post_commit_hooks = [] - [[tool.bumpversion.files]] -filename = "my_project_template/__init__.py" +filename = "src/my_project_template/__init__.py" search = "__version__ = \"{current_version}\"" replace = "__version__ = \"{new_version}\"" @@ -35,3 +34,8 @@ replace = "version = \"{new_version}\"" filename = "api-spec.yaml" search = "version: {current_version}" replace = "version: {new_version}" + +[[tool.bumpversion.files]] +filename = "Makefile" +search = "VERSION := {current_version}" +replace = "VERSION := {new_version}" diff --git a/.dockerignore b/.dockerignore index 06f2cff..073ea4d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +.git .github .eggs/ build @@ -6,9 +7,9 @@ dist *.egg-info tests venv +.venv __pycache__ -*.pyc *.pyo *.pyd *.output diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 81c7b58..ffafac7 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,10 +12,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error + **Expected behavior** A clear and concise description of what you expected to happen. @@ -23,16 +20,5 @@ A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - **Additional context** Add any other context about the problem here. diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 3078c19..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Format Check - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: psf/black@stable diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 6bfdc01..729d563 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -1,6 +1,3 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - name: BDD and Unit Tests on: @@ -10,24 +7,29 @@ on: branches: [ master ] jobs: - build: - + run-tests: + name: python runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - if [ -f requirements-tests.txt ]; then pip install -r requirements-tests.txt; fi - - name: Test with pytest - run: | - pytest - - name: Run BDD Tests - run: | - behave + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version-file: ".python-version" + + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + # Install a specific version of uv. + version: "0.8.15" + + - name: Install the project + run: uv sync --locked --group=test + + - name: Run pytests + run: uv run pytest + + - name: Run BDD Tests + run: uv run behave diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..91cd797 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,20 @@ +name: CI +on: push +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version-file: ".python-version" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + + # Update output format to enable automatic inline annotations. + - name: Run Ruff + run: ruff check --output-format=github . diff --git a/Dockerfile b/Dockerfile index 735b1f1..845b0cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,45 @@ -FROM python:3.13-slim-trixie - +FROM python:3.13-slim-trixie AS builder LABEL MAINTAINER="Pradeep Bashyal" COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +ENV UV_COMPILE_BYTECODE=1 +ENV UV_LINK_MODE=copy +ENV UV_PYTHON_PREFERENCE=only-managed + +WORKDIR /app +# Install everything except the package +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --locked --no-install-project --group deploy + +# Sync so that Python version is installed +COPY . /app +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --locked --group deploy && uv build + + +# Final Docker Image +FROM python:3.13-slim-trixie + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + WORKDIR /app +# Copy the Python packages +COPY --from=builder /app/.venv /app/.venv + +COPY --from=builder /app/dist/my_project_template-0.0.1-py3-none-any.whl /tmp/ +RUN python3 -m pip install /tmp/my_project_template-0.0.1-py3-none-any.whl + COPY app.py /app/ COPY api.py /app/ COPY api-spec.yaml /app/ -COPY my_project_template /app/my_project_template +COPY run-app.sh /app/ + +# Put the uv built Python packages in the PATH +ENV PYTHONPATH="/app/.venv/lib/python3.13/site-packages/:" # Sync the project into a new environment, asserting the lockfile is up to date COPY pyproject.toml /app/ diff --git a/Makefile b/Makefile index 78e2023..4d950c9 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ lint: ## check style with ruff uv tool run ruff check behave: clean-test ## run the behave tests, generate and serve report - - uv run behave -f allure_behave.formatter:AllureFormatter -o allure_report + uv run behave -f allure_behave.formatter:AllureFormatter -o allure_report allure serve allure_report pytest: clean-test ## run tests quickly with the default Python @@ -86,7 +86,6 @@ docker: docker-build ## build a docker image and run the service sync: clean ## install the package to the active Python's site-packages uv sync --all-groups - pre-commit install install: sync ## Sync pyproject.toml to .venv as well as install tools pre-commit install diff --git a/pyproject.toml b/pyproject.toml index 8ca4686..ad7543b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,9 @@ +[build-system] +requires = ["uv_build>=0.8.15,<0.9.0"] +build-backend = "uv_build" + [project] -name = "nmdp-python-project-template" +name = "my_project_template" version = "0.0.1" description="Python Project Template. Standardized Python project structure for NMDP projects" requires-python = ">=3.13" diff --git a/tests/unit/test_my_project_template.py b/tests/unit/test_my_project_template.py index 8386e38..6806218 100644 --- a/tests/unit/test_my_project_template.py +++ b/tests/unit/test_my_project_template.py @@ -26,6 +26,9 @@ """Tests for `my_project_template` package.""" import pytest +from my_project_template.algorithm.match import slug_match +from my_project_template.model.slug import SLUG +from my_project_template.model.allele import Allele @pytest.fixture @@ -40,3 +43,25 @@ def supported_genes(): def test_content(supported_genes): """Sample pytest test function with the pytest fixture as an argument.""" assert "HLA-A" in supported_genes + + +def test_slug_match_identical_slugs(): + """Test that identical SLUGs match.""" + allele1 = Allele("HLA-A", "HLA-A*01:01") + allele2 = Allele("HLA-A", "HLA-A*02:01") + slug1 = SLUG(allele1, allele2) + slug2 = SLUG(allele1, allele2) + + assert slug_match(slug1, slug2) is True + + +def test_slug_match_different_slugs(): + """Test that different SLUGs do not match.""" + allele1 = Allele("HLA-A", "HLA-A*01:01") + allele2 = Allele("HLA-A", "HLA-A*02:01") + allele3 = Allele("HLA-A", "HLA-A*03:01") + + slug1 = SLUG(allele1, allele2) + slug2 = SLUG(allele1, allele3) + + assert slug_match(slug1, slug2) is False diff --git a/uv.lock b/uv.lock index 403e2b3..6bb4d88 100644 --- a/uv.lock +++ b/uv.lock @@ -486,9 +486,9 @@ wheels = [ ] [[package]] -name = "nmdp-python-project-template" +name = "my-project-template" version = "0.0.1" -source = { virtual = "." } +source = { editable = "." } [package.dev-dependencies] deploy = [