Skip to content

Commit fda4924

Browse files
committed
(wip)
1 parent 0ce1262 commit fda4924

File tree

10 files changed

+70
-65
lines changed

10 files changed

+70
-65
lines changed

.github/workflows/check.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ jobs:
4545
uses: astral-sh/setup-uv@v7
4646
with:
4747
add-problem-matchers: 'false'
48-
- name: Get pip cache dir
49-
id: pip-cache
50-
run: |
51-
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
52-
- name: Persistent Github pip cache
53-
uses: actions/cache@v5
54-
with:
55-
path: ${{ steps.pip-cache.outputs.dir }}
56-
key: pip-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'setup.cfg', 'setup.py', 'Makefile') }}
57-
restore-keys: |
58-
pip-${{ runner.os }}-${{ matrix.python-version }}-
59-
pip-${{ runner.os }}-
60-
- name: Persistent Github venv cache
61-
uses: actions/cache@v5
62-
with:
63-
path: .venv/
64-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'setup.cfg', 'setup.py', 'Makefile') }}
6548
- name: Install dependencies
6649
run: make venv
6750
- name: flake8
@@ -137,7 +120,9 @@ jobs:
137120
with:
138121
add-problem-matchers: 'false'
139122
- name: Install remaining dependencies
140-
run: make venv-system-site-packages
123+
run: make venv-system-site-packages VENV=.venv-site
124+
- name: Set VENV_PYTHON
125+
run: echo "VENV_PYTHON=.venv-site/bin/python" >> "$GITHUB_ENV"
141126
- name: flake8
142127
uses: liskin/gh-problem-matcher-wrap@v3
143128
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.egg-info/
22
*.md.err
33
/.*_cache/
4+
/.venv-site/
45
/.venv/
56
/build/
67
/dist/

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ Other common tasks are available in the [Makefile](Makefile):
3333
-->
3434

3535
$ make help
36-
venv-system-site-packages: Setup ./.venv/ (--system-site-packages)
37-
venv: Setup ./.venv/
3836
check: Invoke all checks (lints, tests, readme)
3937
lint: Invoke lints
4038
lint-flake8:
@@ -46,11 +44,13 @@ Other common tasks are available in the [Makefile](Makefile):
4644
readme: Update usage/examples in *.md and fail if it differs from version control
4745
dist: Build distribution artifacts (sdist, wheel)
4846
publish: Publish to PyPI
49-
ipython: Invoke IPython in venv (not installed by default)
47+
ipython: Invoke IPython with the project and its dependencies available
5048
clean: Clean all gitignored files/directories
5149
template-update: Re-render cookiecutter template into the template branch
5250
template-merge: Re-render cookiecutter template and merge into the current branch
5351
smoke-dist: Smoke test the build artifacts in an isolated venv (i.e. check for unspecified dependencies)
52+
venv: Sync uv venv
53+
venv-system-site-packages: Setup $(VENV) (--system-site-packages)
5454
help: Display this help
5555
<!-- end include tests/readme/make-help.md -->
5656

Makefile

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
SHELL := bash
22
.SHELLFLAGS := -eu -o pipefail -c
33

4-
PYTHON = python3
4+
UV_RUN_SYNC_FLAGS ?= --exact --all-extras
5+
VENV_PYTHON ?= uv run $(UV_RUN_SYNC_FLAGS) python
56

6-
VENV = .venv
7-
VENV_PYTHON = $(VENV)/bin/python
8-
VENV_DONE = $(VENV)/.done
9-
VENV_SYSTEM_SITE_PACKAGES = $(VENV)/.venv-system-site-packages
10-
VENV_USE_SYSTEM_SITE_PACKAGES = $(wildcard $(VENV_SYSTEM_SITE_PACKAGES))
7+
VENV ?= $(or $(if $(filter 1,$(words $(VENV_PYTHON))),$(patsubst %/bin/,%,$(filter %/bin/,$(dir $(VENV_PYTHON))))),$(error Cannot determine VENV path))
118

129
TEMPLATES_DIR = $(HOME)/src
1310
TEMPLATE = $(eval TEMPLATE := $$(shell realpath --relative-to=. $$(TEMPLATES_DIR)/cookiecutter-python-cli))$(TEMPLATE)
1411

15-
.PHONY: venv-system-site-packages
16-
## Setup ./.venv/ (--system-site-packages)
17-
venv-system-site-packages:
18-
$(MAKE) VENV_USE_SYSTEM_SITE_PACKAGES=1 venv
19-
20-
.PHONY: venv
21-
## Setup ./.venv/
22-
venv: $(VENV_DONE)
23-
2412
.PHONY: check
2513
## Invoke all checks (lints, tests, readme)
2614
check: lint test readme
@@ -33,17 +21,20 @@ LINT_SOURCES = src/ tests/
3321

3422
.PHONY: lint-flake8
3523
##
36-
lint-flake8: $(VENV_DONE)
24+
lint-flake8:
3725
$(VENV_PYTHON) -m flake8 $(LINT_SOURCES)
3826

3927
.PHONY: lint-mypy
4028
##
41-
lint-mypy: $(VENV_DONE)
42-
$(VENV_PYTHON) -m mypy --show-column-numbers $(LINT_SOURCES)
29+
lint-mypy:
30+
$(VENV_PYTHON) -m mypy \
31+
--python-executable "$$($(VENV_PYTHON) -c 'import sys; print(sys.executable)')" \
32+
--show-column-numbers $(LINT_SOURCES)
33+
# ^ overrides hardcoded python_executable in pyproject.toml (which is there for pylsp)
4334

4435
.PHONY: lint-isort
4536
##
46-
lint-isort: $(VENV_DONE)
37+
lint-isort:
4738
$(VENV_PYTHON) -m isort --check $(LINT_SOURCES)
4839

4940
.PHONY: test
@@ -52,26 +43,26 @@ test: test-pytest test-prysk
5243

5344
.PHONY: test-pytest
5445
##
55-
test-pytest: $(VENV_DONE)
46+
test-pytest:
5647
$(VENV_PYTHON) -m pytest $(PYTEST_FLAGS) tests/
5748

5849
.PHONY: test-prysk
5950
##
6051
test-prysk: PRYSK_INTERACTIVE=$(shell [ -t 0 ] && echo --interactive)
61-
test-prysk: $(VENV_DONE)
62-
PATH="$(CURDIR)/$(VENV)/bin:$$PATH" \
63-
XDG_DATA_HOME=/home/user/.local/share \
64-
XDG_CONFIG_HOME=/home/user/.config \
65-
$(VENV_PYTHON) -m prysk --indent=4 --shell=/bin/bash $(PRYSK_INTERACTIVE) \
52+
test-prysk:
53+
$(if $(filter-out uv,$(firstword $(VENV_PYTHON))), \
54+
PATH="$(CURDIR)/$(VENV)/bin:$$PATH" \
55+
)$(VENV_PYTHON) -m prysk --indent=4 --shell=/bin/bash $(PRYSK_INTERACTIVE) \
6656
$(wildcard tests/*.md tests/*/*.md tests/*/*/*.md)
57+
# ^ PATH only needed for venv-system-site-packages, uv sets it already
6758

6859
.PHONY: readme
6960
## Update usage/examples in *.md and fail if it differs from version control
7061
readme: $(wildcard *.md)
7162
git diff --exit-code $^
7263

7364
.PHONY: $(wildcard *.md)
74-
$(wildcard *.md) &: $(VENV_DONE) test-prysk
65+
$(wildcard *.md) &: test-prysk
7566
$(VENV_PYTHON) tests/include-preproc.py --comment-start="<!-- " --comment-end=" -->" $(wildcard *.md)
7667

7768
.PHONY: dist
@@ -85,9 +76,11 @@ publish: dist
8576
uv publish
8677

8778
.PHONY: ipython
88-
## Invoke IPython in venv (not installed by default)
89-
ipython: $(VENV_DONE)
90-
$(VENV_PYTHON) -m IPython
79+
## Invoke IPython with the project and its dependencies available
80+
ipython:
81+
uv run $(UV_RUN_SYNC_FLAGS) \
82+
--with ipython \
83+
python -m IPython
9184

9285
.PHONY: clean
9386
## Clean all gitignored files/directories
@@ -116,20 +109,21 @@ smoke-dist: dist
116109
-- python -m "$$package" --help; \
117110
done
118111

119-
define VENV_CREATE
120-
$(PYTHON) -m venv $(VENV)
121-
endef
122-
123-
define VENV_CREATE_SYSTEM_SITE_PACKAGES
124-
$(PYTHON) -m venv --system-site-packages --without-pip $(VENV)
125-
touch $(VENV_SYSTEM_SITE_PACKAGES)
126-
endef
112+
.PHONY: venv
113+
## Sync uv venv
114+
venv:
115+
uv sync $(UV_RUN_SYNC_FLAGS)
127116

128-
$(VENV_DONE): $(MAKEFILE_LIST) pyproject.toml
129-
$(if $(VENV_USE_SYSTEM_SITE_PACKAGES),$(VENV_CREATE_SYSTEM_SITE_PACKAGES),$(VENV_CREATE))
130-
$(VENV_PYTHON) -m pip install 'pip >= 25.1' # PEP-735 (dependency groups)
117+
.PHONY: venv-system-site-packages
118+
## Setup $(VENV) (--system-site-packages)
119+
venv-system-site-packages: VENV_PYTHON=$(VENV)/bin/python
120+
venv-system-site-packages: PYTHON=python3
121+
venv-system-site-packages:
122+
uv venv --system-site-packages --seed $(VENV)
131123
extras=$$(uvx --from yq -- tomlq -e -r '.project."optional-dependencies" // [] | keys | join(",")' pyproject.toml); \
132124
$(VENV_PYTHON) -m pip install --group dev -e ".[ $$extras ]"
133-
touch $@
125+
@echo
126+
@echo "Now use: make VENV_PYTHON=$(VENV_PYTHON)"
127+
# ^ uv's dependency solver ignores --system-site-packages, so we need to use pip
134128

135129
include _help.mk

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ least once to let strava-offline reuse these downloaded files.
132132
[strava-bulk-export]: https://support.strava.com/hc/en-us/articles/216918437-Exporting-your-Data-and-Bulk-Export#Bulk
133133

134134
<!-- include tests/readme/help-gpx.md -->
135+
<!--
136+
$ . "$TESTDIR"/../.xdg-user.sh
137+
-->
138+
135139
$ strava-offline gpx --help
136140
Usage: strava-offline gpx [OPTIONS]
137141

@@ -192,6 +196,10 @@ which is located at `~/.config/strava_offline/config.yaml` by default
192196
Sample config file can be generated using the `--config-sample` flag:
193197

194198
<!-- include tests/readme/config-sample.md -->
199+
<!--
200+
$ . "$TESTDIR"/../.xdg-user.sh
201+
-->
202+
195203
$ strava-offline --config-sample
196204
# Perform full sync instead of incremental
197205
full: false

tests/.xdg-user.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!bash
2+
# shellcheck disable=2239
3+
4+
export XDG_DATA_HOME=/home/user/.local/share
5+
export XDG_CONFIG_HOME=/home/user/.config

tests/readme/config-sample.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
$ . "$TESTDIR"/../.xdg-user.sh
3+
-->
4+
15
$ strava-offline --config-sample
26
# Perform full sync instead of incremental
37
full: false

tests/readme/help-gpx.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
$ . "$TESTDIR"/../.xdg-user.sh
3+
-->
4+
15
$ strava-offline gpx --help
26
Usage: strava-offline gpx [OPTIONS]
37

tests/readme/help-sqlite.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
$ . "$TESTDIR"/../.xdg-user.sh
3+
-->
4+
15
$ strava-offline sqlite --help
26
Usage: strava-offline sqlite [OPTIONS]
37

tests/readme/make-help.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
-->
88

99
$ make help
10-
venv-system-site-packages: Setup ./.venv/ (--system-site-packages)
11-
venv: Setup ./.venv/
1210
check: Invoke all checks (lints, tests, readme)
1311
lint: Invoke lints
1412
lint-flake8:
@@ -20,9 +18,11 @@
2018
readme: Update usage/examples in *.md and fail if it differs from version control
2119
dist: Build distribution artifacts (sdist, wheel)
2220
publish: Publish to PyPI
23-
ipython: Invoke IPython in venv (not installed by default)
21+
ipython: Invoke IPython with the project and its dependencies available
2422
clean: Clean all gitignored files/directories
2523
template-update: Re-render cookiecutter template into the template branch
2624
template-merge: Re-render cookiecutter template and merge into the current branch
2725
smoke-dist: Smoke test the build artifacts in an isolated venv (i.e. check for unspecified dependencies)
26+
venv: Sync uv venv
27+
venv-system-site-packages: Setup $(VENV) (--system-site-packages)
2828
help: Display this help

0 commit comments

Comments
 (0)