Set environment variable at the project level - pydev

Using PyDev with Eclipse Juno, I need to set some environment variables to debug every single of the many scripts in my project. I have found how to set them for a given script but it would be totally impractical to do it for all of them. The only solution I have found consists in adding those variable to the Python interpreter configuration in the Preferences. But then it will be used by all projects, which I don't want.
I thought of creating a script setting those environment variables and then launching Python, and then add it as a new Python interpreter but PyDev does not accept two interpreters with the same actual exe (I guess it checks sys.executable).

The recommended approach is really setting it at the Python interpreter level.
You can use virtualenv ( http://pypi.python.org/pypi/virtualenv ) to create a copy of your interpreter in a different path.

Just to elaborate that #FabioZadrozny's answer meets the need of the OP...
In case it hasn't occurred to you, do this:
From the menu "Window->Preference"
Navigate to "PyDev->Interpreters->Python Interpreter"
Create a new interpreter instance with "New..." button
Name it something like "python-MyProj", but use the same executable you are already using
Now in the "Environment" tab for that interpreter, set up the needed environment variable
Now, see the PyDev project to use THAT interpreter:
Right-click the project to get "Properties..."
Navigate to "PyDev-Interpreter/Grammar"
Select the newly created interpreter instance by name
Now run any python file within the project, and it should "see" the configured environment variable.
By this mechanism, you do have a "project specific setting"... which, again, for the reasons #FabioZadrozny pointed out, need to be set at the interpreter level.

Related

Apama 10.3: Add pysys nature to projects

I am working with Apama 10.3, in Software AG Designer. I have a project that I'd like to add the Pysys nature to my project, but the usual attempts (right-click on project name, project > properties, etc.) don't help. I couldn't find anything in the documentation either.
How can I work with Pysys in Designer, please? I'd like to be able to build my tests via the IDE, for consistency and convenience.
Currently eclipse/Designer doesn't have a PySys nature, but what you can do is add a generic eclipse "Python" nature – which you can do using "PyDev".
And then to launch pysys from eclipse you’ll need to add a launch configuration. There are various options but the most convenient for this purpose is the “external tool” eclipse feature.
You need to invoke pysys.py with the right environment for locating python and also Apama if you want to use it with the Apama extensions. If you’re using PySys with Apama 10.3.1+ this is easy as you can use the new capability of the apama_env.bat script to execute a command e.g. ${apama_home}\bin\apama_env pysys run –n 0 –purge. If you’re on an earlier version I’m afraid you probably need to create a trivial .bat script of your own that first runs apama_env and then pysys %*
You'll want to set the working directory in the eclipse launch config go ${project_loc}/tests so it runs all tests. Or alternatively, ${selected_resource_loc}, to invoke a specific test subtree. You could create separate launch configs for both use cases.

Installing haxe

I have a problem with programming in Haxe. Whenever I try to run a code, I get an error:
Please don't add haxe/std to your classpath, instead set HAXE_STD_PATH env var.
I tried to find a solution - according to multiple sites, I'm supposed to change the environment variable HAXE_LIBRARY_PATH to HAXE_STD_PATH and set the value to actual path to the std file in my haxe folder. In my case, there was no such variable among my env vars, so I made HAXE_STD_PATH as a new one - and I still get the same error.
I'm using FlashDevelop and when I try to search for any class that would reference std, I can see in Type Explorer that there is a classpath that leads straight to haxe/std, which should not happen IMO. I looked at classpaths in Properties and the path to std was not listed, so I could not change it.
So problem could be in the classpath or in FlashDevelop settings.
Did anyone have the same problem?
Oh, and BTW I'm using Windows - and yes, restarting did not help.
I removed all: FD including program settings and HaxeToolkit (the whole map).
Then I reinstalled FD, Haxe (using the apps window from FD), Lime and openFL (from command window).
Now I don't get this error anymore.

Get eclipse run configuration arguments from script or environment variable (Pydev)

I am developing with openerp using PyDev on a Linux box.
So far I have to use 6 different run configurations, with an argument whose value is the same for all these configurations, and an other argument which is specific to each one.
Example: openerp -d <common_value> -u <specific_value>
I want to be able to do this : openerp -d $COMMON_VALUE -u <specific_value>, so that everytime I have to change the value of db, I don't have to go and change its value manually in all the six run configurations.
I tried to use environment variables, but these do not get reloaded even after I restart Eclipse. Would there be a way to read it from a bash script or other ?
Thank you for your help
Well, I think the best way in this case would be creating a launcher script (which in turn would fix sys.argv and call execfile with the openerp module) and create a launch for that module instead.
If you want, you can load that value from an environment variable (then set the environment variable in preferences > PyDev > Interpreters > Python Interpreter > Environment) -- and that's also the place you have to use to change it later on, as the process will by default inherit the environment variables that were used when Eclipse was started up.
Or load it from a file -- or leave it hardcoded and change on that module -- which may be the most straightforward way :)
Another option:
You can 'connect' your launch configurations to a file (run > run configurations > select the configuration > common > save as > shared file), that way you can do a search/replace to fix the run configurations (which should be faster than doing it in the UI).

How to set up environment variable for all tests in Eclipse?

Setting up environment variables for hundreds of tests get old very quick. Is there a way to declare an environmental variable globally in Eclipse?
Can this be done in Eclipse? Can this be done outside of Eclipse?
It seems that the only way to do it is to enable "Run all tests in the selected project .." and set Environment variables once there.
If you want to run a single test, and that test requires an environment variable set, it looks like you need to set that environment variable as part of that tests's settings.
In windows use the "start" command to spawn eclipse from command line with defined variables (linux has similar functionality)
Make file starteclipse.cmd
================================
SET VAR1=SOMEVALUE
SET VAR2=SOMEVALUE
start d:\eclipse\eclipse.exe
================================
From command line go to the dir with starteclipse.cmd file and run it.
This will spawn eclipse with proper environment settings.
I also find it frustrating having to set env vars one by one.
If you own the code and have a chance to change it, you'd be better off using a System property instead, which can be passed as VMArgs -Dprop=val.
You can set VM args in a global level - Preferences | Java | Installed JREs, and Plugin Development | Target platform.
Even if you can't change the code, most well civilised java libs support properties as well if not more than env vars- so it's worth double checking.
(of course it's not an option for external processes).

Reusing Eclipse run time variable input

I am trying to create an eclipse runtime tool to diff 2 files. For my specific instance the files have the same name but are comparing versions.
I created a runtime external tool configuration using p4merge using these arguments:
gen\${string_prompt:File Name} gen2\${string_prompt:File Name}
What I really want is 1 dialog box where I can use the variable 2ce.
Anyone know if this is possible directly in eclipse other than writing a batch or shell script?
In the "External Tools Configurations" window, on the "Environment" tab, create a new environment variable. Set it's name to tmp_StrInput or something similar and it's value to "${string_prompt:Hint:DefaultText}".
Then, in your arguments (or anywhere else) on the "Main" tab, use ${env_var:tmp_StrInput} every time you want to insert the result from the string_prompt dialog.
The prompt appears and sets the environmental variable before the tool is run, the only negative side-effect is that you have created an extra environment variable. It does seem a bit like a work around but it works well!