From c82ef49ed4efc0d73d72be22c9ac9c65b579db17 Mon Sep 17 00:00:00 2001
From: danx0r <dan.miller@eye0.com>
Date: Sat, 27 Aug 2022 16:10:41 -0700
Subject: [PATCH] rebase patch for VPYTHON_HTTP_PORT and
 VPYTHON_NO_LAUNCH_BROWSER

---
 vpython/no_notebook.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/vpython/no_notebook.py b/vpython/no_notebook.py
index 0f8b67e..4193161 100755
--- a/vpython/no_notebook.py
+++ b/vpython/no_notebook.py
@@ -65,8 +65,10 @@ def find_free_port():
     s.bind(('', 0))  # find an available port
     return s.getsockname()[1]
 
-
-__HTTP_PORT = find_free_port()
+if "VPYTHON_HTTP_PORT" in os.environ:
+    __HTTP_PORT = int(os.environ["VPYTHON_HTTP_PORT"])
+else:
+    __HTTP_PORT = find_free_port()
 __SOCKET_PORT = find_free_port()
 
 try:
@@ -259,19 +261,24 @@ def onClose(self, wasClean, code, reason):
 
 
 try:
+    no_launch = os.environ.get("VPYTHON_NO_LAUNCH_BROWSER", False)
+    if no_launch=="0":
+        no_launch=False
     if platform.python_implementation() == 'PyPy':
         server_address = ('', 0)      # let HTTPServer choose a free port
         __server = HTTPServer(server_address, serveHTTP)
         port = __server.server_port   # get the chosen port
         # Change the global variable to store the actual port used
         __HTTP_PORT = port
-        _webbrowser.open('http://localhost:{}'.format(port)
+        if not no_launch:
+            _webbrowser.open('http://localhost:{}'.format(port)
                          )  # or webbrowser.open_new_tab()
     else:
         __server = HTTPServer(('', __HTTP_PORT), serveHTTP)
         # or webbrowser.open_new_tab()
-        if _browsertype == 'default':  # uses default browser
-            _webbrowser.open('http://localhost:{}'.format(__HTTP_PORT))
+        if not no_launch:
+            if _browsertype == 'default':  # uses default browser
+                _webbrowser.open('http://localhost:{}'.format(__HTTP_PORT))
 
 except:
     pass