Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06b20b5

Browse files
committed
Remove GNU make-specific directive from Doc/Makefile
`define` - https://www.gnu.org/software/make/manual/html_node/Multi_002dLine.html - is a GNU make extension not generally supported by other makes. Introduce `UV` variable to accomodate for the case when `uv` is not in `PATH`. Remove the ```bash $ python -m $(1) --version >/dev/null ``` commands that can prevent the installation of a package when it's already present. The rationale is this approach is really fragile, for multiple reasons. Firstly, it works on packages defining `__main__.py` module, there- fore as an example, `anyio==4.4.0` package, even if installed, would output: ```bash $ /tmp/venv/bin/python -m anyio >/dev/null /tmp/venv/bin/python: No module named anyio.__main__; 'anyio' is a package and cannot be directly executed $ echo $? 1 ``` Secondly, unlike package installation, which is insensitive to capitalization as well as `-`/`_` separators - https://packaging.python.org/en/latest/specifications/name-normalization/#names-and-normalization - module names are sensitive to naming, meaning this may happen (and indeed happened in bc37ac7) ```bash $ /tmp/venv/bin/python -m sphinx-autobuild --help >/dev/null /tmp/venv/bin/python: No module named sphinx-autobuild $ echo $? 1 $ /tmp/venv/bin/python -m sphinx_autobuild --help >/dev/null $ echo $? 0 ``` And lastly, name of the package may not be the same as its contents that are subsequently imported. Consider `PyYAML==6.0.1`, whose contents are importable from the `yaml` namespace - https://pyyaml.org/wiki/PyYAMLDocumentation ```bash $ /tmp/venv/bin/python -m pyyaml >/dev/null /tmp/venv/bin/python: No module named pyyaml $ /tmp/venv/bin/python -m yaml >/dev/null /tmp/venv/bin/python: No module named yaml.__main__; 'yaml' is a package and cannot be directly executed ```
1 parent 151934a commit 06b20b5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Doc/Makefile

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# You can set these variables from the command line.
77
PYTHON = python3
88
VENVDIR = ./venv
9+
UV = uv
910
SPHINXBUILD = PATH=$(VENVDIR)/bin:$$PATH sphinx-build
1011
BLURB = PATH=$(VENVDIR)/bin:$$PATH blurb
1112
JOBS = auto
@@ -150,14 +151,10 @@ gettext: build
150151
htmlview: html
151152
$(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('build/html/index.html'))"
152153

153-
.PHONY: ensure-sphinx-autobuild
154-
ensure-sphinx-autobuild: venv
155-
$(call ensure_package,sphinx-autobuild)
156-
157154
.PHONY: htmllive
158155
htmllive: SPHINXBUILD = $(VENVDIR)/bin/sphinx-autobuild
159156
htmllive: SPHINXOPTS = --re-ignore="/venv/" --open-browser --delay 0
160-
htmllive: ensure-sphinx-autobuild html
157+
htmllive: _ensure-sphinx-autobuild html
161158

162159
.PHONY: clean
163160
clean: clean-venv
@@ -174,15 +171,15 @@ venv:
174171
echo "To recreate it, remove it first with \`make clean-venv'."; \
175172
else \
176173
echo "Creating venv in $(VENVDIR)"; \
177-
if uv --version > /dev/null; then \
178-
uv venv $(VENVDIR); \
179-
VIRTUAL_ENV=$(VENVDIR) uv pip install -r $(REQUIREMENTS); \
174+
if $(UV) --version >/dev/null 2>&1; then \
175+
$(UV) venv $(VENVDIR); \
176+
VIRTUAL_ENV=$(VENVDIR) $(UV) pip install -r $(REQUIREMENTS); \
180177
else \
181178
$(PYTHON) -m venv $(VENVDIR); \
182179
$(VENVDIR)/bin/python3 -m pip install --upgrade pip; \
183180
$(VENVDIR)/bin/python3 -m pip install -r $(REQUIREMENTS); \
184-
echo "The venv has been created in the $(VENVDIR) directory"; \
185181
fi; \
182+
echo "The venv has been created in the $(VENVDIR) directory"; \
186183
fi
187184

188185
.PHONY: dist
@@ -240,17 +237,24 @@ dist:
240237
rm -r dist/python-$(DISTVERSION)-docs-texinfo
241238
rm dist/python-$(DISTVERSION)-docs-texinfo.tar
242239

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); \
240+
.PHONY: _ensure-package
241+
_ensure-package: venv
242+
if $(UV) --version >/dev/null 2>&1; then \
243+
VIRTUAL_ENV=$(VENVDIR) $(UV) pip install $(PACKAGE); \
246244
else \
247-
$(VENVDIR)/bin/python3 -m $(1) --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install $(1); \
245+
$(VENVDIR)/bin/python3 -m pip install $(PACKAGE); \
248246
fi
249-
endef
247+
248+
.PHONY: _ensure-pre-commit
249+
_ensure-pre-commit:
250+
make _ensure-package PACKAGE=pre-commit
251+
252+
.PHONY: _ensure-sphinx-autobuild
253+
_ensure-sphinx-autobuild:
254+
make _ensure-package PACKAGE=sphinx-autobuild
250255

251256
.PHONY: check
252-
check: venv
253-
$(call ensure_package,pre_commit)
257+
check: _ensure-pre-commit
254258
$(VENVDIR)/bin/python3 -m pre_commit run --all-files
255259

256260
.PHONY: serve

0 commit comments

Comments
 (0)