From 30c68cbd1ab6ec3d090bb4c19dced79ae447bfcf Mon Sep 17 00:00:00 2001 From: pyroscope Date: Sun, 16 Feb 2020 17:25:15 +0100 Subject: [PATCH] invoke docs: open browser with built docs, and take port from env --- tasks.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tasks.py b/tasks.py index 2ed9d0cf..0d01a1b6 100644 --- a/tasks.py +++ b/tasks.py @@ -10,10 +10,11 @@ import glob import shutil import subprocess +import webbrowser from invoke import task -SPHINX_AUTOBUILD_PORT = 8340 +SPHINX_AUTOBUILD_PORT = int(os.environ.get('SPHINX_AUTOBUILD_PORT', '8340')) def watchdog_pid(ctx): @@ -27,8 +28,8 @@ def watchdog_pid(ctx): return pid -@task -def docs(ctx): +@task(help={'open-tab': "Open docs in new browser tab after initial build"}) +def docs(ctx, open_tab=False): """Start watchdog to build the Sphinx docs.""" build_dir = 'docs/_build' index_html = build_dir + '/html/index.html' @@ -51,7 +52,10 @@ def docs(ctx): ctx.run("touch docs/index.rst") ctx.run('ps {}'.format(pid), pty=False) url = 'http://localhost:{port:d}/'.format(port=SPHINX_AUTOBUILD_PORT) - print("\n*** Open '{}' in your browser...".format(url)) + if open_tab: + webbrowser.open_new_tab(url) + else: + print("\n*** Open '{}' in your browser...".format(url)) break