Skip to content

Commit

Permalink
Merge pull request #1346 from wm75/fix-venv-keeping
Browse files Browse the repository at this point in the history
Fix virtualenv dir bookkeeping
  • Loading branch information
mvdbeek committed Jan 16, 2023
2 parents c40a036 + de8e2d3 commit 6747e88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 13 additions & 6 deletions planemo/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,14 +1023,17 @@ def __init__(
kwds,
)
self.galaxy_root = galaxy_root
self._virtual_env_dir = None
self._virtual_env_locs = []

@property
def virtual_env_dir(self):
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
loc = None
for loc in self._virtual_env_locs:
if not os.path.isabs(loc):
loc = os.path.join(self.galaxy_root, loc)
if os.path.isdir(loc):
break
return loc

@property
def gravity_state_dir(self):
Expand All @@ -1046,7 +1049,11 @@ def kill(self):
with open(self.pid_file) as f:
print(f"pid_file contents are [{f.read()}]")
if self.env.get("GRAVITY_STATE_DIR"):
stop_gravity(virtual_env=self.virtual_env_dir, gravity_state_dir=self.gravity_state_dir, env=self.env)
stop_gravity(
virtual_env=self.virtual_env_dir or os.path.join(self.galaxy_root, ".venv"),
gravity_state_dir=self.gravity_state_dir,
env=self.env,
)
kill_pid_file(self.pid_file)

def startup_command(self, ctx, **kwds):
Expand Down
9 changes: 5 additions & 4 deletions planemo/galaxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ def setup_venv(ctx, kwds: Dict[str, Any], config: Optional["LocalGalaxyConfig"]


def locate_galaxy_virtualenv(ctx, kwds: Dict[str, Any], config: Optional["LocalGalaxyConfig"] = None):
virtual_env_locs = []
if os.environ.get("GALAXY_VIRTUAL_ENV"):
venv_command = ""
virtual_env_dir = os.environ["GALAXY_VIRTUAL_ENV"]
virtual_env_locs.append(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 @@ -82,13 +83,13 @@ def locate_galaxy_virtualenv(ctx, kwds: Dict[str, Any], config: Optional["LocalG
if galaxy_branch != "master":
shared_venv_path = f"{shared_venv_path}_{galaxy_branch}"

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

0 comments on commit 6747e88

Please sign in to comment.