Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

114 lines (88 sloc) 2.84 KB
import os
from pathlib import Path
from shutil import which
from invoke import task
PKG_NAME = "pelican"
PKG_PATH = Path("pelican")
DOCS_PORT = os.environ.get("DOCS_PORT", 8000)
ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/virtualenvs"))
VENV = str(VENV_PATH.expanduser())
TOOLS = ["poetry", "pre-commit"]
POETRY = which("poetry") if which("poetry") else (VENV / Path("bin") / "poetry")
which("pre-commit") if which("pre-commit") else (VENV / Path("bin") / "pre-commit")
def docbuild(c):
"""Build documentation""""{VENV}/bin/sphinx-build docs docs/_build")
def docserve(c):
"""Serve docs at http://localhost:$DOCS_PORT/ (default port is 8000)"""
from livereload import Server
server = Server()"docs/", lambda: docbuild(c))"CONTRIBUTING.rst", lambda: docbuild(c))"docs/*.rst", lambda: docbuild(c))
server.serve(port=DOCS_PORT, root="docs/_build")
def tests(c):
"""Run the test suite""""{VENV}/bin/pytest", pty=True)
def black(c, check=False, diff=False):
"""Run Black auto-formatter, optionally with --check or --diff"""
check_flag, diff_flag = "", ""
if check:
check_flag = "--check"
if diff:
diff_flag = "--diff""{VENV}/bin/black {check_flag} {diff_flag} {PKG_PATH}")
def isort(c, check=False, diff=False):
check_flag, diff_flag = "", ""
if check:
check_flag = "-c"
if diff:
diff_flag = "--diff"
f"{VENV}/bin/isort {check_flag} {diff_flag} --recursive {PKG_PATH}/*"
def flake8(c):"{VENV}/bin/flake8 {PKG_PATH}")
def lint(c):
isort(c, check=True)
black(c, check=True)
def tools(c):
"""Install tools in the virtual environment if not already on PATH"""
for tool in TOOLS:
if not which(tool):"{VENV}/bin/pip install {tool}")
def precommit(c):
"""Install pre-commit hooks to .git/hooks/pre-commit""""{PRECOMMIT} install")
def setup(c):"{VENV}/bin/pip install -U pip")
tools(c)"{POETRY} install")
def update_functional_tests(c):
"""Update the generated functional test output"""
f"bash -c 'LC_ALL=en_US.utf8 pelican -o {PKG_PATH}/tests/output/custom/ -s samples/ samples/content/'"
f"bash -c 'LC_ALL=fr_FR.utf8 pelican -o {PKG_PATH}/tests/output/custom_locale/ -s samples/ samples/content/'"
f"bash -c 'LC_ALL=en_US.utf8 pelican -o {PKG_PATH}/tests/output/basic/ samples/content/'"
You can’t perform that action at this time.