Skip to content

rebase patch for VPYTHON_HTTP_PORT and VPYTHON_NO_LAUNCH_BROWSER #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions vpython/no_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down