Skip to content

Commit 4a503ab

Browse files
committed
"xcetool image run": print server and viewer URLs
Addresses #46
1 parent 4f33344 commit 4a503ab

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

test/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import runpy
23
import subprocess
34
from unittest.mock import patch, ANY, MagicMock
@@ -102,3 +103,27 @@ def test_image_run(runner_mock):
102103
from_saved=False,
103104
keep=False,
104105
)
106+
107+
108+
@patch("xcengine.cli.ContainerRunner")
109+
def test_image_run_print_urls(runner_mock):
110+
cli_runner = CliRunner()
111+
instance_mock = runner_mock.return_value = MagicMock()
112+
port = 32168
113+
result = cli_runner.invoke(
114+
cli, ["image", "run", "--server", "--port", str(port), "foo"]
115+
)
116+
runner_mock.assert_called_once_with(image="foo", output_dir=None)
117+
assert result.exit_code == 0
118+
instance_mock.run.assert_called_once_with(
119+
run_batch=False,
120+
host_port=port,
121+
from_saved=False,
122+
keep=False,
123+
)
124+
assert re.search(
125+
f"server.*http://localhost:{port}", result.stdout, re.IGNORECASE
126+
)
127+
assert re.search(
128+
f"viewer.*http://localhost:{port}/viewer", result.stdout, re.IGNORECASE
129+
)

xcengine/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pathlib
1010
import subprocess
11+
import sys
1112
import tempfile
1213

1314
import click
@@ -18,6 +19,7 @@
1819
LOGGER = logging.getLogger(__name__)
1920
logging.basicConfig(level=logging.INFO)
2021

22+
2123
@click.group(
2224
help="Create and run compute engine scripts and containers "
2325
"from IPython notebooks"
@@ -154,9 +156,11 @@ def build(
154156
)
155157
image = image_builder.build()
156158
if eoap:
159+
157160
class IndentDumper(yaml.Dumper):
158161
def increase_indent(self, flow=False, indentless=False):
159162
return super(IndentDumper, self).increase_indent(flow, False)
163+
160164
eoap.write_text(
161165
yaml.dump(
162166
image_builder.create_cwl(),
@@ -221,6 +225,14 @@ def run(
221225
is not click.core.ParameterSource.DEFAULT
222226
)
223227
actual_port = port if server or port_specified_explicitly else None
228+
if actual_port is not None:
229+
print(
230+
f"xcube server will be available at http://localhost:{actual_port}"
231+
)
232+
print(
233+
f"xcube viewer will be available at "
234+
f"http://localhost:{actual_port}/viewer"
235+
)
224236
runner.run(
225237
run_batch=batch,
226238
host_port=actual_port,

0 commit comments

Comments
 (0)