Skip to content

Commit c772f66

Browse files
committed
use uv run in Makefile; make more prettier; update precommit config
1 parent 30eeadf commit c772f66

File tree

5 files changed

+66
-75
lines changed

5 files changed

+66
-75
lines changed

.github/actions/setup-python-env/action.yml

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

.pre-commit-config.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ repos:
77
- id: check-toml
88
- id: check-yaml
99
- id: check-json
10-
exclude: ^.devcontainer/devcontainer.json
10+
exclude: ^.devcontainer/.*devcontainer.json
1111
- id: pretty-format-json
12-
exclude: ^.devcontainer/devcontainer.json
12+
exclude: ^.devcontainer/.*devcontainer.json
1313
args: [--autofix, --no-sort-keys]
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
@@ -20,3 +20,19 @@ repos:
2020
- id: ruff-check
2121
args: [ --exit-non-zero-on-fix ]
2222
- id: ruff-format
23+
24+
- repo: local
25+
hooks:
26+
- id: canonicalize-gitignore
27+
name: Sort unique .gitignore
28+
entry: sort -u -o .gitignore .gitignore
29+
language: system
30+
files: ^\.gitignore$
31+
32+
- repo: local
33+
hooks:
34+
- id: canonicalize-pyproject
35+
name: Ensure pyproject.toml in canonical order and format
36+
entry: uvx toml-sort --in-place pyproject.toml
37+
language: system
38+
files: ^pyproject.toml$

Makefile

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
.DEFAULT_GOAL := help
77
default: help
88

9-
SHELL:=/bin/bash
9+
ifeq ("","$(shell command -v zsh)")
10+
$(error "zsh not found; you must install zsh first")
11+
endif
12+
SHELL:=zsh -eu -o pipefail -o null_glob
1013

1114
COLOR_RESET=\033[0m
1215
COLOR_CYAN_BOLD=\033[1;36m
13-
define ECHO_BANNER
16+
define INFO_MESSAGE
1417
@echo -e "⏩$(COLOR_CYAN_BOLD)$(1)$(COLOR_RESET)"
1518
endef
1619

@@ -20,85 +23,73 @@ endef
2023
.PHONY: help
2124
help: ## Display help message
2225
@uvx python -c "import re; \
23-
[[print(f'- \033[36m{m[0]:<20}\033[0m {m[1]}') for m in re.findall(r'^([\sa-zA-Z_-]+):.*?## (.*)$$', open(makefile).read(), re.M)] for makefile in ('$(MAKEFILE_LIST)').strip().split()]" | sort
24-
26+
[[print(f'✦ \033[36m{m[0]:<20}\033[0m {m[1]}') for m in re.findall(r'^([\sa-zA-Z_-]+):.*?## (.*)$$', open(makefile).read(), re.M)] for makefile in ('$(MAKEFILE_LIST)').strip().split()]" | sort
2527

2628
############################################################################
2729
#= SETUP, INSTALLATION, PACKAGING
2830

2931
install: devready
3032
.PHONY: devready
3133
devready: ## Prepare local dev env: Create virtual env, install the pre-commit hooks
32-
$(call ECHO_BANNER, "Prepare local dev env: Create virtual env, install the pre-commit hooks")
34+
$(call INFO_MESSAGE, Prepare local dev env: Create virtual env and install the pre-commit hooks)
3335
uv sync --dev
34-
uvx pre-commit install
36+
uv run pre-commit install
37+
@echo '⚠️ You must activate the virtual env with `source .venv/bin/activate`'
3538

3639
.PHONY: build
3740
build: ## Build package
38-
$(call ECHO_BANNER, "Building package")
41+
$(call INFO_MESSAGE, "Building package")
3942
rm -fr dist
40-
uvx --from build pyproject-build --installer uv
41-
42-
.PHONY: publish
43-
publish: ## Publish a release to PyPI.
44-
$(call ECHO_BANNER, "Publishing to PyPI.")
45-
uvx publish
46-
43+
uv build
4744

4845
############################################################################
49-
#= TESTING AND CODE QUALITY
46+
#= FORMATTING, TESTING, AND CODE QUALITY
5047

51-
.PHONY: check
52-
cqa check: ## Run code quality tools.
53-
$(call ECHO_BANNER, "Checking lock file consistency with 'pyproject.toml'")
48+
.PHONY: cqa
49+
cqa: ## Run code quality assessments.
50+
$(call INFO_MESSAGE, "Checking lock file consistency")
5451
uv lock --locked
55-
$(call ECHO_BANNER, "Linting code: Running pre-commit")
56-
uvx pre-commit run -a
57-
$(call ECHO_BANNER, "Checking for obsolete dependencies: Running deptry")
58-
uvx deptry src
52+
$(call INFO_MESSAGE, "Linting and reformatting files")
53+
uv run pre-commit run -a
54+
$(call INFO_MESSAGE, "Checking for obsolete dependencies")
55+
uv run deptry src
5956

6057
.PHONY: test
6158
test: ## Test the code with pytest
6259
@echo "🚀 Testing code: Running pytest"
63-
pytest
64-
#uvx python -m pytest # --cov --cov-config=pyproject.toml --cov-report=xml
65-
60+
uv run pytest
6661

6762
############################################################################
6863
#= DOCUMENTATION
6964

65+
.PHONY: docs-serve
66+
docs-serve: ## Build and serve the documentation
67+
$(call INFO_MESSAGE, "Build and serve docs for local development")
68+
uv run mkdocs serve
69+
7070
.PHONY: docs-test
7171
docs-test: ## Test if documentation can be built without warnings or errors
72-
$(call ECHO_BANNER, "Testing whether docs can be build")
73-
uvx mkdocs build -s
74-
75-
.PHONY: serve
76-
serve: ## Build and serve the documentation
77-
$(call ECHO_BANNER, "Build and serve docs for local development")
78-
uvx mkdocs serve
79-
72+
$(call INFO_MESSAGE, "Testing whether docs can be build")
73+
uv run mkdocs build -s
8074

8175
############################################################################
8276
#= CLEANUP
8377

8478
.PHONY: clean
8579
clean: ## Remove temporary and backup files
86-
$(call ECHO_BANNER, "Remove temporary and backup files")
80+
$(call INFO_MESSAGE, "Remove temporary and backup files")
8781
rm -frv **/*~ **/*.bak
8882

8983
.PHONY: cleaner
9084
cleaner: clean ## Remove files and directories that are easily rebuilt
91-
$(call ECHO_BANNER, "Remove files and directories that are easily rebuilt")
85+
$(call INFO_MESSAGE, "Remove files and directories that are easily rebuilt")
9286
rm -frv .cache build dist docs/_build
93-
rm -frv **/__pycache__
94-
rm -frv **/*.egg-info
95-
rm -frv **/*.pyc
96-
rm -frv **/*.orig
97-
rm -frv **/*.rej
87+
rm -frv **/*.pyc **/__pycache__ **/*.egg-info
88+
rm -frv **/*.orig **/*.rej
9889

9990
.PHONY: cleanest
10091
cleanest: cleaner ## Remove all files that can be rebuilt
101-
$(call ECHO_BANNER, "Remove files and directories that can be rebuilt")
92+
$(call INFO_MESSAGE, "Remove files and directories that can be rebuilt")
10293
rm -frv .eggs .tox .venv venv
10394

10495
.PHONY: distclean

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ name = "biocommons-example"
2222
authors = [
2323
{name = "biocommons contributors", email = "[email protected]"}
2424
]
25+
dependencies = ["coloredlogs ~= 15.0", "pyyaml ~= 6.0"]
2526
description = "biocommons.example package (namespaced)"
2627
readme = "README.md"
2728
license = "Apache-2.0"
@@ -33,9 +34,13 @@ classifiers = [
3334
"Programming Language :: Python :: 3.12",
3435
"Operating System :: OS Independent"
3536
]
36-
dependencies = ["coloredlogs ~= 15.0", "pyyaml ~= 6.0"]
3737
dynamic = ["version"]
3838

39+
[project.optional-dependencies]
40+
example = [
41+
"pyyaml"
42+
]
43+
3944
[project.scripts]
4045
marvin-quote = "biocommons.example.__main__:main"
4146

@@ -68,6 +73,8 @@ branch = true
6873
omit = ["*_test.py", "*/test/*", "*/tests/*"]
6974
source = ["src"]
7075

76+
[tool.deptry]
77+
7178
[tool.deptry.package_module_name_map]
7279
# map package name to import name
7380
# Making this explicit suppresses deptry notices

uv.lock

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

0 commit comments

Comments
 (0)