55from difflib import SequenceMatcher
66import sys
77
8- shared = join (".." , "shared" )
8+ root = os .path .abspath ("." )
9+ shared = join (root , "shared" )
910version_file = join ("shared" , "project_version.txt" )
11+ index_file = join (root , "docs" , "index.html" )
1012
1113class 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" )
119141def version (app , field ):
@@ -153,4 +175,6 @@ def help(app, method = None):
153175if __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