11# * Variables
22SHELL ?= /usr/bin/env bash
3- ACTIVEPYTHON = $(shell which python)
3+
4+ # use the directory rather than the python binary to allow auto-discovery, which is more cross-platform compatible
5+ PYTHON_PATH := $(shell which python)
6+ PYTHON_ROOT := $(shell dirname $(dir $(PYTHON_PATH ) ) )
7+ UV_PYTHON_ROOT ?= $(PYTHON_ROOT )
8+
9+ # to actually reuse an existing virtual/conda environment, the 'UV_PROJECT_ENVIRONMENT' variable must be set to it
10+ # use this command:
11+ # UV_PROJECT_ENVIRONMENT=/path/to/env make [target]
12+ # consider exporting this variable in '/path/to/env/etc/conda/activate.d/env.sh' to enable it by default when
13+ # activating a conda environment, and reset it in '/path/to/env/etc/conda/deactivate.d/env.sh'
14+ UV_PROJECT_ENVIRONMENT ?=
15+ # make sure every uv command employs the specified environment path
16+ ifeq (${UV_PROJECT_ENVIRONMENT},)
17+ UV_COMMAND := uv
18+ else
19+ UV_COMMAND := UV_PROJECT_ENVIRONMENT="${UV_PROJECT_ENVIRONMENT}" uv
20+ endif
421
522# * UV
623.PHONY : setup
@@ -9,35 +26,35 @@ setup:
926
1027.PHONY : publish
1128publish :
12- uv publish --build
29+ $( UV_COMMAND ) publish --build
1330
1431# * Installation
1532.PHONY : install
1633install : setup
17- uv export --format requirements-txt -o requirements.txt --no-dev
18- uv pip install --python $( ACTIVEPYTHON ) -r requirements.txt
34+ $( UV_COMMAND ) export --format requirements-txt -o requirements.txt --no-dev
35+ $( UV_COMMAND ) pip install --python " $( UV_PYTHON_ROOT ) " -r requirements.txt
1936
2037.PHONY : install-dev
2138install-dev : setup
22- uv export --format requirements-txt -o requirements-dev.txt
23- uv pip install --python $( ACTIVEPYTHON ) -r requirements-dev.txt
39+ $( UV_COMMAND ) export --format requirements-txt -o requirements-dev.txt
40+ $( UV_COMMAND ) pip install --python " $( UV_PYTHON_ROOT ) " -r requirements-dev.txt
2441
2542.PHONY : pre-commit-install
2643pre-commit-install : setup
27- uv run --python $( ACTIVEPYTHON ) pre-commit install
44+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " pre-commit install
2845
2946# * Formatters
3047.PHONY : codestyle
3148codestyle : setup
32- uv run --python $( ACTIVEPYTHON ) ruff format --config=pyproject.toml stac_model tests
49+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " ruff format --config=pyproject.toml stac_model tests
3350
3451.PHONY : format
3552format : codestyle
3653
3754# * Linting
3855.PHONY : test
3956test : setup
40- uv run --python $( ACTIVEPYTHON ) pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/
57+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/
4158
4259.PHONY : check
4360check : check-examples check-markdown check-lint check-mypy check-safety check-citation
@@ -47,23 +64,23 @@ check-all: check
4764
4865.PHONY : mypy
4966mypy : setup
50- uv run --python $( ACTIVEPYTHON ) mypy --config-file pyproject.toml ./
67+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " mypy --config-file pyproject.toml ./
5168
5269.PHONY : check-mypy
5370check-mypy : mypy
5471
5572.PHONY : check-safety
5673check-safety : setup
57- uv run --python $( ACTIVEPYTHON ) safety check --full-report
58- uv run --python $( ACTIVEPYTHON ) bandit -ll --recursive stac_model tests
74+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " safety check --full-report
75+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " bandit -ll --recursive stac_model tests
5976
6077.PHONY : lint
6178lint : setup
62- uv run --python $( ACTIVEPYTHON ) ruff check --fix --config=pyproject.toml ./
79+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " ruff check --fix --config=pyproject.toml ./
6380
6481.PHONY : check-lint
6582check-lint : lint
66- uv run --python $( ACTIVEPYTHON ) ruff check --config=pyproject.toml ./
83+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " ruff check --config=pyproject.toml ./
6784
6885.PHONY : format-lint
6986format-lint : lint
@@ -97,8 +114,8 @@ lint-all: lint mypy check-safety check-markdown
97114
98115.PHONY : update-dev-deps
99116update-dev-deps : setup
100- uv export --only-dev --format requirements-txt -o requirements-only-dev.txt
101- uv pip install --python $( ACTIVEPYTHON ) -r requirements-only-dev.txt
117+ $( UV_COMMAND ) export --only-dev --format requirements-txt -o requirements-only-dev.txt
118+ $( UV_COMMAND ) pip install --python " $( UV_PYTHON_ROOT ) " -r requirements-only-dev.txt
102119
103120# * Cleaning
104121.PHONY : pycache-remove
0 commit comments