Skip to content

Commit

Permalink
Merge pull request #1307 from mvdbeek/fix_stopping_gravity
Browse files Browse the repository at this point in the history
Fix recording of virtual_env_dir
  • Loading branch information
mvdbeek committed Oct 31, 2022
2 parents b7d9761 + b3f3bd9 commit b6511dd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
7 changes: 4 additions & 3 deletions planemo/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,11 +1003,12 @@ def __init__(
kwds,
)
self.galaxy_root = galaxy_root
self._virtual_env_dir = None

@property
def virtual_env_dir(self):
virtual_env = self._kwds.get("GALAXY_VIRTUAL_ENV", ".venv")
if virtual_env and not os.path.isabs(virtual_env):
virtual_env = self._virtual_env_dir or ".venv"
if not os.path.isabs(virtual_env):
virtual_env = os.path.join(self.galaxy_root, virtual_env)
return virtual_env

Expand Down Expand Up @@ -1036,7 +1037,7 @@ def startup_command(self, ctx, **kwds):
"""
daemon = kwds.get("daemon", False)
# TODO: Allow running dockerized Galaxy here instead.
setup_venv_command = setup_venv(ctx, kwds)
setup_venv_command = setup_venv(ctx, kwds, self)
run_script = f"{shlex.quote(os.path.join(self.galaxy_root, 'run.sh'))} $COMMON_STARTUP_ARGS"
if daemon:
run_script += " --daemon"
Expand Down
24 changes: 18 additions & 6 deletions planemo/galaxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
import os
import shlex
import string
from typing import (
Any,
Dict,
Optional,
TYPE_CHECKING,
)

from galaxy.util.commands import shell

Expand All @@ -14,6 +20,9 @@
DEFAULT_PYTHON_VERSION,
)

if TYPE_CHECKING:
from planemo.galaxy.config import LocalGalaxyConfig

# Activate galaxy's virtualenv if present (needed for tests say but not for
# server because run.sh does this).
ACTIVATE_COMMAND = (
Expand All @@ -38,15 +47,15 @@
UNCACHED_VIRTUAL_ENV_COMMAND = "GALAXY_VIRTUAL_ENV=.venv"


def setup_venv(ctx, kwds):
def setup_venv(ctx, kwds: Dict[str, Any], config: Optional["LocalGalaxyConfig"] = None):
if kwds.get("skip_venv", False):
return ""

create_template_params = {
"create_virtualenv": create_command("$GALAXY_VIRTUAL_ENV", kwds.get("galaxy_python_version"))
}
return shell_join(
locate_galaxy_virtualenv(ctx, kwds),
locate_galaxy_virtualenv(ctx, kwds, config),
PRINT_VENV_COMMAND if ctx.verbose else None,
CREATE_COMMAND_TEMPLATE.safe_substitute(create_template_params),
PRINT_VENV_COMMAND if ctx.verbose else None,
Expand All @@ -60,10 +69,10 @@ def setup_venv(ctx, kwds):
)


def locate_galaxy_virtualenv(ctx, kwds):
def locate_galaxy_virtualenv(ctx, kwds: Dict[str, Any], config: Optional["LocalGalaxyConfig"] = None):
if os.environ.get("GALAXY_VIRTUAL_ENV"):
venv_command = ""
kwds["GALAXY_VIRTUAL_ENV"] = os.environ["GALAXY_VIRTUAL_ENV"]
virtual_env_dir = os.environ["GALAXY_VIRTUAL_ENV"]
elif not kwds.get("no_cache_galaxy", False):
workspace = ctx.workspace
galaxy_branch = kwds.get("galaxy_branch") or "master"
Expand All @@ -72,11 +81,14 @@ def locate_galaxy_virtualenv(ctx, kwds):
shared_venv_path = f"{shared_venv_path}_{galaxy_python_version}"
if galaxy_branch != "master":
shared_venv_path = f"{shared_venv_path}_{galaxy_branch}"
kwds["GALAXY_VIRTUAL_ENV"] = shared_venv_path

virtual_env_dir = shared_venv_path
venv_command = CACHED_VIRTUAL_ENV_COMMAND % shlex.quote(shared_venv_path)
else:
kwds["GALAXY_VIRTUAL_ENV"] = ".venv"
virtual_env_dir = ".venv"
venv_command = UNCACHED_VIRTUAL_ENV_COMMAND
if config:
config._virtual_env_dir = virtual_env_dir
return shell_join(
venv_command,
"export GALAXY_VIRTUAL_ENV",
Expand Down

0 comments on commit b6511dd

Please sign in to comment.