Setting an environment variable for python tools

Hello everyone,

I have some python scripts that are contacting an external server in order to produce their results.

I would like to pass the IP of that external server as an environment variable in the python scripts.

Right now the python tools do not see the variables even if it is set in the /etc/environment. I also tried setting the variables in the galaxy service.

Any ideas how I can pass the variables inside the python tools?

Thanks a lot,
Thanasis.

1 Like

I have discovered the environment_setup_file option in the galaxy.ini file. Is there documentation anywhere on how it works?

I was thinking to setup the environment using that option because as it says here:
https://galaxyproject.org/admin/config/tool-dependencies/#galaxy-specific-environment-file
it is being run before the tools.

So, any more documentation anywhere?

1 Like

Try here: https://docs.galaxyproject.org/en/master/index.html

I’ll also ping for more pro admin help on Monday. Apologies for delayed reply!

I looked into the documentation but I couldn’t find anything relevant.

Whatever I tried it didn’t work and it didn’t set the env variable inside the python environment of the tools.

Can you please ping someone that may know?

Don’t know if you are in a hurry and need a temporary quick fix. But if so, you can execute a bash script containing export VARNAME="my value" and the python script instead of directly executing the python script from the XML.

I did a temporary fix like that but I was wondering what’s the proper way.

Hi - I pinged for more help again at Gitter. They may reply here or there and you are certainly welcome to follow up at Gitter as well: https://gitter.im/galaxyproject/Lobby?at=5d794a53ae44a84124beef02

What is the execution environment for these scripts? If they are running on worker nodes, those nodes may not have the environment variable set.

This does not run on worker nodes, there is only the master node.

The tools are python scripts.

When I was testing them I tried to fetch the env variables inside the script but they didn’t exist. So I figured that they ran inside a python virtual environment.

So I want to find a way to load some env variables inside that virtual environment when every script starts.

Maybe I do not fully grasp the context and I am wrong somewhere.

The overarching issue is you are trying to bypass Galaxy to pass a tool information. This will always be brittle as Galaxy decides the execution environment. I recommend using one of Galaxies mechanisms to pass a tool information. Perhaps put it in a file in the tool-data folder and have the tool read it. One of the things I have been meaning to look into is if Galaxy loads anything you include in the galaxy.yml into its config object. You can access that via the $_app_ variable in the tools command block via the Cheetah template engine.

1 Like