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,

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:
it is being run before the tools.

So, any more documentation anywhere?

1 Like

Try here:

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:

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.


Hello @innovate-invent and thanks for the reply!

What I am doing now is exactly what you described. I am saving the info on a python script in a specific path and then I load it when my python tools run.

I was just asking if there is another, proper way to do that, maybe by putting the variables in the galaxy.yml as you said. Is this possible? I did not understand the way you said, to load it through the $app variable. Is there an example for that somewhere?

See here:

I haven’t tested if you can add custom options to the galaxy.yml but it might be possible.
Let me know if you are able to get this to work.