Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ top-right and select "Create a new repository":
This will create a new repository that's an exact copy of exemplar. The next step is to
customize it for your use case.

To do so, execute the bash script `stamp.sh`. This script will prompt for parameters like
To do so, execute the python script `stamp.py`. This script will prompt for parameters like
the new library's name, paper number, and description. Then it will replace your exemplar
copy with a stamped-out template containing these parameters and create a corresponding
git commit and branch:

```
$ ./stamp.sh
$ python stamp.py
[1/6] project_name (my_project_name): example_library
[2/6] maintainer (your_github_username): your_username
[3/6] minimum_cpp_build_version (20):
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter/check_cookiecutter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function check_consistency() {
cp "$script_dir"/../.github/workflows/todo_exemplar_test.yml "$out_dir_path"/exemplar/.github/workflows
mkdir "$out_dir_path"/exemplar/images
cp "$script_dir"/../images/use-this-template.png "$out_dir_path"/exemplar/images/use-this-template.png
cp "$script_dir"/../stamp.sh "$out_dir_path"/exemplar/stamp.sh
cp "$script_dir"/../stamp.py "$out_dir_path"/exemplar/stamp.py
local diff_path
diff_path=$(mktemp)
diff -r "$script_dir/.." "$out_dir_path/exemplar" \
Expand Down
4 changes: 2 additions & 2 deletions cookiecutter/{{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ top-right and select "Create a new repository":
This will create a new repository that's an exact copy of exemplar. The next step is to
customize it for your use case.

To do so, execute the bash script `stamp.sh`. This script will prompt for parameters like
To do so, execute the python script `stamp.py`. This script will prompt for parameters like
the new library's name, paper number, and description. Then it will replace your exemplar
copy with a stamped-out template containing these parameters and create a corresponding
git commit and branch:

```
$ ./stamp.sh
$ python stamp.py
[1/6] project_name (my_project_name): example_library
[2/6] maintainer (your_github_username): your_username
[3/6] minimum_cpp_build_version (20):
Expand Down
38 changes: 38 additions & 0 deletions stamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#!/usr/bin/env python3
import os, shutil, subprocess, sys, tempfile
from pathlib import Path

if "-h" in sys.argv or "--help" in sys.argv:
print("stamp.py -- beman exemplar template library creation tool\n\n"
"This script is intended to be run on a fork of exemplar.\n\n"
"It sets up cookiecutter, runs it on the cookiecutter template, replaces the\n"
"repository's current contents with the result, runs pre-commit,\n"
"switches to a new branch 'stamp', and creates a git commit.\n\n"
"All parameters are passed through to the cookiecutter invocation.")
sys.exit(0)

repo_dir = Path(__file__).parent.resolve()
os.chdir(repo_dir)

with tempfile.TemporaryDirectory() as v_dir, tempfile.TemporaryDirectory() as o_dir:
v_dir, o_dir = Path(v_dir), Path(o_dir)
subprocess.run([sys.executable, "-m", "venv", str(v_dir)], check=True)
bin_dir = v_dir / ("Scripts" if os.name == "nt" else "bin")
python = bin_dir / ("python.exe" if os.name == "nt" else "python")

subprocess.run([str(python), "-m", "pip", "install", "cookiecutter", "pre-commit"], capture_output=True, check=True)
subprocess.run([str(python), "-m", "cookiecutter", str(repo_dir / "cookiecutter"), "-o", str(o_dir)] + sys.argv[1:], check=True)
subprocess.run(["git", "rm", "-rf", "."], capture_output=True, check=True)
gen_dir = next(o_dir.iterdir())
for item in gen_dir.iterdir():
if item.is_dir(): shutil.copytree(item, repo_dir / item.name, dirs_exist_ok=True)
else: shutil.copy2(item, repo_dir / item.name)
subprocess.run(["git", "add", "."], capture_output=True, check=True)
pc = bin_dir / ("pre-commit.exe" if os.name == "nt" else "pre-commit")
subprocess.run([str(pc), "run", "--all-files"], capture_output=True)
subprocess.run(["git", "add", "."], capture_output=True, check=True)
subprocess.run(["git", "checkout", "-b", "stamp"], check=True)
subprocess.run(["git", "commit", "-q", "-m", "Stamp out exemplar template"], check=True)
print("Successfully stamped out exemplar template to the new branch 'stamp'.")
print("Try 'git push origin stamp' to push the branch upstream,\nthen create a pull request.")
44 changes: 0 additions & 44 deletions stamp.sh

This file was deleted.

Loading