Skip to content

Commit

Permalink
Merge pull request #61 from stac-extensions/fix-uv-install
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Nov 15, 2024
2 parents e8b03c0 + 4564af5 commit 08ce10c
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 185 deletions.
49 changes: 33 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#* Variables
SHELL ?= /usr/bin/env bash
ACTIVEPYTHON = $(shell which python)

# use the directory rather than the python binary to allow auto-discovery, which is more cross-platform compatible
PYTHON_PATH := $(shell which python)
PYTHON_ROOT := $(shell dirname $(dir $(PYTHON_PATH)))
UV_PYTHON_ROOT ?= $(PYTHON_ROOT)

# to actually reuse an existing virtual/conda environment, the 'UV_PROJECT_ENVIRONMENT' variable must be set to it
# use this command:
# UV_PROJECT_ENVIRONMENT=/path/to/env make [target]
# consider exporting this variable in '/path/to/env/etc/conda/activate.d/env.sh' to enable it by default when
# activating a conda environment, and reset it in '/path/to/env/etc/conda/deactivate.d/env.sh'
UV_PROJECT_ENVIRONMENT ?=
# make sure every uv command employs the specified environment path
ifeq (${UV_PROJECT_ENVIRONMENT},)
UV_COMMAND := uv
else
UV_COMMAND := UV_PROJECT_ENVIRONMENT="${UV_PROJECT_ENVIRONMENT}" uv
endif

#* UV
.PHONY: setup
Expand All @@ -9,35 +26,35 @@ setup:

.PHONY: publish
publish:
uv publish --build
$(UV_COMMAND) publish --build

#* Installation
.PHONY: install
install: setup
uv export --format requirements-txt -o requirements.txt --no-dev
uv pip install --python $(ACTIVEPYTHON) -r requirements.txt
$(UV_COMMAND) export --format requirements-txt -o requirements.txt --no-dev
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements.txt

.PHONY: install-dev
install-dev: setup
uv export --format requirements-txt -o requirements-dev.txt
uv pip install --python $(ACTIVEPYTHON) -r requirements-dev.txt
$(UV_COMMAND) export --format requirements-txt -o requirements-dev.txt
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements-dev.txt

.PHONY: pre-commit-install
pre-commit-install: setup
uv run --python $(ACTIVEPYTHON) pre-commit install
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" pre-commit install

#* Formatters
.PHONY: codestyle
codestyle: setup
uv run --python $(ACTIVEPYTHON) ruff format --config=pyproject.toml stac_model tests
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" ruff format --config=pyproject.toml stac_model tests

.PHONY: format
format: codestyle

#* Linting
.PHONY: test
test: setup
uv run --python $(ACTIVEPYTHON) pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/

.PHONY: check
check: check-examples check-markdown check-lint check-mypy check-safety check-citation
Expand All @@ -47,23 +64,23 @@ check-all: check

.PHONY: mypy
mypy: setup
uv run --python $(ACTIVEPYTHON) mypy --config-file pyproject.toml ./
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" mypy --config-file pyproject.toml ./

.PHONY: check-mypy
check-mypy: mypy

.PHONY: check-safety
check-safety: setup
uv run --python $(ACTIVEPYTHON) safety check --full-report
uv run --python $(ACTIVEPYTHON) bandit -ll --recursive stac_model tests
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" safety check --full-report
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" bandit -ll --recursive stac_model tests

.PHONY: lint
lint: setup
uv run --python $(ACTIVEPYTHON) ruff check --fix --config=pyproject.toml ./
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" ruff check --fix --config=pyproject.toml ./

.PHONY: check-lint
check-lint: lint
uv run --python $(ACTIVEPYTHON) ruff check --config=pyproject.toml ./
$(UV_COMMAND) run --python "$(UV_PYTHON_ROOT)" ruff check --config=pyproject.toml ./

.PHONY: format-lint
format-lint: lint
Expand Down Expand Up @@ -97,8 +114,8 @@ lint-all: lint mypy check-safety check-markdown

.PHONY: update-dev-deps
update-dev-deps: setup
uv export --only-dev --format requirements-txt -o requirements-only-dev.txt
uv pip install --python $(ACTIVEPYTHON) -r requirements-only-dev.txt
$(UV_COMMAND) export --only-dev --format requirements-txt -o requirements-only-dev.txt
$(UV_COMMAND) pip install --python "$(UV_PYTHON_ROOT)" -r requirements-only-dev.txt

#* Cleaning
.PHONY: pycache-remove
Expand Down
Loading

0 comments on commit 08ce10c

Please sign in to comment.