-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJustfile
More file actions
134 lines (105 loc) · 4.18 KB
/
Justfile
File metadata and controls
134 lines (105 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
set shell := ["bash", "-eu", "-o", "pipefail", "-c"]
set script-interpreter := ["bash", "-eux", "-o", "pipefail"]
venv_include_system_site_packages := shell("grep -s -l '^include-system-site-packages\\s*=\\s*true$' .venv/pyvenv.cfg || :")
uv_run_sync_flags := if venv_include_system_site_packages == "" { '--exact --all-extras' } else { '--no-sync' }
# ^ uv's dependency solver ignores --system-site-packages, so we need to pass --no-sync
package := 'strava_offline'
template := 'cookiecutter-python-cli'
templates_dir := home_directory() / 'src'
# ----------------------------------------------------------------------
help:
@just --list --unsorted
# Run the project
run *params:
uv run {{ uv_run_sync_flags }} python -m {{ package }} {{ params }}
# Run all checks (`lint`, `test`, `readme-diff`)
check: lint test readme-diff
# Clean all gitignored files/directories
clean:
git clean -ffdX
# Invoke IPython with the project and its dependencies available
ipython:
uv run {{ uv_run_sync_flags }} --with ipython python -m IPython
# ----------------------------------------------------------------------
lint_sources := 'src/ tests/'
readme_sources := './*.md'
# Run all linters
[group('check')]
lint: lint-flake8 lint-mypy lint-isort
[group('check')]
lint-flake8:
uv run {{ uv_run_sync_flags }} python -m flake8 {{ lint_sources }}
[group('check')]
lint-mypy:
uv run {{ uv_run_sync_flags }} python -m mypy --show-column-numbers {{ lint_sources }}
[group('check')]
lint-isort:
uv run {{ uv_run_sync_flags }} python -m isort --check {{ lint_sources }}
# Run all tests
[group('check')]
test: test-pytest test-prysk
# Run Python tests
[group('check')]
test-pytest *pytest_flags:
uv run {{ uv_run_sync_flags }} python -m pytest {{ pytest_flags }} tests/
# Run CLI tests
[group('check')]
test-prysk *prysk_flags=shell("[ -t 0 ] && echo --interactive || :"):
shopt -s nullglob && \
uv run {{ uv_run_sync_flags }} python -m prysk --indent=4 --shell=/bin/bash {{ prysk_flags }} tests/*.md tests/*/*.md tests/*/*/*.md
# Update usage/examples in docs
[group('check')]
readme: test-prysk
uv run {{ uv_run_sync_flags }} python tests/include-preproc.py --comment-start="<!-- " --comment-end=" -->" {{ readme_sources }}
# `readme` and fail if they differ from version control
[group('check')]
readme-diff: readme
git diff --exit-code {{ readme_sources }}
# ----------------------------------------------------------------------
# Build distribution artifacts (sdist, wheel)
[group('dist')]
dist:
uv build --clear
# Publish to PyPI
[group('dist')]
publish: dist
uv publish
# Smoke test the build artifacts in an isolated venv (i.e. check for unspecified dependencies)
[group('dist')]
[script]
smoke-dist: dist
for dist in dist/{{ package }}-*.{whl,tar*}; do
for bin in $(uvx --from yq -- tomlq -e -r '.project.scripts | keys[]' pyproject.toml); do
extras=$(uvx --from yq -- tomlq -r --arg script "$bin" '.project.scripts[$script] // "" | scan("\\[.*\\]")' pyproject.toml)
uv run \
--isolated --no-project \
--with "$dist$extras" \
-- "$bin" --help
done
done
# ----------------------------------------------------------------------
# Sync uv .venv
[group('venv')]
venv:
uv sync {{ uv_run_sync_flags }}
# Setup .venv with --system-site-packages
[group('venv')]
[script]
venv-system-site-packages:
uv venv --system-site-packages --seed .venv
extras=$(uvx --from yq -- tomlq -e -r '.project."optional-dependencies" // [] | keys | join(",")' pyproject.toml)
uv run --no-sync python -m pip install --group dev -e ".[ $extras ]"
# ^ uv's dependency solver ignores --system-site-packages, so we need to use pip
# ----------------------------------------------------------------------
# Re-render cookiecutter template into the template branch
[group('template')]
template-update:
{{ templates_dir / template }}/update.sh \
-t {{ shell('realpath --relative-to=. "$1"', templates_dir / template) }} \
-p . \
-b template \
-i .cookiecutter.json
# `template-update` and merge into the current branch
[group('template')]
template-merge: template-update
git merge template