-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpy_dev_container_template.py
More file actions
executable file
·60 lines (48 loc) · 1.66 KB
/
py_dev_container_template.py
File metadata and controls
executable file
·60 lines (48 loc) · 1.66 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
60
#!/usr/bin/env python3
"""
Script to run the generation template.
To test, just create an empty directory then run this script from that directory.
"""
import shutil
from pathlib import Path
# the directory this script is running out of
source_directory = Path(__file__).parent.absolute()
# workspace directory
workspace_directory = Path(".").absolute()
# project name
project_name = workspace_directory.name
files_to_mutate: list[Path] = []
DIRECTORIES_TO_CREATE = [
"tests",
".dev_container_logs",
]
for d in DIRECTORIES_TO_CREATE:
target_path: Path = workspace_directory / d
if not target_path.exists():
target_path.mkdir()
DIRECTORIES_TO_COPY = [
(".devcontainer_template", ".devcontainer"),
(".vscode", ".vscode"),
]
for source, target in DIRECTORIES_TO_COPY:
source_path: Path = source_directory / source
target_path: Path = workspace_directory / target
if not target_path.exists():
shutil.copytree(source_path, target_path)
for f in target_path.glob("*.*"):
files_to_mutate.append(f)
FILES_TO_COPY = [
(".gitignore", ".gitignore"),
("pyproject.toml.template", "pyproject.toml"),
]
for source, target in FILES_TO_COPY:
source_path: Path = source_directory / source
target_path: Path = workspace_directory / target
if not target_path.exists():
shutil.copy(source_path, target_path)
files_to_mutate.append(f)
for f in files_to_mutate:
incoming = f.read_bytes()
outgoing = incoming.replace(b"<<WORKSPACE DIRECTORY>>", str(workspace_directory).encode("utf-8"))
outgoing = outgoing.replace(b"<<PROJECT NAME>>", project_name.encode("utf-8"))
f.write_bytes(outgoing)