Skip to content

Commit 160903e

Browse files
Upgrade to Modern Python (#4)
* Created pyproject.toml and removed setup.py * Remove requirement*.txt files * Add 'Bump My Version' config * Update all the versions to the latest * Make flask work with api-spec * Docker support - Use Python 3.13 - Update Dockerfile to use uv - Update docker targets in Makefile * Removed HISTORY file * package in src/ and Docker build - Moved package under src/ - Dockerfile builds image * Update dockerfile and project * Update all the versions to the latest Fix Conflicts * Make flask work with api-spec * Use uv in GitHub Action * Use ruff instead of black in CI
1 parent afea0c3 commit 160903e

File tree

10 files changed

+117
-41
lines changed

10 files changed

+117
-41
lines changed

.bumpversion.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ setup_hooks = []
2020
pre_commit_hooks = []
2121
post_commit_hooks = []
2222

23-
2423
[[tool.bumpversion.files]]
25-
filename = "my_project_template/__init__.py"
24+
filename = "src/my_project_template/__init__.py"
2625
search = "__version__ = \"{current_version}\""
2726
replace = "__version__ = \"{new_version}\""
2827

@@ -35,3 +34,8 @@ replace = "version = \"{new_version}\""
3534
filename = "api-spec.yaml"
3635
search = "version: {current_version}"
3736
replace = "version: {new_version}"
37+
38+
[[tool.bumpversion.files]]
39+
filename = "Makefile"
40+
search = "VERSION := {current_version}"
41+
replace = "VERSION := {new_version}"

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.git
12
.github
23
.eggs/
34
build
@@ -6,9 +7,9 @@ dist
67
*.egg-info
78
tests
89
venv
10+
.venv
911

1012
__pycache__
11-
*.pyc
1213
*.pyo
1314
*.pyd
1415
*.output

.github/workflows/black.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/python-tests.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: BDD and Unit Tests
52

63
on:
@@ -10,24 +7,29 @@ on:
107
branches: [ master ]
118

129
jobs:
13-
build:
14-
10+
run-tests:
11+
name: python
1512
runs-on: ubuntu-latest
1613

1714
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python 3.9
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: 3.9
23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27-
if [ -f requirements-tests.txt ]; then pip install -r requirements-tests.txt; fi
28-
- name: Test with pytest
29-
run: |
30-
pytest
31-
- name: Run BDD Tests
32-
run: |
33-
behave
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version-file: ".python-version"
21+
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v6
24+
with:
25+
# Install a specific version of uv.
26+
version: "0.8.15"
27+
28+
- name: Install the project
29+
run: uv sync --locked --group=test
30+
31+
- name: Run pytests
32+
run: uv run pytest
33+
34+
- name: Run BDD Tests
35+
run: uv run behave

.github/workflows/ruff.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
on: push
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: Install Python
9+
uses: actions/setup-python@v5
10+
with:
11+
python-version-file: ".python-version"
12+
13+
- name: Install dependencies
14+
run: |
15+
python -m pip install --upgrade pip
16+
pip install ruff
17+
18+
# Update output format to enable automatic inline annotations.
19+
- name: Run Ruff
20+
run: ruff check --output-format=github .

Dockerfile

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
1-
FROM python:3.13-slim-trixie
2-
1+
FROM python:3.13-slim-trixie AS builder
32
LABEL MAINTAINER="Pradeep Bashyal"
43

54
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
65

6+
ENV UV_COMPILE_BYTECODE=1
7+
ENV UV_LINK_MODE=copy
8+
ENV UV_PYTHON_PREFERENCE=only-managed
9+
10+
WORKDIR /app
11+
# Install everything except the package
12+
RUN --mount=type=cache,target=/root/.cache/uv \
13+
--mount=type=bind,source=uv.lock,target=uv.lock \
14+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15+
uv sync --locked --no-install-project --group deploy
16+
17+
# Sync so that Python version is installed
18+
COPY . /app
19+
RUN --mount=type=cache,target=/root/.cache/uv \
20+
uv sync --locked --group deploy && uv build
21+
22+
23+
# Final Docker Image
24+
FROM python:3.13-slim-trixie
25+
26+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
27+
728
WORKDIR /app
829

30+
# Copy the Python packages
31+
COPY --from=builder /app/.venv /app/.venv
32+
33+
COPY --from=builder /app/dist/my_project_template-0.0.1-py3-none-any.whl /tmp/
34+
RUN python3 -m pip install /tmp/my_project_template-0.0.1-py3-none-any.whl
35+
936
COPY app.py /app/
1037
COPY api.py /app/
1138
COPY api-spec.yaml /app/
12-
COPY my_project_template /app/my_project_template
39+
COPY run-app.sh /app/
40+
41+
# Put the uv built Python packages in the PATH
42+
ENV PYTHONPATH="/app/.venv/lib/python3.13/site-packages/:"
1343

1444
# Sync the project into a new environment, asserting the lockfile is up to date
1545
COPY pyproject.toml /app/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ lint: ## check style with ruff
5858
uv tool run ruff check
5959

6060
behave: clean-test ## run the behave tests, generate and serve report
61-
- uv run behave -f allure_behave.formatter:AllureFormatter -o allure_report
61+
uv run behave -f allure_behave.formatter:AllureFormatter -o allure_report
6262
allure serve allure_report
6363

6464
pytest: clean-test ## run tests quickly with the default Python

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
[build-system]
2+
requires = ["uv_build>=0.8.15,<0.9.0"]
3+
build-backend = "uv_build"
4+
15
[project]
2-
name = "nmdp-python-project-template"
6+
name = "my_project_template"
37
version = "0.0.1"
48
description="Python Project Template. Standardized Python project structure for NMDP projects"
59
requires-python = ">=3.13"

tests/unit/test_my_project_template.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"""Tests for `my_project_template` package."""
2727

2828
import pytest
29+
from my_project_template.algorithm.match import slug_match
30+
from my_project_template.model.slug import SLUG
31+
from my_project_template.model.allele import Allele
2932

3033

3134
@pytest.fixture
@@ -40,3 +43,25 @@ def supported_genes():
4043
def test_content(supported_genes):
4144
"""Sample pytest test function with the pytest fixture as an argument."""
4245
assert "HLA-A" in supported_genes
46+
47+
48+
def test_slug_match_identical_slugs():
49+
"""Test that identical SLUGs match."""
50+
allele1 = Allele("HLA-A", "HLA-A*01:01")
51+
allele2 = Allele("HLA-A", "HLA-A*02:01")
52+
slug1 = SLUG(allele1, allele2)
53+
slug2 = SLUG(allele1, allele2)
54+
55+
assert slug_match(slug1, slug2) is True
56+
57+
58+
def test_slug_match_different_slugs():
59+
"""Test that different SLUGs do not match."""
60+
allele1 = Allele("HLA-A", "HLA-A*01:01")
61+
allele2 = Allele("HLA-A", "HLA-A*02:01")
62+
allele3 = Allele("HLA-A", "HLA-A*03:01")
63+
64+
slug1 = SLUG(allele1, allele2)
65+
slug2 = SLUG(allele1, allele3)
66+
67+
assert slug_match(slug1, slug2) is False

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)