From 3b62de3facaec68b1887a3a509d62c3291e5d986 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 29 May 2024 17:35:25 +0300 Subject: [PATCH] Infra: makefile/RTD: Use uv if installed (#3791) --- .readthedocs.yaml | 3 +++ Makefile | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b2f23f8a7..9ba41b98a 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -10,6 +10,9 @@ build: python: "3" commands: + - asdf plugin add uv + - asdf install uv latest + - asdf global uv latest - make dirhtml JOBS=$(nproc) BUILDDIR=_readthedocs/html sphinx: diff --git a/Makefile b/Makefile index ac1580a97..f42532836 100644 --- a/Makefile +++ b/Makefile @@ -71,16 +71,28 @@ venv: echo "To recreate it, remove it first with \`make clean-venv'."; \ else \ echo "Creating venv in $(VENVDIR)"; \ - $(PYTHON) -m venv $(VENVDIR); \ - $(VENVDIR)/bin/python3 -m pip install -U pip wheel; \ - $(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \ + if uv --version > /dev/null; then \ + uv venv $(VENVDIR); \ + VIRTUAL_ENV=$(VENVDIR) uv pip install -r requirements.txt; \ + else \ + $(PYTHON) -m venv $(VENVDIR); \ + $(VENVDIR)/bin/python3 -m pip install --upgrade pip; \ + $(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \ + fi; \ echo "The venv has been created in the $(VENVDIR) directory"; \ fi +.PHONY: ensure-pre-commit +ensure-pre-commit: venv + if uv --version > /dev/null; then \ + $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || VIRTUAL_ENV=$(VENVDIR) uv pip install pre-commit; \ + else \ + $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit; \ + fi; + ## lint to lint all the files .PHONY: lint -lint: venv - $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit +lint: ensure-pre-commit $(VENVDIR)/bin/python3 -m pre_commit run --all-files ## test to test the Sphinx extensions for PEPs @@ -90,7 +102,7 @@ test: venv ## spellcheck to check spelling .PHONY: spellcheck -spellcheck: venv +spellcheck: ensure-pre-commit $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit $(VENVDIR)/bin/python3 -m pre_commit run --all-files --hook-stage manual codespell