Coverage for evaluation/project_template.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""`aq init` (V6.6.10): a new signal project from the template shipped in the wheel (`aether_quant/_templates/project/`). 

2 

3The template holds a starter signal, its tests (shape and no look-ahead), a pipeline file with its gate, a README and a GitHub 

4workflow that runs the tests and the pipeline on free runners. `{{name}}` and `{{version}}` are filled in when it is copied, and a 

5`.tmpl` suffix is dropped. 

6""" 

7 

8from __future__ import annotations 

9 

10from pathlib import Path 

11 

12TEMPLATE = Path(__file__).resolve().parents[1] / "aether_quant" / "_templates" / "project" 

13RENAMES = {"gitignore": ".gitignore", "workflow.yml": ".github/workflows/pipeline.yml"} 

14 

15 

16def template_files(template: Path = TEMPLATE) -> dict[str, Path]: 

17 """Each template file by the path it gets in the new project.""" 

18 out = {} 

19 for path in sorted(template.rglob("*")): 

20 if path.is_file() and "__pycache__" not in path.parts: 

21 relative = path.relative_to(template).as_posix() 

22 # `.tmpl`: the template's Python stays out of this repo's own lint, coverage and library gate until it is copied 

23 out[RENAMES.get(relative, relative.removesuffix(".tmpl"))] = path 

24 return out 

25 

26 

27def render(text: str, *, name: str, version: str) -> str: 

28 return text.replace("{{name}}", name).replace("{{version}}", version) 

29 

30 

31def create_project(target: Path, *, name: str | None = None, version: str = "0.0.0", template: Path = TEMPLATE) -> list[str]: 

32 """Writes the template into `target` (created if missing) and returns the files written. Refuses a folder that already holds 

33 anything, so an existing project is never overwritten.""" 

34 target = Path(target) 

35 if target.exists() and any(target.iterdir()): 

36 raise FileExistsError(f"{target} is not empty: aq init only writes into a new or empty folder") 

37 name = name or target.resolve().name 

38 written = [] 

39 for relative, source in template_files(template).items(): 

40 destination = target / relative 

41 destination.parent.mkdir(parents=True, exist_ok=True) 

42 destination.write_text(render(source.read_text(encoding="utf-8"), name=name, version=version), encoding="utf-8", newline="\n") 

43 written.append(relative) 

44 return written