Skip to content

Commit 4e47f8a

Browse files
authored
[3.12] Docs makefile/RTD: Use uv if installed (GH-120711) (#120923)
1 parent daef7de commit 4e47f8a

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

.readthedocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ build:
1313
python: "3"
1414

1515
commands:
16+
- asdf plugin add uv
17+
- asdf install uv latest
18+
- asdf global uv latest
1619
- make -C Doc venv html
1720
- mkdir _readthedocs
1821
- mv Doc/build/html _readthedocs/html

Doc/Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ htmlview: html
152152

153153
.PHONY: ensure-sphinx-autobuild
154154
ensure-sphinx-autobuild: venv
155-
$(VENVDIR)/bin/sphinx-autobuild --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install sphinx-autobuild
155+
$(call ensure_package,sphinx-autobuild)
156156

157157
.PHONY: htmllive
158158
htmllive: SPHINXBUILD = $(VENVDIR)/bin/sphinx-autobuild
@@ -174,10 +174,15 @@ venv:
174174
echo "To recreate it, remove it first with \`make clean-venv'."; \
175175
else \
176176
echo "Creating venv in $(VENVDIR)"; \
177-
$(PYTHON) -m venv $(VENVDIR); \
178-
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
179-
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
180-
echo "The venv has been created in the $(VENVDIR) directory"; \
177+
if uv --version > /dev/null; then \
178+
uv venv $(VENVDIR); \
179+
VIRTUAL_ENV=$(VENVDIR) uv pip install -r $(REQUIREMENTS); \
180+
else \
181+
$(PYTHON) -m venv $(VENVDIR); \
182+
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
183+
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
184+
echo "The venv has been created in the $(VENVDIR) directory"; \
185+
fi; \
181186
fi
182187

183188
.PHONY: dist
@@ -235,9 +240,17 @@ dist:
235240
rm -r dist/python-$(DISTVERSION)-docs-texinfo
236241
rm dist/python-$(DISTVERSION)-docs-texinfo.tar
237242

243+
define ensure_package
244+
if uv --version > /dev/null; then \
245+
$(VENVDIR)/bin/python3 -m $(1) --version > /dev/null || VIRTUAL_ENV=$(VENVDIR) uv pip install $(1); \
246+
else \
247+
$(VENVDIR)/bin/python3 -m $(1) --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install $(1); \
248+
fi
249+
endef
250+
238251
.PHONY: check
239252
check: venv
240-
$(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit
253+
$(call ensure_package,pre_commit)
241254
$(VENVDIR)/bin/python3 -m pre_commit run --all-files
242255

243256
.PHONY: serve

0 commit comments

Comments
 (0)