xvik / gradle-use-python-plugin

Use python modules in gradle build

Home Page:https://xvik.github.io/gradle-use-python-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Environment variables

dregert opened this issue · comments

Is there a way to set environment variables when executing a PythonTask?

There is no way currently, sorry.
But it's easy to add. I will release 2.0.1 in a few days.

Just out of curiosity, could you please tell me the case when an environment variable required only for the python process and not system-wide.

I added support for variables but will wait for your answer (about your case) to be sure. I have some doubts that pip tasks could also need variables support (but can't figure out any usage example)

I need to trigger a python script (that I cannot change) and it's configured via environment variables, so I need to pass different configurations to it depending on what I'm trying to do. Therefore setting the environment variables on the system level is not really feasible.
I did try to set the environment variables inside the gradle script (at the global level) before running a PythonTask, but if doesn't seem that the variables set are propagated to the PythonTask.

Regarding the pip tasks, I don't have a usecase for them.

I did try to set the environment variables inside the gradle script (at the global level) before running a PythonTask, but if doesn't seem that the variables set are propagated to the PythonTask.

How? It should be not possible without hacks. Exec task (used for python execution) should see only System.getenv() variables.

If you have time (and desire), you can make sure it works with the plugin snapshot (description collapsed).

The new syntax is the same as with Exec:

task sample(type: PythonTask) {
       command = "-c \"import os;print('variables: '+os.getenv('some', 'null')+' '+os.getenv('foo', 'null'))\""
       environment 'some', 1
       environment 'other', 2
       environment(['foo': 'bar', 'baz': 'bag'])
}

I will release plugin (hopefully) today.

How? It should be not possible without hacks.

I was trying something like: System.setProperty('FOO', 'bar') before calling the PythonTask.

I'll try to test the snapshot later today.
I really appreciate it! Thanks!

I just did a very quick test with the snapshot version and it seems to work just fine :)

Great! Thank you!