Skip to content

Commit 553a23f

Browse files
committed
Updated scripts/manage.py
1 parent 9fcc990 commit 553a23f

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

scripts/linkfix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
if broken == 0:
6666
success("All links are uptodate, not any broken links.")
6767
elif len(replacements) == 0:
68-
success(f"Didn't change any links.")
68+
success(f"Didn't change any links out of {broken} broken ones.")
6969
else:
7070
warning("Make sure you made no mistake and press Enter to proceed.")
7171
input()

scripts/manage.py

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from difflib import SequenceMatcher
66
import sys
77

8-
shared = join("..", "shared")
8+
root = os.path.abspath(".")
9+
shared = join(root, "shared")
910
version_file = join("shared", "project_version.txt")
11+
index_file = join(root, "docs", "index.html")
1012

1113
class App:
1214
def __init__(self):
@@ -80,40 +82,60 @@ def get_command(self, name):
8082
error(f"Did you perhaps meant {match!r}?")
8183
raise ValueError()
8284

83-
app = App()
84-
85-
@app.command("release")
86-
def build(app, job = None):
87-
"Builds the docs, moves them to where they are needed and upgrades the version."
88-
import subprocess
89-
from io import StringIO
90-
91-
def call(cmd, jobname):
85+
@classmethod
86+
def call(cls, cmd, jobname):
87+
import subprocess
9288
err = subprocess.PIPE
9389
out = subprocess.PIPE
9490
p = subprocess.run(cmd, shell=True, stdout=out, stderr=err)
9591
error(p.stderr.decode(), end = "")
9692
if not p.stderr:
9793
success(f"Built {jobname}.")
94+
return True
9895
else:
9996
warning(f"There were errors while building {jobname}.")
97+
return False
98+
99+
app = App()
100+
101+
@app.command("release", "dev")
102+
def build(app, job = None):
103+
"""Builds the docs.
104+
* Increases the project version if 'release' argument is given.
105+
* Opens the docs/index.html in browser if 'dev' argument is given.
106+
* Moves them to where they are needed if 'release' or 'dev' argument is given."""
107+
108+
# should we do that at the start so that it affects this release or at the end so that it doesn't run if there is an exception?
109+
if job == "release":
110+
version('patch')
100111

101112
print("Starting the build process.")
102-
p = call("make html", "HTML")
103-
p = call("make singlehtml", "HTML (single file)")
104-
p = call("make latexpdf", "PDF")
105-
p = call("make epub", "EPUB")
113+
p = app.call("make html", "HTML")
114+
p = app.call("make singlehtml", "HTML (single file)")
115+
p = app.call("make latexpdf", "PDF")
116+
p = app.call("make epub", "EPUB")
106117

107118
if job is None:
108119
return
109120

110-
if job == "release":
111-
version('patch')
112-
import move_documents
121+
import move_documents
122+
if job == "dev":
123+
open()
113124

114125
@app.command()
115-
def check_links(app):
116-
pass
126+
def open(app):
127+
"Opens the docs/index.html in browser."
128+
import webbrowser
129+
webbrowser.open(index_file, new=0, autoraise=True)
130+
success("Opened the docs/index.html in browser.")
131+
132+
@app.command()
133+
def checklinks(app):
134+
"Check the links and fix them manually."
135+
print("Checking the links.")
136+
p = app.call("make linkcheck", "linkcheck")
137+
if p:
138+
import linkfix
117139

118140
@app.command("major", "minor", "patch", "downgrade")
119141
def version(app, field):
@@ -153,4 +175,6 @@ def help(app, method = None):
153175
if __name__ == "__main__":
154176
import sys
155177
args = sys.argv[1:]
156-
app.run(args)
178+
app.run(args)
179+
else:
180+
raise ImportError("This file is not supposed to be imported.")

0 commit comments

Comments
 (0)