Skip to content

Commit

Permalink
Update address output in headless mode (#8647)
Browse files Browse the repository at this point in the history
## Describe your changes

Closes #8629

When Streamlit is started via `server.headless=true`, the address output
does not contain `localhost`, although the server can still be reached
via `localhost`. The `headless` mode just defines whether a browser is
started, not what the address binding is. So, the idea is to show
`localhost` also in case when `server.headless=true` is set.


## GitHub Issue Link (if applicable)

## Testing Plan

- Explanation of why no additional tests are needed
- Unit Tests (JS and/or Python)
- E2E Tests
- Any manual testing needed?

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
  • Loading branch information
raethlein committed May 14, 2024
1 parent 225d629 commit 406b1e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/streamlit/web/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,6 @@ def _print_url(is_running_hello: bool) -> None:
("Unix Socket", config.get_option("server.address")),
]

elif config.get_option("server.headless"):
internal_ip = net_util.get_internal_ip()
if internal_ip:
named_urls.append(("Network URL", server_util.get_url(internal_ip)))

external_ip = net_util.get_external_ip()
if external_ip:
named_urls.append(("External URL", server_util.get_url(external_ip)))

else:
named_urls = [
("Local URL", server_util.get_url("localhost")),
Expand All @@ -268,6 +259,11 @@ def _print_url(is_running_hello: bool) -> None:
if internal_ip:
named_urls.append(("Network URL", server_util.get_url(internal_ip)))

if config.get_option("server.headless"):
external_ip = net_util.get_external_ip()
if external_ip:
named_urls.append(("External URL", server_util.get_url(external_ip)))

cli_util.print_to_cli("")
cli_util.print_to_cli(" %s" % title_message, fg="blue", bold=True)
cli_util.print_to_cli("")
Expand Down
3 changes: 3 additions & 0 deletions lib/tests/streamlit/web/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_print_urls_remote(self, mock_get_internal_ip, mock_get_external_ip):
bootstrap._print_url(False)

out = sys.stdout.getvalue()
self.assertIn("Local URL: http://localhost", out)
self.assertIn("Network URL: http://internal-ip", out)
self.assertIn("External URL: http://external-ip", out)

Expand All @@ -175,6 +176,7 @@ def test_print_urls_remote_no_external(
bootstrap._print_url(False)

out = sys.stdout.getvalue()
self.assertIn("Local URL: http://localhost", out)
self.assertIn("Network URL: http://internal-ip", out)
self.assertNotIn("External URL: http://external-ip", out)

Expand All @@ -199,6 +201,7 @@ def test_print_urls_remote_no_internal(
bootstrap._print_url(False)

out = sys.stdout.getvalue()
self.assertIn("Local URL: http://localhost", out)
self.assertNotIn("Network URL: http://internal-ip", out)
self.assertIn("External URL: http://external-ip", out)

Expand Down

0 comments on commit 406b1e6

Please sign in to comment.