Setting a default working directory in PyDev/LiClipse/Eclipse - eclipse

I am using LiClipse / PyDev. When I run some test or other python module from the package explorer via right click -> run as -> python run, the working directory is set to the directory of the corresponding file, e.g. ${workspace_loc:MyProject/tests/misc}.
I want everything to be executed from the root folder of the project though. Under run configurations -> arguments, that folder can be selected via the button "default" which sets the working directory to ${project_loc:/selected project name}. Unfortunately the "default" button apparently is not selected by default, but instead the "other" option with the directory set as described above.
When having many test modules it becomes a little bit annoying to select this "default" button manually for each one. So how do I get LiClipse to actually select that button by default? Or to use the project directory as the working directory by default in some other way?
A similar question was already asked before, but without a satisfying answer: Configuring the working directory in Eclipse 3.8.1 with PyDev-project. The only conclusion was that an Eclipse bug does not allow to configure the value of the default option, which is not necessary for my purpose though. I only want this option to actually be selected.
The issue might be specific to PyDev, as it seems that Eclipse usually has the "default" option selected according to what I read.

Well, unfortunately, as you discovered, there's really no way to set that default in the IDE.
Still, to solve your problem related to tests, my suggestion would be using the pytest runner (you may have to install it -- instructions at: https://pytest.org/latest/getting-started.html and then set in the PyDev > PyUnit preferences the setting to use the pytest runner)... as a note, even if you won't be using the pytest way of writing tests (which I highly recommend), and using unittest.TestCase, it should work...
When running pytest, PyDev needs to follow a different logic because of how it deals and loads its fixtures which make it use always the same folder (I think it's the source folder, but if you're using the source folder and the project folder as the same it should work -- and if that's not the case, in pytest, it's trivial to create a session auto-use fixture which you could use to change the working directory to a given folder (with unittest.TestCase this is more difficult to do as you're constrained through your test class hierarchy, but you could also override the setUp of your tests to do that).

Related

eclipse build automatically modify

I'd like eclipse to only run make in the directory the current file belongs to, not for the entire project. This becomes more important since the project is very big and make on the top level takes around 20 minutes. most of it is entering-leaving directories and checking if build is needed etc. So I have to manually open the directory in cmd and run make. So I'd like eclipse to do this in its build automatically process. Is that possible?
Try to play with Build directory option found in project properties -> C/C++ Build -> Builder Settings tab. The default value there is ${workspace_loc:/your_project}. However Eclipse provides rich set of predefined variables (see under Variables... button). Probably most interesting for you are these ones:
build_files
Returns the set of absolute file system paths whose modification caused the current build. A list of the characters, 'a' (added), 'c' (changed), 'r' (removed), 'f' (files only), 'd' (directories only), can be supplied as an argument to limit the file list to just those types of deltas. Defaults to all deltas.
selected_resource_loc
Returns the absolute file system path of the selected resource.
Other places where you could try to use these variables are Make build target options in Behaviour tab.
If you can add your build step to the External tools configuration, you could create a manual builder from that.
The External tools configurations are set similarly as the Run configurations, but allow executing different kind of steps (e.g. shell, Ant - I am reasonably sure, make-files can also be supported, but I don't use them - if not, then you can add a shell script that runs the make-file).
To set this up you have to go to the project properties (Right click on the project, select Properties), then go to the Builders page, and add a new builder, that is created from an External tool configuration.
I hope I was clear enough for this to work.
Select your project, open Properties -> Builders. Uncheck the builders that you don't want to run automatically anymore. Hit "New..." and select "External Program".
Now you can specify what command shall be run automatically each time the project is built. To have the parent directory of the currently selected file as an argument for your build command, you may use ${selected_resource_loc}\... See the Variables button for more such place holders that can be resolved at runtime.
Afterwards you may want to configure the "refresh" tab, if you also want to see newly created files in your project explorer. And if everything works well after some trial and error, you may also want to look at the "Build Options" tab to have it run in the background.

Eclipse RCP product - is there anyway to update the PATH during launch

I am working on an eclipse RCP product on windows which internally uses some native binaries (dlls) located in a folder called "bin" which would be available as a part of the product.
I need to make sure that the folder "bin" is present in the PATH when the product.exe file is executed. Is there a clean way to make sure that the folder "bin" is added to PATH when the eclipse RCP product is launched?
I don't want to write any script or batch file that updates the PATH and then calls the product.exe. I also don't want to update the environment variable through the windows UI or command prompt.
I know that when we try to run my product from the eclipse IDE environment, there is an option in the run-configuration, wherein one can configure Environment variables on the Environment tab. I can append the "bin" folder to the PATH by creating a new environment variable called "Path" whose value is C:\EclipseRCPProduct\bin;${env_var:PATH}.
However - I would like to do the same when I run my product directly from the Product.exe which is generated. Does anyone have any idea regarding this?
Also - if anyone has any idea regarding the eclipse code which processes the information specified on the Environment tab of the run configuration, it would be great. I could try playing around with the code to see if I could get it to work when the product is launched from outside eclipse IDE - via the generated RCP product.exe
I don't think there's a way to define system environment variables within the launcher.
The following bug seems to request just that
https://bugs.eclipse.org/bugs/show_bug.cgi?id=286463
In the above mentioned bug, a .bat is attached to achieve your goal.
That said, why do the native binaries have to be located in a bin folder?
I.e. why are they not included in a plugin/fragment?

Eclipse ${project_name} expanded inconsistently

I've been using Eclipse ${project_name} variable as a configuration class hack to determine which project is running.
VM args
-Dproject_name=${project_name} in the relevant JRE builder.
Code
String projectName = System.getProperty("project_name");
The problem is that projectName is inconsistent across different machines, and sometimes in the same machine.
Sometimes it is parsed into ${project_name}, sometimes into the the configuration project, and sometimes into the project calling the configuration.
We use Eclipse 3.6 and 3.71, if that's relevant.
Any ideas?
I have seen that the value of ${project_name} depends on the project that has currently the focus in the IDE. A project has a focus for example when one of its files is selected in the package explorer or one of its files is opened in an editor and the focus is on the editor.
Unfortunately it is not related to the project to which the started application belongs to, and I don't know an Eclipse variable that contains that project (although I'm also interested in a solution for this).
So as a workaround, make sure you are actually in the right project when you run the application from within Eclipse.

How can I clean up Eclipse "run configurations"

I set my java runtime options in Eclipse's Window > Prefs > Java > Installed JREs > Default VM Arguments. Since this setting is sufficient for all my main() entry points, I do not bother with customizing the "run configurations". It looks like nice flexibility but I probably will never need it. I was worried that I would have to repeat my VM arguments in the run configurations and so I started to copy my VM arguments but after an experiment it seems that I do not have to. Now I will have the opposite worry that I have some unintended customizations.
To eliminate the second worry, is there a way to eliminate the clutter visible in the Run drop down menu? What about the "Launch configurations" visible in the JAR export dialog? Is a run configuration the same thing as a launch configuration? How do I eliminate the multiple launch configurations?
I am on Eclipse Indigo on Ubuntu.
Edit After I manually delete all the run configurations, and proceed to do an export, buttons are greyed-out so I can't proceed. When I select the launch configuration drop-down, I end up with only one choice, from an unrelated project. I then created a run configuration for the real main entry point for the current project. I expect the clutter will return as I continue to use Eclipse.
One simple way would be to organize your projects by Eclipse workspace, which would limit the "run configurations" list only to the project referenced in a given workspace.
Switching workspaces would reset that list to the ones recorded for the projects of the new workspace.
Note: the OP's answer regarding launches file location isn't the only location possible.
The official one is:
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches
But you can copy them enywhere else you want (as explained in "How do I save Eclipse launch profiles across workspaces?"), either by manually copying those files or by sharing them:
See "Which eclipse files belong under Version Control".
Once you know where they are saved, a simple delete is enough to make them disappear from the launcher menu.
The answer comes from #Francisco Puga
Experimental evidence shows that deleting "launches" seems to make run configurations disappear so it would seem that they might be synonymous.

Launch and debug a single script in PyDev

I am a beginner in using Eclipse and PyDev (Aptana Studio 3). I am not used to and i don't understand the workflow in such big IDEs as Eclipse.
I have a simple task: i have a simple Python script, which i want to open and run in Eclipse, having its output in Eclipse console. Or debug it.
Until now i used another IDE called Eric4, which allowed me to do what i want - open a file and run immediately, without creating a project or setting up launch configurations.
Is this possible in Eclipse, or i have to create a project for each file i want to run or debug? I want to understand how it works.
I guess i understand that creating a project is needed at least for settings up the paths (PYTHONPATH), but if it's a single script - somehow to use by default the current directory?
For example i have a folder called snippets where i keep a lot of python scripts which demonstrate some functionality. How do i open these files one by one and run them?
Most of my coworkers launch python scripts in a separate console - python my_scipt.py.
You need to have at least one project with the configuration you want (i.e.: syntax type, interpreter), then, open the file you want to run and press F9.
If it's an external file -- i.e.: a file that's not under a project in Eclipse -- it'll ask you to associate a project with the launch to get the needed information for the launch, but the file doesn't really have to be in the project (note that you can drag external files from your filesystem into Eclipse to open them).
I suggest you follow the steps on the getting started: http://pydev.org/manual_101_root.html (it guides you to configuring PyDev and explains how to do a run/debug session).