copier/devtasks.py
Jairo Llopis 67cc4ffde3
feat: nix support
- Provide a dev shell.
- Provide a nix package.
- Provide a nix flake.
- Development environment based on direnv.
- Docs.
- Configure Gitpod to use direnv and nix.
- Configure Cachix out of the box, and document how to use it.
- Add direnv and nix to CI.
- Satisfy some linters that came from Precommix, even when Precommix was later discarded.
- Mark some tests as impure.
- Run only pure tests when building Copier with Nix.
- Add poetry loader to direnv.
- Update contribution guide.
2023-01-18 09:40:08 +00:00

53 lines
1.3 KiB
Python

"""Development helper tasks."""
import os
import shutil
from pathlib import Path
from subprocess import check_call
def clean():
"""Clean build, test or other process artifacts from the project workspace."""
build_artefacts = (
"build/",
"dist/",
"*.egg-info",
"pip-wheel-metadata",
)
python_artefacts = (
".pytest_cache",
"htmlcov",
".coverage",
"**/__pycache__",
"**/*.pyc",
"**/*.pyo",
)
project_dir = Path(".").resolve()
for pattern in build_artefacts + python_artefacts:
for matching_path in project_dir.glob(pattern):
print(f"Deleting {matching_path}")
if matching_path.is_dir():
shutil.rmtree(matching_path)
else:
matching_path.unlink()
def dev_setup():
"""Set up a development environment."""
# Gitpod sets PIP_USER=yes, which breaks poetry
env = dict(os.environ, PIP_USER="no")
check_call(["poetry", "install", "--with", "docs"], env=env)
check_call(
[
"poetry",
"run",
"pre-commit",
"install",
"-t",
"pre-commit",
"-t",
"commit-msg",
],
env=env,
)
check_call(["poetry", "run", "pre-commit", "install-hooks"], env=env)