[py-dev] adding env option to xspec (initialy posted to [execnet-dev])
Hi Jakub,
not sure it makes sense to add this to execnet, maybe better to xdist code? Things is it's easy to set environment variables when initializing gateways yourself. Just when using pytest-xdist you cannot easily do this because that API level is not exposed. So xdist could grow a configuration option to interpret some additional xspec settings.
I suggest to use
popen//env:NAME=value
as syntax. That being said i am not totally opposed to adding it directly to execnet. Maybe other people here on the list also have comments ...
best, holger
On Thu, Jun 24, 2010 at 13:30 +0100, Jakub Gustak wrote:
Hello,
I need to specify some ENV variable when running a sub-process (this case for xdist). AFAIK there is no support for such feature.
I do a workaround by popen//python=./python_with_env where ./python_with_env does specify required ENV.
It would be nice to have xspec env option (e.g. popen//env='VAR1=value VAR2=value' ).
I can fry up a patch for this functionality if you consider it a feature worth inclusion.
Cheers, Jakub Gustak
Moving this topic to py-dev list in this case. I prepared a patch, please review. What I don't like about it is using XSspec.__dict__ because env:NAME=VALUE requires a iteration through XSpec attributes: + def env(self): + return [(env.lstrip('env:'), value) + for env, value in self.gateway.spec.__dict__.iteritems() + if env.startswith('env:')] I believe a small extension to XSpec API would be nice. Any other ideas? regards, jakub
Hi Jakub, On Fri, Jun 25, 2010 at 15:10 +0100, Jakub Gustak wrote:
I suggest to use
popen//env:NAME=value
as syntax. That being said i am not totally opposed to adding it directly to execnet. Maybe other people here on the list also have comments ... ... Moving this topic to py-dev list in this case.
I prepared a patch, please review.
What I don't like about it is using XSspec.__dict__ because env:NAME=VALUE requires a iteration through XSpec attributes:
+ def env(self): + return [(env.lstrip('env:'), value) + for env, value in self.gateway.spec.__dict__.iteritems() + if env.startswith('env:')]
I believe a small extension to XSpec API would be nice. Any other ideas?
I think this is bearable as xspecs have very few key-value pairs. You could use env[4:] instead of lstrip() to optimize though :) One other bit: could you try to rework your patch so that it transfers the environment variables in the "slaveinput" dictionary? This is also processable from pytest_configure and produces a smaller patch i guess. best, holger
On Fri, Jun 25, 2010 at 3:41 PM, holger krekel <holger@merlinux.eu> wrote:
Hi Jakub,
On Fri, Jun 25, 2010 at 15:10 +0100, Jakub Gustak wrote:
I suggest to use
popen//env:NAME=value
as syntax. That being said i am not totally opposed to adding it directly to execnet. Maybe other people here on the list also have comments ... ... Moving this topic to py-dev list in this case.
I prepared a patch, please review.
What I don't like about it is using XSspec.__dict__ because env:NAME=VALUE requires a iteration through XSpec attributes:
+ def env(self): + return [(env.lstrip('env:'), value) + for env, value in self.gateway.spec.__dict__.iteritems() + if env.startswith('env:')]
I believe a small extension to XSpec API would be nice. Any other ideas?
I think this is bearable as xspecs have very few key-value pairs. You could use env[4:] instead of lstrip() to optimize though :)
One other bit: could you try to rework your patch so that it transfers the environment variables in the "slaveinput" dictionary? This is also processable from pytest_configure and produces a smaller patch i guess.
Can you explain in more details? Passing in the slaveinput is not a problem, but where you would like the environ be updated exactly? jakub
On Fri, Jun 25, 2010 at 16:05 +0100, Jakub Gustak wrote:
One other bit: could you try to rework your patch so that it transfers the environment variables in the "slaveinput" dictionary? This is also processable from pytest_configure and produces a smaller patch i guess.
Can you explain in more details?
Passing in the slaveinput is not a problem, but where you would like the environ be updated exactly?
Just like now but taking it from slaveinput['env']. holger
On Fri, Jun 25, 2010 at 4:56 PM, holger krekel <holger@merlinux.eu> wrote:
On Fri, Jun 25, 2010 at 16:05 +0100, Jakub Gustak wrote:
One other bit: could you try to rework your patch so that it transfers the environment variables in the "slaveinput" dictionary? This is also processable from pytest_configure and produces a smaller patch i guess.
Can you explain in more details?
Passing in the slaveinput is not a problem, but where you would like the environ be updated exactly?
Just like now but taking it from slaveinput['env'].
holger
There we go! _ jakub
On Fri, Jun 25, 2010 at 17:29 +0100, Jakub Gustak wrote:
On Fri, Jun 25, 2010 at 4:56 PM, holger krekel <holger@merlinux.eu> wrote:
On Fri, Jun 25, 2010 at 16:05 +0100, Jakub Gustak wrote:
One other bit: could you try to rework your patch so that it transfers the environment variables in the "slaveinput" dictionary? This is also processable from pytest_configure and produces a smaller patch i guess.
Can you explain in more details?
Passing in the slaveinput is not a problem, but where you would like the environ be updated exactly?
Just like now but taking it from slaveinput['env'].
holger
There we go!
did you run the tests? they fail for me. holger
did you run the tests? they fail for me.
With this patch the tests are passing. Also I found out nice interesting thing. To test those changes I have to use the same xdist version (e.g installed setup.py develope) for testing. This is interesting paradox. How do you setup your development environment properly? _ jakub
On 25/06/10 16:41, holger krekel wrote:
+ def env(self): + return [(env.lstrip('env:'), value) + for env, value in self.gateway.spec.__dict__.iteritems() + if env.startswith('env:')]
You could use env[4:] instead of lstrip() to optimize though :)
using [:4] instead of lstrip is not much about performance, but about correctness:
'env:env'.lstrip('env:') ''
ciao, Anto
+ def env(self): + return [(env.lstrip('env:'), value) + for env, value in self.gateway.spec.__dict__.iteritems() + if env.startswith('env:')]
You could use env[4:] instead of lstrip() to optimize though :)
using [:4] instead of lstrip is not much about performance, but about correctness:
'env:env'.lstrip('env:') ''
True, I somehow forgot strip removes chars not whole string. _ jakub
participants (3)
-
Antonio Cuni -
holger krekel -
Jakub Gustak