-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcli.py
More file actions
59 lines (46 loc) · 1.76 KB
/
cli.py
File metadata and controls
59 lines (46 loc) · 1.76 KB
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
50
51
52
53
54
55
56
57
58
59
"""python_seed.scripts.cli."""
import os
import shutil
import click
from .. import __version__
try:
from importlib.resources import files as resources_files # type: ignore
except ImportError:
# Try backported to PY<39 `importlib_resources`.
from importlib_resources import files as resources_files # type: ignore
@click.group(short_help="python-seed CLI")
@click.version_option(version=__version__, message="%(version)s")
def pyseed():
"""python-seed subcommands."""
pass
@pyseed.command(short_help="Create new python seed skeleton")
@click.argument("name", type=str, nargs=1)
@click.option(
"--ci", type=click.Choice(["circleci", "github"]), help="Add CI configuration"
)
def create(name, ci):
"""Create new python seed skeleton."""
template_dir = str(resources_files("python_seed") / "template" / "module")
shutil.copytree(template_dir, name)
if ci:
template_dir = str(
resources_files("python_seed") / "template" / "ci" / f".{ci}"
)
shutil.copytree(template_dir, f"{name}/.{ci}")
covconfig = str(
resources_files("python_seed") / "template" / "cov" / "codecov.yml"
)
shutil.copy2(covconfig, f"{name}/codecov.yml")
new_dir = name
name = name.replace("-", "_")
for root, _, files in os.walk(new_dir):
if root.endswith("pyseed"):
shutil.move(root, root.replace("pyseed", name))
for root, _, files in os.walk(new_dir):
for filename in files:
if filename.endswith(".pyc"):
continue
with open(f"{root}/{filename}", "r", encoding="utf-8") as f:
s = f.read().replace("pyseed", name)
with open(f"{root}/{filename}", "w", encoding="utf-8") as f:
f.write(s)