Skip to content

Commit c82ef49

Browse files
committed
rebase patch for VPYTHON_HTTP_PORT and VPYTHON_NO_LAUNCH_BROWSER
1 parent 36c36ef commit c82ef49

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

vpython/no_notebook.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ def find_free_port():
6565
s.bind(('', 0)) # find an available port
6666
return s.getsockname()[1]
6767

68-
69-
__HTTP_PORT = find_free_port()
68+
if "VPYTHON_HTTP_PORT" in os.environ:
69+
__HTTP_PORT = int(os.environ["VPYTHON_HTTP_PORT"])
70+
else:
71+
__HTTP_PORT = find_free_port()
7072
__SOCKET_PORT = find_free_port()
7173

7274
try:
@@ -259,19 +261,24 @@ def onClose(self, wasClean, code, reason):
259261

260262

261263
try:
264+
no_launch = os.environ.get("VPYTHON_NO_LAUNCH_BROWSER", False)
265+
if no_launch=="0":
266+
no_launch=False
262267
if platform.python_implementation() == 'PyPy':
263268
server_address = ('', 0) # let HTTPServer choose a free port
264269
__server = HTTPServer(server_address, serveHTTP)
265270
port = __server.server_port # get the chosen port
266271
# Change the global variable to store the actual port used
267272
__HTTP_PORT = port
268-
_webbrowser.open('http://localhost:{}'.format(port)
273+
if not no_launch:
274+
_webbrowser.open('http://localhost:{}'.format(port)
269275
) # or webbrowser.open_new_tab()
270276
else:
271277
__server = HTTPServer(('', __HTTP_PORT), serveHTTP)
272278
# or webbrowser.open_new_tab()
273-
if _browsertype == 'default': # uses default browser
274-
_webbrowser.open('http://localhost:{}'.format(__HTTP_PORT))
279+
if not no_launch:
280+
if _browsertype == 'default': # uses default browser
281+
_webbrowser.open('http://localhost:{}'.format(__HTTP_PORT))
275282

276283
except:
277284
pass

0 commit comments

Comments
 (0)