-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
167 lines (132 loc) · 5.4 KB
/
Copy pathjustfile
File metadata and controls
167 lines (132 loc) · 5.4 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
list-tasks:
@just --list
alias f := format
alias t := test
alias l := lint
alias q := quick-tools
### run once after init/clone ###
# Initialize a new project
init: && prepare
git init
git commit --allow-empty -m "Initial commit"
git add --all
git commit -m "🚀 Initialized project using https://github.com/tsvikas/python-template"
just deps-update
git add --all
[ -z "$(git status --porcelain)" ] || git commit -m "⬆️ Updated project dependencies"
uvx --from detect-secrets detect-secrets-hook $(git ls-files)
uvx --from detect-secrets detect-secrets scan > .secrets.baseline
git add .secrets.baseline
git commit -m "🔒 Add detect-secrets baseline"
# Setup the project after cloning
prepare:
uv run prek install --install-hooks
### dependencies ###
# List outdated python dependencies
deps-list-outdated:
uv tree --outdated --depth 1 --color always -q | { grep latest --color=never || exit 0; }
# Update all dependencies
deps-update: && deps-list-outdated
uv sync --upgrade
uv run prek auto-update
uvx sync-with-uv
just _sync-blacken-docs
uvx sync-pre-commit-deps --yaml-mapping 2 --yaml-sequence 4 --yaml-offset 2 .pre-commit-config.yaml || { \
echo "Note: '.pre-commit-config.yaml' changed, and might lost its formatting." \
&& exit 1; \
}
# Audit dependencies
deps-audit:
uv audit --locked
# Sync blacken-docs' black additional_dependency with the version in uv.lock
_sync-blacken-docs:
@black_ver=$(awk -F'"' '/^\[\[package\]\]/{p=0} /^name = "black"$/{p=1} p && /^version =/{print $2; exit}' uv.lock); \
if [ -n "$black_ver" ] && grep -q 'id: blacken-docs' .pre-commit-config.yaml; then \
sed -i -E "/id: blacken-docs/,/^ - repo:/ s/(black==)(<[^>]*>|[0-9][0-9a-z.+-]*)/\1$black_ver/" .pre-commit-config.yaml; \
fi
### code quality ###
_assert_clean_repo:
[ -z "$(git status --porcelain)" ]
# Tests to run before push, tag, or release
_check: _assert_clean_repo test lint
# Check the code, and push if it pass
check-and-push: _check
git push --follow-tags
# Run fast formatting and linting tools
quick-tools:
uv run ruff check --select I001 --fix -q
uv run black -q .
uv run ruff check
uv run --exact --all-extras --no-default-groups --group typing --group test -- ty check
# Format code and files
format:
uv run ruff check --select I001 --fix
uv run black .
uv run prek run --all-files blacken-docs
uv run prek run --all-files mdformat
# Run linters
lint:
uv run ruff check
uv run --exact --all-extras --no-default-groups --group typing --group test -- dmypy run
uv run --exact --all-extras --all-groups --with deptry -- deptry src/
uv run --exact prek run --all-files
# Run Pylint (slow, not used in other tasks)
pylint:
uv run --exact --with pylint -- pylint src
uv run --exact true
# Run tests with pytest
test:
uv run --exact --all-extras --no-default-groups --group test \
--reinstall-package hebrew_numbers -- pytest
uv run --exact true
# Run tests with pytest, using resolution lowest-direct
test-lowest python:
mv uv.lock uv.lock.1
uv sync --exact --all-extras --no-default-groups --group test \
--upgrade --resolution lowest-direct --python {{python}} \
--reinstall-package hebrew_numbers
mv uv.lock.1 uv.lock
uv run --no-sync pytest
uv run --exact true
### Release, tags, previous commits ###
# Create a release commit
release version: (_assert-legal-version version) _check
sed -i.bak "s/## \[Unreleased\]/## [Unreleased]\n\n## [{{version}}] - $(date +%Y-%m-%d)/" CHANGELOG.md
sed -i.bak -E "s|^\[unreleased\]: (https://github\.com/[^/]+/[^/]+)/compare/(.+)\.\.\.HEAD|[{{version}}]: \1/compare/\2...v{{version}}\n[unreleased]: \1/compare/v{{version}}...HEAD|" CHANGELOG.md
sed -i.bak -E "s|^\[unreleased\]: (https://github\.com/[^/]+/[^/]+)/releases/tag/HEAD|[{{version}}]: \1/releases/tag/v{{version}}\n[unreleased]: \1/compare/v{{version}}...HEAD|" CHANGELOG.md
rm -f CHANGELOG.md.bak
git add CHANGELOG.md
git commit -m "🔖 Release v{{version}}"
just _tag-skip-check {{version}} HEAD
# Add a new version tag at a specific commit
tag-version-at-commit version commit: (_assert-legal-version version)
just check-at-commit {{commit}}
just _tag-skip-check {{version}} {{commit}}
version_regex := '^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$'
_assert-legal-version version:
@echo "{{version}}" | grep -qE '{{version_regex}}' || ( echo "Error: not a legal version" && false )
tmp_rc_dir := '/tmp/rc/' + file_name(justfile_directory()) + '/' + datetime('%s')
# Run code checks at a specific commit
check-at-commit commit:
git worktree add {{tmp_rc_dir}} --detach {{commit}}
just -f {{tmp_rc_dir}}/justfile _check || ( git worktree remove -f {{tmp_rc_dir}} && false )
git worktree remove {{tmp_rc_dir}}
_tag-skip-check version commit: (_assert-legal-version version)
git tag -a v{{version}} -m "Release v{{version}}" {{commit}}
### Documentation ###
# Generate reference pages from docstrings
build-docs-ref:
rm -rf docs/reference
uv run --exact --python 3.14 --only-group docs -- \
scripts/gen_ref_pages.py
uv run --exact true
# Build the documentation
build-docs: build-docs-ref
uv run --exact --python 3.14 --only-group docs -- \
mkdocs build
uv run --exact true
# Serve the documentation locally
serve-docs: build-docs-ref
uv run --exact --python 3.14 --only-group docs -- \
mkdocs serve
uv run --exact true