Skip to content

Commit

Permalink
invoke docs: open browser with built docs, and take port from env
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Feb 16, 2020
1 parent bad9816 commit 30c68cb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tasks.py
Expand Up @@ -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):
Expand All @@ -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'
Expand All @@ -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


Expand Down

0 comments on commit 30c68cb

Please sign in to comment.