diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 33785e63..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "example"] - path = example - url = https://github.com/DiamondLightSource/python-copier-template-example.git diff --git a/Dockerfile b/Dockerfile index 38092471..8dd09a45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,12 @@ +# This file is for use as a devcontainer +# +# The devcontainer should use the developer target and run as root with podman +# or docker with user namespaces. ARG PYTHON_VERSION=3.11 FROM python:${PYTHON_VERSION} as developer +RUN apt-get update && apt-get upgrade -y && \ + apt-get install -y --no-install-recommends \ + graphviz \ + && rm -rf /var/lib/apt/lists/* RUN python -m venv /venv -ENV PATH=/venv/bin:$PATH \ No newline at end of file +ENV PATH=/venv/bin:$PATH diff --git a/copier.yml b/copier.yml index 9671b5f1..66a47c65 100644 --- a/copier.yml +++ b/copier.yml @@ -31,7 +31,7 @@ repo_name: help: Name of the repository default: "{{ package_name | replace('_', '-') }}" validator: >- - {% if not (repo_name | regex_search('^[a-zA-Z][a-zA-Z_\-0-9]+$')) %} + {% if not (repo_name | regex_search('^[a-zA-Z][a-zA-Z_\\-0-9]+$')) %} {{ repo_name }} is not a valid repo name {% endif %} @@ -88,4 +88,4 @@ docs_url: when: false _tasks: - - "git init --initial-branch=main" \ No newline at end of file + - "git init --initial-branch=main" diff --git a/dev-requirements.txt b/dev-requirements.txt index 406de27e..d1d9b9cb 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -72,8 +72,6 @@ sphinxcontrib-serializinghtml==1.1.10 tornado==6.4 tox==3.28.0 tox-direct==0.4 -treecomp==1.0.0 -typer==0.9.0 typing-extensions==4.9.0 urllib3==2.1.0 virtualenv==20.25.0 diff --git a/example b/example deleted file mode 160000 index 24c2b73b..00000000 --- a/example +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 24c2b73bfd3899c337eeb27749a4485613638c6f diff --git a/pyproject.toml b/pyproject.toml index 31b6a5a6..88bfaa0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,10 @@ +[build-system] +requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"] +build-backend = "setuptools.build_meta" + [project] name = "python-copier-template" -version = "0.0" +dynamic = ["version"] [project.optional-dependencies] dev = [ @@ -15,7 +19,6 @@ dev = [ "sphinx-copybutton", "sphinx-design", "tox-direct", - "treecomp", ] [tool.pytest.ini_options] diff --git a/template/README.rst.jinja b/template/README.rst.jinja index 966b0650..91c56595 100644 --- a/template/README.rst.jinja +++ b/template/README.rst.jinja @@ -1,5 +1,5 @@ {{package_name}} -=========================== +============================================================================= |code_ci| |docs_ci| |coverage| |pypi_version| |license| diff --git a/tests/test_example.py b/tests/test_example.py index 7170a29b..f5b8170a 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,26 +1,61 @@ -import shutil +import shlex +import subprocess from pathlib import Path -import treecomp -import yaml +import pytest from copier import run_copy +from prompt_toolkit.validation import ValidationError TOP = Path(__file__).absolute().parent.parent -INPUT = TOP / "example" -OUTPUT = TOP / "build" / "example" -def test_template(): - shutil.rmtree(OUTPUT, ignore_errors=True) - answers = yaml.safe_load((INPUT / ".copier-answers.yml").read_text()) +def copy_project( + project_path: Path, + author_email="tom.cobb@diamond.ac.uk", + author_name="Tom Cobb", + component_owner="group:default/sscc", + description="An expanded python-copier-template with all the options", + distribution_name="dls-python-copier-template-example", + docker=True, + docs_type="sphinx", + git_platform="github.com", + github_org="DiamondLightSource", + package_name="python_copier_template_example", + repo_name="python-copier-template-example", +): + answers = locals() + answers.pop("project_path") run_copy( src_path=str(TOP), - dst_path=OUTPUT, + dst_path=project_path, data=answers, vcs_ref="HEAD", unsafe=True, ) - # - comparison = treecomp.diff_file_trees(INPUT, OUTPUT, ignore=[".copier-answers.yml"]) - if comparison.diffs: - raise AssertionError(str(comparison)) + + +def test_template(tmp_path: Path): + project = tmp_path / "project" + venv = tmp_path / "venv" + copy_project(project) + + def run(cmd: str): + sp = subprocess.run( + shlex.split(cmd), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + cwd=str(project), + ) + assert sp.returncode == 0, sp.stdout.decode() + + run(f"python -m venv {venv}") + run(f"{venv}/bin/python -m pip install -e .[dev]") + run(f"{venv}/bin/tox -p") + + +def test_bad_repo_name(tmp_path: Path): + with pytest.raises(ValidationError, match="bad:thing is not a valid repo name"): + copy_project(tmp_path, repo_name="bad:thing") + + +# TODO: check that copier update python-copier-template-example matches generated