Skip to content

Commit aca92c3

Browse files
authored
Merge pull request #9 from Kijewski/pr-once-more
Fixup to #8: handle relative paths
2 parents 230b081 + 911b7e9 commit aca92c3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

book/update-theme.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from http.client import HTTPSConnection
66
from io import StringIO
77
from json import load
8+
from os import PathLike
9+
from pathlib import Path
810

911

1012
INDEX_HBS_DOMAIN = "api.github.com"
@@ -49,7 +51,7 @@
4951
"""
5052

5153

52-
def main():
54+
def update_theme(target: PathLike) -> None:
5355
with closing(HTTPSConnection(INDEX_HBS_DOMAIN, INDEX_HBS_PORT)) as conn:
5456
conn.request(INDEX_HBS_PROTO, INDEX_HBS_PATH, None, INDEX_HBS_HEADERS)
5557
res = conn.getresponse()
@@ -64,7 +66,7 @@ def main():
6466
output_f = StringIO()
6567

6668
_, revision = data["git_url"].rsplit("/", 1)
67-
print("{{!-- Source revision:", revision, "--}}", file=output_f)
69+
print("Source revision:", revision)
6870

6971
state = "before-sidebar"
7072
for line in input_f:
@@ -93,10 +95,13 @@ def main():
9395
state = "after-sidebar"
9496
output_f.write(line)
9597

98+
if state != "after-sidebar":
99+
raise Exception(f"state={state!r}")
100+
96101
output_f.seek(0, 0)
97-
with open("./theme/index.hbs", "wt") as f:
102+
with open(target, "wt") as f:
98103
print(output_f.read(), end="", file=f)
99104

100105

101106
if __name__ == "__main__":
102-
main()
107+
update_theme(Path(__file__).absolute().parent / "theme" / "index.hbs")

0 commit comments

Comments
 (0)