From 759a21ee884e61587ade8022fbf45314ea44724e Mon Sep 17 00:00:00 2001 From: Bill Wallis Date: Fri, 10 Apr 2026 11:08:20 +0100 Subject: [PATCH] feat: add script to apply template locally --- .pre-commit-config.yaml | 2 +- README.md | 2 +- tools/apply.py | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tools/apply.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d5f2324..f336686 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -65,7 +65,7 @@ repos: entry: check-jsonschema pass_filenames: true language: python - additional_dependencies: ["check-jsonschema==0.37.0"] + additional_dependencies: ["check-jsonschema==0.37.1"] # This calls a remote URL, so run on pre-push to avoid slowing down commits stages: ["pre-push"] id: check-pyproject-schema diff --git a/README.md b/README.md index 6528144..b3249bd 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,6 @@ After copying, find and replace on: Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and then install the dependencies: -```bash +```shell uvx --from poethepoet poe install ``` diff --git a/tools/apply.py b/tools/apply.py new file mode 100644 index 0000000..e9a9eb5 --- /dev/null +++ b/tools/apply.py @@ -0,0 +1,53 @@ +import argparse +import logging +import pathlib +import shutil +from collections.abc import Sequence + +SUCCESS = 0 +FAILURE = 1 +ROOT = pathlib.Path(__file__).parent.parent +FILES_TO_COPY = [ + ".github/workflows/tests.yaml", + ".gitignore", + ".pre-commit-config.yaml", + "LICENSE", + "pyproject.toml", +] + + +def copy_files_to_target(target: pathlib.Path) -> int: + if not target.exists(): + logging.error(f"target {target} does not exist") + return FAILURE + if not target.is_dir(): + logging.error(f"target {target} is not a directory") + return FAILURE + + for file in FILES_TO_COPY: + shutil.copy(ROOT / file, target / file) + + return SUCCESS + + +def main(argv: Sequence[str] | None = None) -> int: + """ + Parse the arguments and run the command. + """ + + parser = argparse.ArgumentParser() + parser.add_argument("targets", nargs="*") + + args = parser.parse_args(argv) + ret = SUCCESS + if not args.targets: + parser.print_help() + for target in args.targets: + ret |= copy_files_to_target(target=pathlib.Path(target)) + + return ret + + +if __name__ == "__main__": + # python -m tools.apply + raise SystemExit(main())