Skip to content

Commit

Permalink
Allow passing --listen when running the explorer to specify the hos…
Browse files Browse the repository at this point in the history
…t and port
  • Loading branch information
gutzbenj committed Jun 13, 2024
1 parent b9865a8 commit 2e1deb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
Development
***********

- Allow passing `--listen` when running the explorer to specify the host and port

0.87.0 (06.06.2024)
*******************

Expand Down
20 changes: 17 additions & 3 deletions wetterdienst/ui/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,9 @@ def restapi(listen: str, reload: bool, debug: bool):


@cli.command("explorer", section=advanced_section)
@cloup.option("--listen", type=click.STRING, default=None, help="HTTP server listen address")
@debug_opt
def explorer(debug: bool):
def explorer(listen: str, debug: bool):
set_logging_level(debug)

try:
Expand All @@ -623,12 +624,25 @@ def explorer(debug: bool):
log.error("Please install the explorer extras with 'pip install wetterdienst[explorer]'")
sys.exit(1)

address = "localhost"
port = "8501"
if listen:
try:
address, port = listen.split(":")
except ValueError:
log.error(
f"Invalid listen address. Please provide address and port separated by a colon e.g. '{address}:{port}'."
)
sys.exit(1)

log.info(f"Starting {appname}")
log.info("Starting Explorer web service on http://localhost:8501")
log.info(f"Starting Explorer web service on http://{address}:{port}")

process = None
try:
process = subprocess.Popen(["streamlit", "run", app.__file__]) # noqa: S603, S607
process = subprocess.Popen(
["streamlit", "run", app.__file__, "--server.address", address, "--server.port", port] # noqa: S603, S607
)
process.wait()
except KeyboardInterrupt:
log.info("Stopping Explorer web service")
Expand Down

0 comments on commit 2e1deb0

Please sign in to comment.