Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
# Builds PEP files to HTML using sphinx

PYTHON=python3
VENV_DIR=venv
VENVDIR=.venv
JOBS=8
RENDER_COMMAND=$(PYTHON) build.py -j $(JOBS)
RENDER_COMMAND=$(VENVDIR)/bin/python3 build.py -j $(JOBS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one installs make on windows, this would fail, right? As the executables directory is Scripts.

A

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use make on Windows, I've often seen a separate make.bat though so I think that is used instead of Makefile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AA-Turner correct, this is Unix-only. The PYTHON variable could be updated to use VENVDIR, but that would also allow for overriding the path to the Python executable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have make on my Windows dev machines and use it when necessary sometimes, but at least on this repo I don't really do so, and instead run the various commands I need directly (usually with custom invocations). I wouldn't expect very many if any non-WSL Windows users to do so either.


render:
render: venv
$(RENDER_COMMAND)

pages: rss
pages: venv rss
$(RENDER_COMMAND) --build-dirs

fail-warning:
fail-warning: venv
$(RENDER_COMMAND) --fail-on-warning

check-links:
check-links: venv
$(RENDER_COMMAND) --check-links

rss:
$(PYTHON) generate_rss.py
rss: venv
$(VENVDIR)/bin/python3 generate_rss.py

clean:
clean: clean-venv
-rm -rf build

venv:
$(PYTHON) -m venv $(VENV_DIR)
./$(VENV_DIR)/bin/python -m pip install -r requirements.txt

lint:
pre-commit --version > /dev/null || $(PYTHON) -m pip install pre-commit
pre-commit run --all-files
clean-venv:
rm -rf $(VENVDIR)

spellcheck:
pre-commit --version > /dev/null || $(PYTHON) -m pip install pre-commit
pre-commit run --all-files --hook-stage manual codespell
venv:
@if [ -d $(VENVDIR) ] ; then \
echo "venv already exists."; \
echo "To recreate it, remove it first with \`make clean-venv'."; \
else \
$(PYTHON) -m venv $(VENVDIR); \
$(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \
echo "The venv has been created in the $(VENVDIR) directory"; \
fi
Comment on lines +29 to +37
Copy link
Member

@AA-Turner AA-Turner Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of goes against the point of make as I understand it -- if the name exists on the filesystem then make won't run the target, whereas we need a lot of logic here to do the same thing and support customisation of the venv directory.

I really don't want to overcomplicate this -- whilst I have a desire to make usability better for PEP authors, no-one complained up until now, and so we should balance usability to PEP authors for whom the current Makefile doesn't work and maintainability to ourselves.

A

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, make is primarily for building/compiling files but this sort of thing is pretty common too.

This one is based on the CPython docs Makefile:

venv:
	@if [ -d $(VENVDIR) ] ; then \
		echo "venv already exists."; \
		echo "To recreate it, remove it first with \`make clean-venv'."; \
	else \
		$(PYTHON) -m venv $(VENVDIR); \
		$(VENVDIR)/bin/python3 -m pip install -U pip setuptools; \
		$(VENVDIR)/bin/python3 -m pip install -r requirements.txt; \
		echo "The venv has been created in the $(VENVDIR) directory"; \
	fi

The devguide's Makefile is similar:

venv:
	$(PYTHON) -m venv venv
	./venv/bin/python3 -m pip install --upgrade pip
	./venv/bin/python3 -m pip install -r requirements.txt

I'm sure I've seen similar in other https://github.com/python Makefiles, so using venvs is a fairy common pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a make expert, but as a general principle, I don't think we should let purity override practicality here, particularly when it comes to usability for PEP authors and contributors. We certainly want to reduce friction there as much as practical, and given all the changes lately and the remaining ones we want to do, making things easier rather than harder for users helps all that go more smoothly for everyone.


lint: venv
$(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

spellcheck: venv
$(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