Skip to content

Commit d8d6b91

Browse files
cjrhzware
authored andcommitted
bpo-30487: automatically create a venv and install Sphinx when running make (GH-4346)
1 parent a6fba9b commit d8d6b91

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ matrix:
3636
# (Updating the version is fine as long as no warnings are raised by doing so.)
3737
- python -m pip install sphinx~=1.6.1 blurb
3838
script:
39-
- make check suspicious html SPHINXOPTS="-q -W -j4"
39+
- make check suspicious html SPHINXBUILD="sphinx-build" SPHINXOPTS="-q -W -j4"
4040
- os: linux
4141
language: c
4242
compiler: gcc

Doc/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees -D latex_elements.papersize=$(PA
1717

1818
.PHONY: help build html htmlhelp latex text changes linkcheck \
1919
suspicious coverage doctest pydoc-topics htmlview clean dist check serve \
20-
autobuild-dev autobuild-stable venv
20+
autobuild-dev autobuild-stable
2121

2222
help:
2323
@echo "Please use \`make <target>' where <target> is one of"
@@ -39,7 +39,7 @@ help:
3939
@echo " check to run a check for frequent markup errors"
4040
@echo " serve to serve the documentation on the localhost (8000)"
4141

42-
build:
42+
build: venv
4343
-mkdir -p build
4444
# Look first for a Misc/NEWS file (building from a source release tarball
4545
# or old repo) and use that, otherwise look for a Misc/NEWS.d directory
@@ -122,9 +122,11 @@ clean:
122122
-rm -rf build/* $(VENVDIR)/*
123123

124124
venv:
125-
$(PYTHON) -m venv $(VENVDIR)
126-
$(VENVDIR)/bin/python3 -m pip install -U Sphinx blurb
127-
@echo "The venv has been created in the $(VENVDIR) directory"
125+
@if [ "$(SPHINXBUILD)" == "PATH=$(VENVDIR)/bin:$$PATH sphinx-build" ]; then \
126+
$(PYTHON) -m venv $(VENVDIR); \
127+
echo "A virtual environment for Docs has been made in the $(VENVDIR) directory"; \
128+
$(VENVDIR)/bin/python3 -m pip install Sphinx blurb; \
129+
fi
128130

129131
dist:
130132
rm -rf dist

Doc/README.rst

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,16 @@ tree but are maintained separately and are available from
2121
* `Sphinx <https://pypi.org/project/Sphinx/>`_
2222
* `blurb <https://pypi.org/project/blurb/>`_
2323

24-
The easiest way to install these tools is to create a virtual environment and
25-
install the tools into there.
24+
You could manually create a virtual environment and install them, but there is
25+
a ``Makefile`` already set up to do this for you, as long as you have a working
26+
Python 3 interpreter available.
2627

2728

2829
Using make
2930
----------
3031

31-
To get started on UNIX, you can create a virtual environment with the command ::
32-
33-
make venv
34-
35-
That will install all the tools necessary to build the documentation. Assuming
36-
the virtual environment was created in the ``env`` directory (the default;
37-
configurable with the VENVDIR variable), you can run the following command to
38-
build the HTML output files::
32+
A Makefile has been prepared so that (on Unix), after you change into the
33+
``Doc/`` directory you can simply run ::
3934

4035
make html
4136

@@ -44,8 +39,17 @@ look for instances of sphinxbuild and blurb installed on your process PATH
4439
(configurable with the SPHINXBUILD and BLURB variables).
4540

4641
On Windows, we try to emulate the Makefile as closely as possible with a
47-
``make.bat`` file. If you need to specify the Python interpreter to use,
48-
set the PYTHON environment variable instead.
42+
``make.bat`` file.
43+
44+
To use a Python interpreter that's not called ``python3``, use the standard
45+
way to set Makefile variables, using e.g. ::
46+
47+
make html PYTHON=python
48+
49+
On Windows, set the PYTHON environment variable instead.
50+
51+
To use a specific sphinx-build (something other than ``sphinx-build``), set
52+
the SPHINXBUILD variable.
4953

5054
Available make targets are:
5155

@@ -104,11 +108,14 @@ Available make targets are:
104108
Without make
105109
------------
106110

107-
First, install the tool dependencies from PyPI.
108-
109-
Then, from the ``Doc`` directory, run ::
111+
Install the Sphinx package and its dependencies from PyPI. In this situation,
112+
you'll have to create a virtual environment manually, and install Sphinx into
113+
it. Change into the ``Doc`` directory and run ::
110114

111-
sphinx-build -b<builder> . build/<builder>
115+
$ python3 -m venv venv
116+
$ source venv/bin/activate
117+
(venv) $ pip install Sphinx
118+
(venv) $ sphinx-build -b<builder> . build/<builder>
112119

113120
where ``<builder>`` is one of html, text, latex, or htmlhelp (for explanations
114121
see the make targets above).

0 commit comments

Comments
 (0)