@@ -186,30 +186,24 @@ def trac_23428_browser_workaround():
186186
187187@contextmanager
188188def sage_doc_server ():
189- from sage .env import SAGE_DOC_SERVER_URL
190-
191- if SAGE_DOC_SERVER_URL :
192- print (f'Sage doc server running at { SAGE_DOC_SERVER_URL } ' )
193- yield
194- else :
195- from functools import partial
196- from http .server import SimpleHTTPRequestHandler , ThreadingHTTPServer
197- from threading import Thread
189+ from functools import partial
190+ from http .server import SimpleHTTPRequestHandler , ThreadingHTTPServer
191+ from threading import Thread
198192
199- from sage .env import SAGE_DOC , SAGE_DOC_LOCAL_PORT as port
193+ from sage .env import SAGE_DOC , SAGE_DOC_LOCAL_PORT as port
200194
201- server = ThreadingHTTPServer (('localhost' , int (port )),
202- partial (SimpleHTTPRequestHandler , directory = SAGE_DOC ))
203- server_thread = Thread (target = server .serve_forever , name = "sage_doc_server" )
204- server_thread .start ()
205- print (f'Sage doc server started running at http://localhost:{ port } ' )
195+ server = ThreadingHTTPServer (('localhost' , int (port )),
196+ partial (SimpleHTTPRequestHandler , directory = SAGE_DOC ))
197+ server_thread = Thread (target = server .serve_forever , name = "sage_doc_server" )
198+ server_thread .start ()
199+ print (f'Sage doc server started running at http://localhost:{ port } ' )
206200
207- try :
208- yield
209- finally :
210- server .shutdown ()
211- server_thread .join ()
212- print (f'Sage doc server stopped runnning at http://localhost:{ port } ' )
201+ try :
202+ yield
203+ finally :
204+ server .shutdown ()
205+ server_thread .join ()
206+ print (f'Sage doc server stopped runnning at http://localhost:{ port } ' )
213207
214208
215209if __name__ == '__main__' :
@@ -254,5 +248,17 @@ if __name__ == '__main__':
254248
255249 banner ()
256250
257- with sage_doc_server ():
251+ # Start a Sage doc server if the Sage documentation is available locally.
252+ # See the corresponding code in src/sage/repl/ipython_kernel/kernel.py.
253+
254+ from sage .env import SAGE_DOC_SERVER_URL
255+ from sage .features .sagemath import sagemath_doc_html
256+
257+ if SAGE_DOC_SERVER_URL :
258+ print (f'Sage doc server running at { SAGE_DOC_SERVER_URL } ' )
259+ launcher (unknown )
260+ elif sagemath_doc_html ().is_present ():
261+ with sage_doc_server ():
262+ launcher (unknown )
263+ else :
258264 launcher (unknown )
0 commit comments