Skip to content

Commit

Permalink
Merge pull request #1299 from mvdbeek/test_log_fixes
Browse files Browse the repository at this point in the history
Fix printing planemo test logs
  • Loading branch information
mvdbeek committed Oct 20, 2022
2 parents 2de34aa + ad9253f commit 75cbd3a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
3 changes: 2 additions & 1 deletion planemo/commands/cmd_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ def cli(ctx, uris, **kwds):
paths = uris_to_paths(ctx, uris)
runnables = for_paths(paths)
kwds["galaxy_skip_client_build"] = kwds.pop("skip_client_build", False)
galaxy_serve(ctx, runnables, **kwds)
with galaxy_serve(ctx, runnables, **kwds):
pass
10 changes: 2 additions & 8 deletions planemo/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
)
from planemo.mulled import build_involucro_context
from planemo.shed import tool_shed_url
from planemo.virtualenv import DEFAULT_PYTHON_VERSION
from .api import (
DEFAULT_ADMIN_API_KEY,
gi,
Expand Down Expand Up @@ -336,12 +335,7 @@ def config_join(*args):
if not os.path.isdir(galaxy_root):
_install_galaxy(ctx, galaxy_root, install_env, kwds)

if parse_version(kwds.get("galaxy_python_version") or DEFAULT_PYTHON_VERSION) >= parse_version("3"):
# on python 3 we use gunicorn,
# which requires 'main' as server name
server_name = "main"
else:
server_name = f"planemo{random.randint(0, 100000)}"
server_name = "main"
# Once we don't have to support earlier than 18.01 - try putting these files
# somewhere better than with Galaxy.
log_file = f"{server_name}.log"
Expand Down Expand Up @@ -634,7 +628,7 @@ def _config_directory(ctx, **kwds):
finally:
cleanup = not kwds.get("no_cleanup", False)
if created_config_directory and cleanup:
shutil.rmtree(config_directory)
shutil.rmtree(config_directory, ignore_errors=True)


class GalaxyInterface(metaclass=abc.ABCMeta):
Expand Down
13 changes: 8 additions & 5 deletions planemo/galaxy/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
from .run import run_galaxy_command


@contextlib.contextmanager
def serve(ctx, runnables=None, **kwds):
if runnables is None:
runnables = []
"""Serve a Galaxy instance with artifacts defined by paths."""
try:
return _serve(ctx, runnables, **kwds)
with _serve(ctx, runnables, **kwds) as config:
yield config
except Exception as e:
ctx.vlog("Problem serving Galaxy", exception=e)
raise


@contextlib.contextmanager
def _serve(ctx, runnables, **kwds):
engine = kwds.get("engine", "galaxy")
if engine == "docker_galaxy":
Expand Down Expand Up @@ -67,7 +70,7 @@ def _serve(ctx, runnables, **kwds):
os.symlink(real_pid_file, kwds["pid_file"])
else:
io.warn("Can't find Galaxy pid file [%s] to link" % real_pid_file)
return config
yield config


@contextlib.contextmanager
Expand All @@ -76,10 +79,10 @@ def serve_daemon(ctx, runnables=None, **kwds):
if runnables is None:
runnables = []
config = None
kwds["daemon"] = True
try:
kwds["daemon"] = True
config = serve(ctx, runnables, **kwds)
yield config
with serve(ctx, runnables, **kwds) as config:
yield config
finally:
if config:
if ctx.verbose:
Expand Down
24 changes: 12 additions & 12 deletions tests/test_galaxy_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def test_serve_daemon(self):
"""Test serving a galaxy tool via a daemon Galaxy process."""
port = network_util.get_free_port()
cat_path = os.path.join(TEST_REPOS_DIR, "single_tool", "cat.xml")
config = galaxy_serve(
with galaxy_serve(
self.test_context,
[for_path(cat_path)],
install_galaxy=True,
galaxy_branch=target_galaxy_branch(),
port=port,
daemon=True,
no_dependency_resolution=True,
)
_assert_service_up(config)
config.kill()
) as config:
_assert_service_up(config)
config.kill()
_assert_service_down(config)

@skip_if_environ("PLANEMO_SKIP_REDUNDANT_TESTS") # redundant with test_cmd_serve -> test_serve_workflow
Expand All @@ -52,7 +52,7 @@ def test_serve_workflow(self):
cat = os.path.join(PROJECT_TEMPLATES_DIR, "demo", "cat.xml")
workflow = os.path.join(TEST_DATA_DIR, "wf1.gxwf.yml")
extra_tools = [random_lines, cat]
config = galaxy_serve(
with galaxy_serve(
self.test_context,
[for_path(workflow)],
install_galaxy=True,
Expand All @@ -61,13 +61,13 @@ def test_serve_workflow(self):
daemon=True,
extra_tools=extra_tools,
no_dependency_resolution=True,
)
_assert_service_up(config)
user_gi = config.user_gi
assert user_gi.tools.show_tool("random_lines1")
assert len(user_gi.workflows.get_workflows()) == 1
config.kill()
_assert_service_down(config)
) as config:
_assert_service_up(config)
user_gi = config.user_gi
assert user_gi.tools.show_tool("random_lines1")
assert len(user_gi.workflows.get_workflows()) == 1
config.kill()
_assert_service_down(config)


def _assert_service_up(config):
Expand Down

0 comments on commit 75cbd3a

Please sign in to comment.