Skip to content

Instantly share code, notes, and snippets.

@mvdbeek
Last active November 1, 2020 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvdbeek/8ca744f5ee8f61bcb74faa8e35a147ff to your computer and use it in GitHub Desktop.
Save mvdbeek/8ca744f5ee8f61bcb74faa8e35a147ff to your computer and use it in GitHub Desktop.
Mapping Galaxy tools to a python 2 destination

What it does

This configuration will manipulate the PATH variable, so that tools that

  • call python
  • and do not specify a python requirement as a dependency
  • and that you can't change for some reason (e.g they use the deprecated package_* dependencies)

will use python 2. Since we embedd the metdata setting in the job script we set use_metadata_binary and place a script called galaxy-set-metadata into the bin directory of galaxy's virtualenv environment. This will make sure that the metdata setting uses python 3 and has access to Galaxy's internals.

How to set it up

Place galaxy-set-metadata into your galaxy's virtualenv/bin directory (usually in <galaxy_root>/.venv/bin) and make it executable. Add an additional destination to your existing destinations, and map the failing legacy tool(s) to that location.

If some of your legacy tools use galaxy internals you can install the galaxy-data package into your python 2 environment ({{path to python folder with python 2 binary}}/python -m pip install galaxy-data).

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
from galaxy.metadata.set_metadata import set_metadata
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(set_metadata())
<job_conf>
<plugins>
...
</plugins>
<destinations>
<destination id="python2_legacy" runner="{{your runner}}">
...
<!-- use galaxy-set-metadata script -->
<param id="use_metadata_binary">true</param>
<!-- activate regular galaxy virtualenv -->
<env file="{{galaxy's virtualenv activate script here}}"/>
<env id="GALAXY_VIRTUAL_ENV">None</env>
<!-- place path that contains python 2 before galaxy's virtualenv path -->
<env id="PATH">{{path to python folder with python 2 binary}}:$PATH</env>
...
</destination>
...
</destinations>
<tools>
<tool id="{{some_legacy_tool_that_needs_python_2}}" destination="python2_legacy"/>
...
</tools>
</job_conf>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment