Add Windows support to Invoke tasks

This commit is contained in:
Justin Mayer 2020-04-24 15:21:05 +02:00
commit 1ac4abcb67

View file

@ -7,22 +7,24 @@ from invoke import task
PKG_NAME = "pelican"
PKG_PATH = Path("pelican")
DOCS_PORT = os.environ.get("DOCS_PORT", 8000)
BIN_DIR = "bin" if os.name != "nt" else "Scripts"
ACTIVE_VENV = os.environ.get("VIRTUAL_ENV", None)
VENV_HOME = Path(os.environ.get("WORKON_HOME", "~/virtualenvs"))
VENV_PATH = Path(ACTIVE_VENV) if ACTIVE_VENV else (VENV_HOME / PKG_NAME)
VENV = str(VENV_PATH.expanduser())
VENV_BIN = Path(VENV) / Path(BIN_DIR)
TOOLS = ["poetry", "pre-commit"]
POETRY = which("poetry") if which("poetry") else (VENV / Path("bin") / "poetry")
POETRY = which("poetry") if which("poetry") else (VENV_BIN / "poetry")
PRECOMMIT = (
which("pre-commit") if which("pre-commit") else (VENV / Path("bin") / "pre-commit")
which("pre-commit") if which("pre-commit") else (VENV_BIN / "pre-commit")
)
@task
def docbuild(c):
"""Build documentation"""
c.run(f"{VENV}/bin/sphinx-build docs docs/_build")
c.run(f"{VENV_BIN}/sphinx-build docs docs/_build")
@task(docbuild)
@ -40,7 +42,7 @@ def docserve(c):
@task
def tests(c):
"""Run the test suite"""
c.run(f"{VENV}/bin/pytest", pty=True)
c.run(f"{VENV_BIN}/pytest", pty=True)
@task
@ -51,7 +53,7 @@ def black(c, check=False, diff=False):
check_flag = "--check"
if diff:
diff_flag = "--diff"
c.run(f"{VENV}/bin/black {check_flag} {diff_flag} {PKG_PATH} tasks.py")
c.run(f"{VENV_BIN}/black {check_flag} {diff_flag} {PKG_PATH} tasks.py")
@task
@ -62,13 +64,13 @@ def isort(c, check=False, diff=False):
if diff:
diff_flag = "--diff"
c.run(
f"{VENV}/bin/isort {check_flag} {diff_flag} --recursive {PKG_PATH}/* tasks.py"
f"{VENV_BIN}/isort {check_flag} {diff_flag} --recursive {PKG_PATH}/* tasks.py"
)
@task
def flake8(c):
c.run(f"{VENV}/bin/flake8 {PKG_PATH} tasks.py")
c.run(f"{VENV_BIN}/flake8 {PKG_PATH} tasks.py")
@task
@ -83,7 +85,7 @@ def tools(c):
"""Install tools in the virtual environment if not already on PATH"""
for tool in TOOLS:
if not which(tool):
c.run(f"{VENV}/bin/pip install {tool}")
c.run(f"{VENV_BIN}/python -m pip install {tool}")
@task
@ -94,7 +96,7 @@ def precommit(c):
@task
def setup(c):
c.run(f"{VENV}/bin/pip install -U pip")
c.run(f"{VENV_BIN}/python -m pip install -U pip")
tools(c)
c.run(f"{POETRY} install")
precommit(c)