Skip to content

Commit

Permalink
♻️ Change Makefile to use poetry + work on windows (with the exceptio…
Browse files Browse the repository at this point in the history
…n of the publish target)
  • Loading branch information
bruxisma committed Mar 17, 2024
1 parent 608ecee commit 1a5745a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/_site/
/site/
/_ext/__pycache__/
__pycache__
53 changes: 37 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
# Makefile for Sphinx documentation
GNUMAKEFLAGS := --no-builtins --no-builtin-variables
.SUFFIXES:

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
BUILDDIR = _site
ifeq ($(OS),Windows_NT)
--which := where
--null := nul
RM := rmdir /s /q
else
--which := which
--null ?= /dev/null
RM := rm -rf
endif

POETRY ?= $(shell $(--which) poetry 2> $(--null))

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
ifeq (${POETRY},)
$(error Could not find the `poetry` command. \
Please make sure you have installed poetry, and that it is on your system's PATH environment variable. \
If you don't have poetry installed, please visit https://python-poetry.org for instructions on its installation.)
endif

.PHONY: clean all
venv ?= $(shell $(POETRY) env info --path 2> $(--null))

all:
$(SPHINXBUILD) -b html $(SPHINXOPTS) . $(BUILDDIR)
@echo
@echo "Build finished. The HTML pages are in '$(BUILDDIR)'."
srcdir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))

clean:
rm -rf $(BUILDDIR)/*
build.flags += $(if $(BUILDER),-b $(BUILDER),-b html)
build.flags += $(if $(NOCOLOR),,--color)
build.flags += $(if $(SPHINXOPTS),$(SPHINXOPTS))

SRCDIR ?= $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
OUTDIR ?= $(join $(SRCDIR),_site)

.PHONY: all setup cache-clean clean

all: $(if $(venv),,setup)
$(POETRY) run sphinx-build ${build.flags} "${SRCDIR}" "${OUTDIR}"

cache-clean:
rm -rf $(BUILDDIR)/.doctrees
$(RM) "$(join $(OUTDIR),.doctrees)"

clean:
$(RM) "$(OUTDIR)"

setup:
$(POETRY) install

publish: clean all
./publish.sh

0 comments on commit 1a5745a

Please sign in to comment.