Skip to content

Commit 3230129

Browse files
committed
Updated manage script
1 parent bed944a commit 3230129

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

scripts/manage.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
class App:
1414
def __init__(self):
1515
self.procedures = {}
16+
self.configurations = {
17+
"default": None,
18+
}
1619

20+
def configure(self, **kwargs):
21+
invalid = set(kwargs) - set(self.configurations)
22+
if invalid:
23+
raise ValueError(f"The followings are not valid configuration keys: {', '.join(invalid)}.")
24+
self.configurations.update(kwargs)
1725

1826
def command(self, *cli_args):
1927
def util(f):
@@ -26,12 +34,17 @@ def g(*args, **kwargs):
2634

2735
def run(self, args):
2836
if len(args) == 0:
29-
error(f"No argument is passed.")
30-
return
31-
if len(args) > 2:
37+
if self.configurations["default"] is None:
38+
error(f"No argument is passed.")
39+
return
40+
command = self.configurations["default"]
41+
arg = ()
42+
elif len(args) > 2:
3243
error(f"No more than two args is required.")
3344
return
34-
command, *arg = args
45+
else:
46+
command, *arg = args
47+
3548
try:
3649
procedure, expected_args = self.get_command(command)
3750
except ValueError:
@@ -97,10 +110,11 @@ def call(cls, cmd, jobname):
97110
return False
98111

99112
app = App()
113+
app.configure(default = "help")
100114

101115
@app.command("release", "dev")
102116
def build(app, job = None):
103-
"""Builds the docs.
117+
"""Builds the docs. Builds them in all available formats if [release] argument is given.
104118
* Increases the project version if [release] argument is given.
105119
* Opens the docs/index.html in browser if [dev] argument is given.
106120
* Moves them to where they are needed if [release] or [dev] argument is given."""
@@ -111,9 +125,11 @@ def build(app, job = None):
111125

112126
print("Starting the build process.")
113127
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")
128+
129+
if job == "release":
130+
p = app.call("make singlehtml", "HTML (single file)")
131+
p = app.call("make latexpdf", "PDF")
132+
p = app.call("make epub", "EPUB")
117133

118134
if job is None:
119135
return
@@ -138,10 +154,16 @@ def checklinks(app):
138154
import linkfix
139155

140156
@app.command("major", "minor", "patch", "downgrade")
141-
def version(app, field):
142-
"Upgrades or downgrades the project version with respect to the specified argument ([major], [minor], [patch] or [downgrade])."
157+
def version(app, field = "display"):
158+
"""Upgrades or downgrades the project version with respect to the specified argument ([major], [minor], [patch] or [downgrade]).
159+
* Displays the current version if no argument is passed.
160+
"""
143161
with open(version_file, "r") as f:
144162
versions = list(map(lambda x: x[:-1] if x.endswith("\n") else x, f))
163+
164+
if field == "display":
165+
return print("Project version:", versions[-1])
166+
145167
if field == "downgrade":
146168
if len(versions) == 1:
147169
error("Can't downgrade when there is a single recorded version.")

0 commit comments

Comments
 (0)