11# * Variables
22SHELL ?= /usr/bin/env bash
3- PYTHON ?= python
4- PYTHONPATH := ` pwd `
5- POETRY ?= poetry
63
7- # * Poetry
8- .PHONY : poetry-install
9- poetry-install :
10- curl -sSL https://install.python-poetry.org | $(PYTHON ) -
11-
12- .PHONY : poetry-remove
13- poetry-remove :
14- curl -sSL https://install.python-poetry.org | $(PYTHON ) - --uninstall
15-
16- .PHONY : poetry-plugins
17- poetry-plugins :
18- $(POETRY ) self add poetry-plugin-up
19-
20- .PHONY : poetry-env
21- poetry-env :
22- $(POETRY ) config virtualenvs.in-project true
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
21+
22+ # * UV
23+ .PHONY : setup
24+ setup :
25+ which uv > /dev/null || (curl -LsSf https://astral.sh/uv/install.sh | sh)
2326
2427.PHONY : publish
2528publish :
26- $(POETRY ) publish --build
29+ $(UV_COMMAND ) publish --build
2730
2831# * Installation
2932.PHONY : install
30- install : poetry-env
31- $(POETRY ) lock -n && poetry export --without-hashes > requirements-lock.txt
32- $(POETRY ) install -n
33- -poetry run mypy --install-types --non-interactive ./
33+ install : setup
34+ $(UV_COMMAND ) export --format requirements-txt -o requirements.txt --no-dev
35+ $(UV_COMMAND ) pip install --python " $( UV_PYTHON_ROOT) " -r requirements.txt
3436
3537.PHONY : install-dev
36- install-dev : poetry-env install
37- $(POETRY ) install -n --with dev
38+ install-dev : setup
39+ $(UV_COMMAND ) export --format requirements-txt -o requirements-dev.txt
40+ $(UV_COMMAND ) pip install --python " $( UV_PYTHON_ROOT) " -r requirements-dev.txt
3841
3942.PHONY : pre-commit-install
40- pre-commit-install :
41- $(POETRY ) run pre-commit install
42-
43+ pre-commit-install : setup
44+ $(UV_COMMAND ) run --python " $( UV_PYTHON_ROOT) " pre-commit install
4345
4446# * Formatters
4547.PHONY : codestyle
46- codestyle :
47- $(POETRY ) run ruff format --config=pyproject.toml stac_model tests
48+ codestyle : setup
49+ $(UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " ruff format --config=pyproject.toml stac_model tests
4850
4951.PHONY : format
5052format : codestyle
5153
5254# * Linting
5355.PHONY : test
54- test :
55- PYTHONPATH= $( PYTHONPATH ) poetry run pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/
56+ test : setup
57+ $( UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/
5658
5759.PHONY : check
5860check : check-examples check-markdown check-lint check-mypy check-safety check-citation
@@ -61,37 +63,28 @@ check: check-examples check-markdown check-lint check-mypy check-safety check-ci
6163check-all : check
6264
6365.PHONY : mypy
64- mypy :
65- $(POETRY ) run mypy --config-file pyproject.toml ./
66+ mypy : setup
67+ $(UV_COMMAND ) run --python " $( UV_PYTHON_ROOT ) " mypy --config-file pyproject.toml ./
6668
6769.PHONY : check-mypy
6870check-mypy : mypy
6971
70- # NOTE:
71- # purposely running with docker rather than python package due to conflicting dependencies
72- # see https://github.com/citation-file-format/cffconvert/issues/292
73- .PHONY : check-citation
74- check-citation :
75- docker run --rm -v $(PYTHONPATH ) /CITATION.cff:/app/CITATION.cff citationcff/cffconvert --validate
76-
7772.PHONY : check-safety
78- check-safety :
79- $(POETRY ) check
80- $(POETRY ) run safety check --full-report
81- $(POETRY ) run bandit -ll --recursive stac_model tests
73+ check-safety : setup
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
8276
8377.PHONY : lint
84- lint :
85- $(POETRY ) run ruff --config=pyproject.toml ./
86- $(POETRY ) run pydocstyle --count --config=pyproject.toml ./
87- $(POETRY ) run pydoclint --config=pyproject.toml ./
78+ lint : setup
79+ $(UV_COMMAND ) run --python " $( UV_PYTHON_ROOT) " ruff check --fix --config=pyproject.toml ./
8880
8981.PHONY : check-lint
9082check-lint : lint
83+ $(UV_COMMAND ) run --python " $( UV_PYTHON_ROOT) " ruff check --config=pyproject.toml ./
9184
9285.PHONY : format-lint
93- format-lint :
94- $( POETRY ) run ruff --config=pyproject.toml --fix ./
86+ format-lint : lint
87+ ruff format --config=pyproject.toml ./
9588
9689.PHONY : install-npm
9790install-npm :
@@ -120,8 +113,9 @@ $(addprefix fix-, $(FORMATTERS)): fix-%: format-%
120113lint-all : lint mypy check-safety check-markdown
121114
122115.PHONY : update-dev-deps
123- update-dev-deps :
124- $(POETRY ) up --only=dev-dependencies --latest
116+ update-dev-deps : setup
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
125119
126120# * Cleaning
127121.PHONY : pycache-remove
0 commit comments