-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
57 lines (50 loc) · 1.35 KB
/
render.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
import json
import sys
import urllib.request
from pathlib import Path
conf_template = """
project = '{project}'
author = '{author}'
copyright = '{year}, {author}'
extensions = [
'myst_parser',
'sphinx_copybutton',
]
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = ['_templates']
html_theme = 'pydata_sphinx_theme'
html_theme_options = {{
'navigation_with_keys': False,
'show_toc_level': 2,
'external_links': [
{{
'name': 'View on GitHub',
'url': 'https://github.com/{repo}',
}},
]
}}
html_title = project
html_show_sourcelink = False
"""
# read sys.argv
config = {}
for arg in sys.argv[1:]:
if arg.startswith("-"):
k, v = arg.lstrip("-").split("=")
config[k] = v
# get created year of repo
if "year" not in config:
url = f"https://api.github.com/repos/{config['repo']}"
response = urllib.request.urlopen(url)
data = json.loads(response.read().decode("utf-8"))
config["year"] = data["created_at"][:4]
# create conf.py
if not (conf := Path("conf.py")).is_file():
conf.write_text(conf_template.format(**config))
# change README to index
exts = ["md", "rst"]
if not any(Path(f"index.{ext}").is_file() for ext in exts):
for ext in exts:
if (p := Path(f"README.{ext}")).is_file():
p.rename(f"index.{ext}")
break