11SHELL := 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
129TEMPLATES_DIR = $(HOME ) /src
1310TEMPLATE = $(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)
2614check : 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# #
6051test-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
7061readme : $(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
135129include _help.mk
0 commit comments