Skip to content

Commit afea0c3

Browse files
Upgrade to Modern Tools (#3)
* 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
1 parent 9414b99 commit afea0c3

21 files changed

+1146
-187
lines changed

.bumpversion.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[tool.bumpversion]
2+
current_version = "0.0.1"
3+
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
4+
serialize = ["{major}.{minor}.{patch}"]
5+
search = "{current_version}"
6+
replace = "{new_version}"
7+
regex = false
8+
ignore_missing_version = false
9+
ignore_missing_files = false
10+
tag = false
11+
sign_tags = false
12+
tag_name = "v{new_version}"
13+
tag_message = "Bump version: {current_version} → {new_version}"
14+
allow_dirty = false
15+
commit = false
16+
message = "Bump version: {current_version} → {new_version}"
17+
moveable_tags = []
18+
commit_args = ""
19+
setup_hooks = []
20+
pre_commit_hooks = []
21+
post_commit_hooks = []
22+
23+
24+
[[tool.bumpversion.files]]
25+
filename = "my_project_template/__init__.py"
26+
search = "__version__ = \"{current_version}\""
27+
replace = "__version__ = \"{new_version}\""
28+
29+
[[tool.bumpversion.files]]
30+
filename = "pyproject.toml"
31+
search = "version = \"{current_version}\""
32+
replace = "version = \"{new_version}\""
33+
34+
[[tool.bumpversion.files]]
35+
filename = "api-spec.yaml"
36+
search = "version: {current_version}"
37+
replace = "version: {new_version}"

.gitignore

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ coverage.xml
5050
*.py,cover
5151
.hypothesis/
5252
.pytest_cache/
53+
.ruff_cache/
5354

5455
# Translations
5556
*.mo
@@ -65,39 +66,16 @@ db.sqlite3-journal
6566
instance/
6667
.webassets-cache
6768

68-
# Scrapy stuff:
69-
.scrapy
70-
7169
# Sphinx documentation
7270
docs/_build/
7371

74-
# PyBuilder
75-
target/
76-
7772
# Jupyter Notebook
7873
.ipynb_checkpoints
7974

8075
# IPython
8176
profile_default/
8277
ipython_config.py
8378

84-
# pyenv
85-
.python-version
86-
87-
# pipenv
88-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91-
# install all needed dependencies.
92-
#Pipfile.lock
93-
94-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95-
__pypackages__/
96-
97-
# Celery stuff
98-
celerybeat-schedule
99-
celerybeat.pid
100-
10179
# SageMath parsed files
10280
*.sage.py
10381

@@ -110,6 +88,9 @@ ENV/
11088
env.bak/
11189
venv.bak/
11290

91+
# Mac
92+
.DS_Store
93+
11394
# IDEs
11495
# Spyder project settings
11596
.spyderproject
@@ -134,3 +115,4 @@ dmypy.json
134115
# behave
135116
pretty.output
136117
allure_report/
118+

.pre-commit-config.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.2.0
4-
hooks:
5-
- id: trailing-whitespace
6-
- id: end-of-file-fixer
7-
- id: check-yaml
8-
- id: check-added-large-files
9-
- repo: https://github.com/psf/black
10-
rev: 22.3.0
11-
hooks:
12-
- id: black
13-
language_version: python3
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.12.12
5+
hooks:
6+
# Run the linter.
7+
- id: ruff-check
8+
types_or: [python, pyi]
9+
args: [--fix]
10+
# Run the formatter.
11+
- id: ruff-format
12+
types_or: [python, pyi]

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
FROM python:3.11-slim-buster
1+
FROM python:3.13-slim-trixie
22

33
LABEL MAINTAINER="Pradeep Bashyal"
44

5-
WORKDIR /app
6-
7-
COPY requirements.txt /app
8-
RUN pip install --no-cache-dir --upgrade pip && \
9-
pip install --no-cache-dir -r requirements.txt
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
106

11-
COPY requirements-deploy.txt /app
12-
RUN pip install --no-cache-dir -r requirements-deploy.txt
7+
WORKDIR /app
138

149
COPY app.py /app/
1510
COPY api.py /app/
1611
COPY api-spec.yaml /app/
1712
COPY my_project_template /app/my_project_template
1813

19-
CMD ["gunicorn" , "--bind", "0.0.0.0:8080", "--worker-tmp-dir", "/dev/shm", "app:app"]
14+
# Sync the project into a new environment, asserting the lockfile is up to date
15+
COPY pyproject.toml /app/
16+
COPY uv.lock /app/
17+
RUN /bin/uv sync --locked --group deploy
18+
19+
CMD [".venv/bin/gunicorn" , "--bind", "0.0.0.0:8080", "--worker-tmp-dir", "/dev/shm", "app:app"]

HISTORY.rst

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

Makefile

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT_NAME := $(shell basename `pwd`)
22
PACKAGE_NAME := my_project_template
3+
VERSION := 0.0.1
34

45
.PHONY: clean clean-test clean-pyc clean-build docs help test test-all
56
.DEFAULT_GOAL := help
@@ -53,56 +54,48 @@ clean-test: ## remove test and coverage artifacts
5354
rm -fr .pytest_cache
5455
rm -fr allure_report
5556

56-
lint: ## check style with flake8
57-
# stop the build if there are Python syntax errors or undefined names \
58-
exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
59-
flake8 $(PACKAGE_NAME) tests --count --select=E9,F63,F7,F82 --show-source --statistics
60-
flake8 $(PACKAGE_NAME) --exit-zero --max-complexity=10 --max-line-length=127 --statistics
57+
lint: ## check style with ruff
58+
uv tool run ruff check
6159

6260
behave: clean-test ## run the behave tests, generate and serve report
63-
- behave -f allure_behave.formatter:AllureFormatter -o allure_report
61+
- uv run behave -f allure_behave.formatter:AllureFormatter -o allure_report
6462
allure serve allure_report
6563

6664
pytest: clean-test ## run tests quickly with the default Python
67-
PYTHONPATH=. pytest
65+
uv run pytest
6866

6967
test: clean-test ## run all(BDD and unit) tests
70-
PYTHONPATH=. pytest
71-
behave
68+
uv run pytest
69+
uv run behave
7270

7371
coverage: ## check code coverage quickly with the default Python
74-
coverage run --source my_project_template -m pytest
72+
coverage run --source $(PACKAGE_NAME) -m pytest
7573
coverage report -m
7674
coverage html
7775
$(BROWSER) htmlcov/index.html
7876

7977
dist: clean ## builds source and wheel package
80-
python setup.py sdist
81-
python setup.py bdist_wheel
78+
uv build
8279
ls -l dist
8380

8481
docker-build: ## build a docker image for the service
85-
docker build -t my-project-template-service:0.0.1 .
82+
docker build -t $(PACKAGE_NAME):$(VERSION) .
8683

8784
docker: docker-build ## build a docker image and run the service
88-
docker run --name my-project-template -p 8080:8080 my-project-template-service:0.0.1
89-
90-
install: clean ## install the package to the active Python's site-packages
91-
pip install --upgrade pip setuptools
92-
python setup.py install
93-
pip install -r requirements.txt
94-
pip install -r requirements-tests.txt
95-
pip install -r requirements-dev.txt
96-
pip install -r requirements-deploy.txt
85+
docker run --name $(PACKAGE_NAME) -p 8080:8080 $(PACKAGE_NAME):$(VERSION)
86+
87+
sync: clean ## install the package to the active Python's site-packages
88+
uv sync --all-groups
89+
pre-commit install
90+
91+
install: sync ## Sync pyproject.toml to .venv as well as install tools
9792
pre-commit install
93+
uv tool install bump-my-version
9894

9995
venv: ## creates a Python3 virtualenv environment in venv
100-
python3 -m venv venv --prompt $(PROJECT_NAME)-venv
101-
@echo "====================================================================="
102-
@echo "To activate the new virtual environment, execute the following from your shell"
103-
@echo "source venv/bin/activate"
96+
uv venv --prompt $(PROJECT_NAME)-venv
10497

10598
activate: ## activate a virtual environment. Run `make venv` before activating.
10699
@echo "====================================================================="
107100
@echo "To activate the new virtual environment, execute the following from your shell"
108-
@echo "source venv/bin/activate"
101+
@echo "source .venv/bin/activate"

app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
app = connexion.App(__name__)
77
application = app.app
8-
api = app.add_api("api-spec.yaml")
8+
app.add_api("api-spec.yaml")
99

1010

1111
@app.route("/")
1212
def index():
13-
return redirect(api.base_path + "/ui")
13+
return redirect("/ui")
1414

1515

1616
if __name__ == "__main__":
17-
app.run(port=8080, debug=True)
17+
app.run(port=8080)

pyproject.toml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[project]
2+
name = "nmdp-python-project-template"
3+
version = "0.0.1"
4+
description="Python Project Template. Standardized Python project structure for NMDP projects"
5+
requires-python = ">=3.13"
6+
dependencies = [
7+
]
8+
authors = [
9+
{name = "Pradeep Bashyal", email = "[email protected]"},
10+
{name = "NMDP Person"},
11+
{email = "[email protected]"},
12+
]
13+
maintainers = [
14+
{name = "Pradeep Bashyal", email = "[email protected]"},
15+
]
16+
readme = "README.md"
17+
license = "LGPL-3.0-only"
18+
keywords = ["HLA", "matching"]
19+
classifiers = [
20+
# Prevent a package from being uploaded to PyPI
21+
# "Private :: Do Not Upload"
22+
23+
# How mature is this project? Common values are
24+
# 3 - Alpha
25+
# 4 - Beta
26+
# 5 - Production/Stable
27+
"Development Status :: 2 - Pre-Alpha",
28+
29+
# Indicate who your project is intended for
30+
"Intended Audience :: Developers",
31+
"Topic :: Software Development :: Build Tools",
32+
33+
# Specify the Python versions you support here.
34+
"Programming Language :: Python :: 3.13",
35+
"Programming Language :: Python :: 3.14",
36+
]
37+
38+
[project.urls]
39+
Homepage = "https://nmdp-bioinformatics.org/"
40+
Documentation = "https://github.com/nmdp-bioinformatics/nmdp-python-project-template/README.md"
41+
Repository = "https://github.com/nmdp-bioinformatics/nmdp-python-project-template"
42+
Issues = "https://github.com/nmdp-bioinformatics/nmdp-python-project-template/issues"
43+
Changelog = "https://github.com/nmdp-bioinformatics/nmdp-python-project-template/blob/master/CHANGELOG.md"
44+
45+
[dependency-groups]
46+
dev = [
47+
"pre-commit>=4.2.0",
48+
"ruff>=0.11.11",
49+
"allure-behave==2.15.0",
50+
"coverage==7.10.6",
51+
]
52+
53+
test = [
54+
"pytest==8.4.2",
55+
"behave==1.3.3",
56+
"pyhamcrest==2.1.0",
57+
]
58+
59+
deploy=[
60+
"connexion[swagger-ui,flask,uvicorn]==3.2.0",
61+
"gunicorn==23.0.0"
62+
]
63+
64+
[tool.pytest.ini_options]
65+
minversion = "6.0"
66+
addopts = "-ra -q"
67+
testpaths = [
68+
"tests",
69+
]
70+
71+
[tool.ruff]
72+
exclude = [".git", ".venv", "tests",]

requirements-deploy.txt

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

0 commit comments

Comments
 (0)