Skip to content

Commit 4af7f17

Browse files
committed
build: add python boilerplate
1 parent 8ddb4a0 commit 4af7f17

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
lint:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v6
24+
with:
25+
enable-cache: true
26+
27+
- name: Install dependencies
28+
run: uv sync --extra dev
29+
30+
- name: Check style
31+
run: uv run ruff check && uv run ruff format --check
32+
precommit_hooks:
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
cmd:
37+
- "end-of-file-fixer"
38+
- "trailing-whitespace"
39+
- "mixed-line-ending"
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Set up Python 3.12
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: 3.12
47+
48+
- uses: pre-commit/[email protected]
49+
with:
50+
extra_args: ${{ matrix.cmd }} --all-files

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0 # pre-commit-hooks version
4+
hooks:
5+
- id: check-added-large-files
6+
- id: detect-private-key
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
exclude: "^docs/source/_templates/.*\\.rst"
10+
- id: check-merge-conflict
11+
- id: detect-aws-credentials
12+
args: [ --allow-missing-credentials ]
13+
- id: mixed-line-ending
14+
args: [ --fix=lf ]
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: v0.12.8 # ruff version
17+
hooks:
18+
- id: ruff-format
19+
- id: ruff
20+
args: [ --fix, --exit-non-zero-on-fix ]
21+
minimum_pre_commit_version: 4.2.0

Makefile

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Makefile for Python project
2+
3+
.DELETE_ON_ERROR:
4+
.PHONY: FORCE
5+
.PRECIOUS:
6+
.SUFFIXES:
7+
8+
SHELL:=/bin/bash -e -o pipefail
9+
SELF:=$(firstword $(MAKEFILE_LIST))
10+
11+
PKG=vlm
12+
PKGD=$(subst .,/,${PKG})
13+
PYV:=3.11
14+
VEDIR=venv/${PYV}
15+
16+
UNAME = $(shell uname)
17+
ifeq (${UNAME},Darwin)
18+
_XRM_R:=
19+
else
20+
_XRM_R:=r
21+
endif
22+
XRM=xargs -0${_XRM_R} rm
23+
24+
############################################################################
25+
#= BASIC USAGE
26+
default: help
27+
28+
#=> help -- display this help message
29+
help:
30+
@sbin/makefile-extract-documentation "${SELF}"
31+
32+
33+
############################################################################
34+
#= SETUP, INSTALLATION, PACKAGING
35+
36+
#=> venv: make a Python 3 virtual environment & install basic dependencies
37+
.PHONY: venv/%
38+
venv/%:
39+
python$* -m venv $@; \
40+
. $@/bin/activate; \
41+
python -m ensurepip --upgrade; \
42+
pip install --upgrade pip setuptools; \
43+
pip install .
44+
45+
#=> develop: install package in develop mode
46+
.PHONY: develop
47+
develop:
48+
pip install -e .[test]
49+
50+
#=> devready: create venv, install prerequisites, install pkg in develop mode
51+
.PHONY: devready
52+
devready:
53+
make ${VEDIR} && source ${VEDIR}/bin/activate && make develop
54+
@echo '################################################################'
55+
@echo '### `source ${VEDIR}/bin/activate` to use this environment ###'
56+
@echo '################################################################'
57+
58+
#=> install: install package
59+
#=> bdist bdist_egg bdist_wheel build sdist: distribution options
60+
.PHONY: bdist bdist_egg bdist_wheel build build_sphinx sdist install
61+
bdist bdist_egg bdist_wheel build sdist install: %:
62+
python setup.py $@
63+
64+
############################################################################
65+
#= TESTING
66+
# see test configuration in setup.cfg
67+
68+
.PHONY: testready
69+
testready:
70+
pip install -e '.[postgres,queueing,test]'
71+
72+
#=> test: execute tests
73+
.PHONY: test
74+
test:
75+
python -m pytest tests
76+
77+
#=> cqa: execute code quality tests
78+
cqa:
79+
ruff format --check
80+
ruff check
81+
82+
#=> reformat: reformat code
83+
.PHONY: reformat
84+
reformat:
85+
ruff check --fix
86+
ruff format
87+
88+
############################################################################
89+
#= CLEANUP
90+
91+
#=> clean: remove temporary and backup files
92+
.PHONY: clean
93+
clean:
94+
find . \( -name \*~ -o -name \*.bak \) -print0 | ${XRM}
95+
96+
#=> cleaner: remove files and directories that are easily rebuilt
97+
.PHONY: cleaner
98+
cleaner: clean
99+
rm -rf .cache *.egg-info .pytest_cache build dist doc/_build htmlcov
100+
find . \( -name \*.pyc -o -name \*.orig -o -name \*.rej \) -print0 | ${XRM} -fr
101+
find . -name __pycache__ -print0 | ${XRM} -fr
102+
rm -fvr .ruff_cache
103+
104+
#=> cleanest: remove files and directories that require more time/network fetches to rebuild
105+
.PHONY: cleanest
106+
cleanest: cleaner
107+
rm -fr .eggs .venv

pyproject.toml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
[project]
2+
name = "vlm"
3+
authors = [
4+
{ name="biocommons contributors", email="[email protected]" },
5+
]
6+
description = "Off-the-shelf solution for adding local aggregate-level variant information to a VLM network"
7+
readme = "README.md"
8+
license = { file="LICENSE" }
9+
requires-python = ">=3.11"
10+
classifiers = [
11+
"Programming Language :: Python :: 3",
12+
"Programming Language :: Python :: 3.11",
13+
"Programming Language :: Python :: 3.12",
14+
"Programming Language :: Python :: 3.13",
15+
"Programming Language :: Python :: 3.14",
16+
"License :: OSI Approved :: MIT License",
17+
"Operating System :: OS Independent",
18+
]
19+
dependencies = [
20+
"fastapi>=0.95.0",
21+
"python-multipart", # required for fastapi file uploads
22+
"uvicorn",
23+
"python-dotenv",
24+
"anyio",
25+
]
26+
dynamic = ["version"]
27+
28+
[project.optional-dependencies]
29+
test = [
30+
"pytest",
31+
"pytest-cov",
32+
"httpx",
33+
"jsonschema",
34+
"pyyaml",
35+
]
36+
dev = [
37+
"ruff==0.12.8",
38+
"pre-commit>=4.2.0",
39+
"ipykernel",
40+
]
41+
42+
[project.urls]
43+
Homepage = "https://github.com/genomicmedlab/vlm_in_a_box"
44+
Documentation = "https://github.com/genomicmedlab/vlm_in_a_box/"
45+
Changelog = "https://github.com/genomicmedlab/vlm_in_a_box/releases"
46+
Source = "https://github.com/genomicmedlab/vlm_in_a_box/"
47+
"Bug Tracker" = "https://github.com/genomicmedlab/vlm_in_a_box/issues"
48+
49+
50+
[build-system]
51+
requires = [
52+
"setuptools >= 65.3",
53+
"setuptools_scm >= 8"
54+
]
55+
build-backend = "setuptools.build_meta"
56+
57+
[tool.setuptools_scm]
58+
59+
[tool.pytest.ini_options]
60+
addopts = "--cov=anyvar --cov-report term-missing"
61+
testpaths = ["tests"]
62+
pythonpath = ["src"]
63+
64+
[tool.coverage.run]
65+
branch = true
66+
source = ["biocommons.example"]
67+
omit = ["*_test.py", "*/test/*", "*/tests/*"]
68+
69+
[tool.coverage.report]
70+
show_missing = true
71+
exclude_lines = [
72+
# Have to re-enable the standard pragma
73+
"pragma: no cover",
74+
75+
# Don't complain about missing debug-only code:
76+
"def __repr__",
77+
"if self.debug",
78+
79+
# Don't complain if tests don't hit defensive assertion code:
80+
"raise AssertionError",
81+
"raise NotImplementedError",
82+
83+
# Don't complain if non-runnable code isn't run:
84+
"if __name__ == .__main__.:",
85+
]
86+
87+
[tool.ruff]
88+
src = ["src"]
89+
include = ["src/**/*.py", "tests/**/*.py"]
90+
91+
[tool.ruff.lint]
92+
select = ["ALL"]
93+
ignore = [
94+
# not used
95+
"AIR",
96+
"ERA",
97+
"FAST",
98+
"YTT",
99+
"FBT",
100+
"CPY",
101+
"DJ",
102+
"EM",
103+
"EXE",
104+
"FIX",
105+
"FA",
106+
"INT",
107+
"PYI",
108+
"TID",
109+
"TD",
110+
"TC",
111+
"C90",
112+
"NPY",
113+
"PD",
114+
# ignore for compatibility with formatter
115+
"D206",
116+
"D300",
117+
"W191",
118+
"E111",
119+
"E114",
120+
"E117",
121+
"E501",
122+
"W191",
123+
"S321",
124+
"COM812",
125+
# don't require types on *args, **kwargs
126+
"ANN002",
127+
"ANN003",
128+
# subjective pylint thresholds
129+
"PLR0904",
130+
"PLR091",
131+
"PLR1702",
132+
# excessive docstring requirements
133+
"D105",
134+
"D205",
135+
"D203",
136+
"D213", # conflicts with D212
137+
"D400",
138+
"D401",
139+
"D403",
140+
"D415",
141+
# excessive exception message requirements
142+
"TRY003",
143+
# excessive type ignore requirements
144+
"PGH003",
145+
# misc unnecessary readability requirements
146+
"RET504",
147+
]
148+
149+
[tool.ruff.lint.flake8-unused-arguments]
150+
ignore-variadic-names = true
151+
152+
[tool.ruff.lint.per-file-ignores]
153+
"__init__.py" = ["F401", "E402"]
154+
"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "B011", "INP001", "D", "C400", "PLR2004"]
155+
156+
[tool.ruff.format]
157+
docstring-code-format = true

src/vlm/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)