Skip to content

Commit 32f06fe

Browse files
committed
browser: Support NOBROWSER environment variable to prevent launching any browser
1 parent 3261aac commit 32f06fe

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

nextstrain/cli/browser.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@
77
falling back to a set of default browsers. May be program names, e.g.
88
``firefox``, or absolute paths to specific executables, e.g.
99
``/usr/bin/firefox``.
10+
11+
.. envvar:: NOBROWSER
12+
13+
If set to a truthy value (e.g. 1) then no web browser will be considered
14+
available. This can be useful to prevent opening of a browser when there
15+
are not other means of doing so.
1016
"""
1117
import webbrowser
1218
from threading import Thread, ThreadError
1319
from os import environ
1420
from .util import warn
1521

1622

17-
# Avoid text-mode browsers
18-
TERM = environ.pop("TERM", None)
19-
try:
20-
BROWSER = webbrowser.get()
21-
except:
23+
if environ.get("NOBROWSER"):
2224
BROWSER = None
23-
finally:
24-
if TERM is not None:
25-
environ["TERM"] = TERM
25+
else:
26+
# Avoid text-mode browsers
27+
TERM = environ.pop("TERM", None)
28+
try:
29+
BROWSER = webbrowser.get()
30+
except:
31+
BROWSER = None
32+
finally:
33+
if TERM is not None:
34+
environ["TERM"] = TERM
2635

2736

2837
def open_browser(url: str, new_thread: bool = True):

0 commit comments

Comments
 (0)