forked from moskomule/pyproject_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
62 lines (43 loc) · 1.52 KB
/
init.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
50
51
52
53
54
55
56
57
58
59
60
61
62
import pathlib
def pyproject_toml(owner_name: str, repo_name: str):
file = pathlib.Path("pyproject.toml")
with file.open('r') as f:
content = f.read()
content = content.format(owner_name=owner_name, repo_name=repo_name)
with file.open('w') as f:
f.write(content)
def mkdocs(owner_name: str, repo_name: str):
file = pathlib.Path("mkdocs.yml")
with file.open('r') as f:
content = f.read()
content = content.format(owner_name=owner_name, repo_name=repo_name)
with file.open('w') as f:
f.write(content)
docs_root = pathlib.Path("docs")
with (docs_root / "index.md").open('w') as f:
f.write(f"# {repo_name}")
def project_dir(repo_name: str):
root = pathlib.Path(repo_name)
root.mkdir()
(root / "__init__.py").touch()
with (root / "__about__.py").open('w') as f:
f.write("__version__ = '0.0.1'")
def readme(owner_name: str, repo_name: str):
file = pathlib.Path("README.md")
with file.open('r') as f:
content = f.read()
content = content.split('---')[1]
content = content.format(owner_name=owner_name, repo_name=repo_name)
with file.open('w') as f:
f.write(content)
if __name__ == "__main__":
import argparse
p = argparse.ArgumentParser()
p.add_argument("name")
args = p.parse_args()
name = args.name
owner_name, repo_name = name.split("/")
pyproject_toml(owner_name, repo_name)
mkdocs(owner_name, repo_name)
project_dir(repo_name)
readme(owner_name, repo_name)