Skip to content

Commit

Permalink
Merge pull request #9179 from BinderDavid/fix-7977
Browse files Browse the repository at this point in the history
Make users-guide buildable from within doc/ subdirectory
  • Loading branch information
mergify[bot] authored Aug 21, 2023
2 parents 84acb0e + 8ed6ecf commit 41225bb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
32 changes: 6 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,13 @@ bootstrap-jsons: $(BOOTSTRAP_GHC_VERSIONS:%=bootstrap-json-%)
# documentation
##############################################################################

# TODO: when we have sphinx-build2 ?
SPHINXCMD:=sphinx-build
# Flag -n ("nitpick") warns about broken references
# Flag -W turns warnings into errors
# Flag --keep-going continues after errors
SPHINX_FLAGS:=-n -W --keep-going -E
SPHINX_HTML_OUTDIR:=dist-newstyle/doc/users-guide
USERGUIDE_STAMP:=$(SPHINX_HTML_OUTDIR)/index.html

# do pip install every time so we have up to date requirements when we build
users-guide: .python-sphinx-virtualenv $(USERGUIDE_STAMP)
$(USERGUIDE_STAMP) : doc/*.rst
mkdir -p $(SPHINX_HTML_OUTDIR)
(. ./.python-sphinx-virtualenv/bin/activate && pip install -r doc/requirements.txt && $(SPHINXCMD) $(SPHINX_FLAGS) doc $(SPHINX_HTML_OUTDIR))

.python-sphinx-virtualenv:
python3 -m venv .python-sphinx-virtualenv
(. ./.python-sphinx-virtualenv/bin/activate)

# This goal is intended for manual invocation, always rebuilds.
.PHONY: users-guide-requirements
users-guide-requirements: doc/requirements.txt
.PHONY: users-guide
users-guide:
$(MAKE) -C doc users-guide

.PHONY: doc/requirements.txt
doc/requirements.txt: .python-sphinx-virtualenv
. .python-sphinx-virtualenv/bin/activate \
&& make -C doc build-and-check-requirements
.PHONY: users-guide-requirements
users-guide-requirements:
$(MAKE) -C doc users-guide-requirements

ifeq ($(shell uname), Darwin)
PROCS := $(shell sysctl -n hw.logicalcpu)
Expand Down
40 changes: 37 additions & 3 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@
#
#
SKJOLD_GITHUB_API_TOKEN ?= ${GITHUB_TOKEN}
# TODO: when we have sphinx-build2 ?
SPHINXCMD:=sphinx-build
# Flag -n ("nitpick") warns about broken references
# Flag -W turns warnings into errors
# Flag --keep-going continues after errors
SPHINX_FLAGS:=-n -W --keep-going -E
SPHINX_HTML_OUTDIR:=../dist-newstyle/doc/users-guide
USERGUIDE_STAMP:=$(SPHINX_HTML_OUTDIR)/index.html
PYTHON_VIRTUALENV_ACTIVATE:=../.python-sphinx-virtualenv/bin/activate

# Python virtual environment
##############################################################################

# Create a python virtual environment in the root of the cabal repository.
$(PYTHON_VIRTUALENV_ACTIVATE):
python3 -m venv ../.python-sphinx-virtualenv
(. $(PYTHON_VIRTUALENV_ACTIVATE))

# Users guide
##############################################################################

# do pip install every time so we have up to date requirements when we build
users-guide: $(PYTHON_VIRTUALENV_ACTIVATE) $(USERGUIDE_STAMP)
$(USERGUIDE_STAMP) : *.rst
mkdir -p $(SPHINX_HTML_OUTDIR)
(. $(PYTHON_VIRTUALENV_ACTIVATE) && pip install -r requirements.txt && $(SPHINXCMD) $(SPHINX_FLAGS) . $(SPHINX_HTML_OUTDIR))

# Requirements
##############################################################################

##
# This goal is intended for manual invocation, always rebuilds.
.PHONY: users-guide-requirements
users-guide-requirements: requirements.txt

.PHONY: build-and-check-requirements
build-and-check-requirements: requirements.txt check-requirements
Expand All @@ -21,8 +55,8 @@ build-and-check-requirements: requirements.txt check-requirements
# requirements.txt is generated from requirements.in
# via pip-compile included in the pip-tools package.
# See https://modelpredict.com/wht-requirements-txt-is-not-enough
requirements.txt: requirements.in
. ../.python-sphinx-virtualenv/bin/activate \
requirements.txt: requirements.in $(PYTHON_VIRTUALENV_ACTIVATE)
. $(PYTHON_VIRTUALENV_ACTIVATE) \
&& pip install --upgrade pip \
&& pip install pip-tools \
&& pip-compile requirements.in
Expand All @@ -37,7 +71,7 @@ check-requirements:
echo "WARNING: Neither SKJOLD_GITHUB_API_TOKEN nor GITHUB_TOKEN is set." \
; echo "Vulnerability check via skjold might fail when using the GitHub GraphQL API." \
; fi
. ../.python-sphinx-virtualenv/bin/activate \
. $(PYTHON_VIRTUALENV_ACTIVATE) \
&& pip install skjold \
&& skjold audit
# NB: For portability, we use '.' (sh etc.) instead of 'source' (bash).
Expand Down
5 changes: 2 additions & 3 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ http://cabal.readthedocs.io/

### How to build it

Building the documentation requires Python 3 and PIP. From the root of cabal
repository run:
Building the documentation requires Python 3 and PIP. Run the following command either from the root of the cabal repository or from the `docs/` subdirectory:

``` console
make users-guide
Expand All @@ -33,7 +32,7 @@ generation step run
> make users-guide-requirements
```

in the root of the repository.
either from the root of the cabal repository or from the `docs/` subdirectory.

Note that generating `requirements.txt` is sensitive to the Python version.
The version currently used is stamped at the top of `requirements.txt`.
Expand Down

0 comments on commit 41225bb

Please sign in to comment.