-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_me.py
49 lines (35 loc) · 1.57 KB
/
run_me.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import typing as t
from pathlib import Path
BASE_NAME = "py-template"
BASE_DESCRIPTION = "It's a Python project template!"
BASE_NAME_UNDERSCORE = BASE_NAME.replace("-", "_")
class TemplateSwap(t.NamedTuple): # noqa: D101
src: Path
needs_hyphen: bool = False
has_description: bool = False
SWAPS = (
TemplateSwap(src=Path("./.flake8")),
TemplateSwap(src=Path("./pyproject.toml"), needs_hyphen=True, has_description=True),
TemplateSwap(src=Path("./README.md"), needs_hyphen=True, has_description=True),
TemplateSwap(src=Path("./tox.ini")),
# Release YAML has a hyphenated name (PyPI URL) and underscore name (build artifact)
TemplateSwap(src=Path("./.github/workflows/pypi_release.yml")),
TemplateSwap(src=Path("./.github/workflows/pypi_release.yml"), needs_hyphen=True),
)
def make_swaps(new_name: str, new_description: str) -> None: # noqa: D103
underscored_name = new_name.replace("-", "_")
Path("./py_template").rename(underscored_name)
for swap in SWAPS:
full_src = swap.src.read_text()
if swap.needs_hyphen:
full_src = full_src.replace(BASE_NAME, new_name)
else:
full_src = full_src.replace(BASE_NAME_UNDERSCORE, underscored_name)
if swap.has_description:
full_src = full_src.replace(BASE_DESCRIPTION, new_description)
swap.src.write_text(full_src)
if __name__ == "__main__":
new_name = input("New Package Name (hyphenated): ")
new_description = input("New Package Description: ")
make_swaps(new_name, new_description)
Path(__file__).unlink()