Great. If you can wait few days, I have to implement a solution to allow calling a subprocess with a ācleanā environment (aka without Slicer paths) for a different project.
Once done, you should have an easy way to achieve this.
Note that in case of Elastix, we added more directories to the path/LD path. In your case you probably want to either add your external programās paths to the beginning of relevant environment variables; or remove all Slicer-specific paths from environment variables.
Thanks, this will be useful. Please consider giving a more descriptive name and only use positive statements in names (try to describe what it is, instead of what it is not). For example, systemEnv(), defaultEnv(), externalEnv(), or startupEnv() names would be better.
jcfr
(Jean Christophe Fillion Robin (Kitware))
#13
Good point. Thanks for the suggestions . I will most likely go with systemEnvstartupEnvironment.
jcfr
(Jean Christophe Fillion Robin (Kitware))
#14
Here is a work-in-progress topic
1 Like
jcfr
(Jean Christophe Fillion Robin (Kitware))
#15
With the upcoming feature, it will be possible to easily invoke processes by excluding the Slicer environment.:
from c++ (using app->startupEnvironment()), or;
from python (using slicer.util.startupEnvironment()
Here are two examples:
Without using the startup environment, this first example fails (as expected):
>>> from subprocess import check_output
>>> check_call(["/usr/bin/python3", "-c", "print('hola')"])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/jcfr/Projects/Slicer-2-build/python-install/lib/python2.7/subprocess.py", line 186, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['/usr/bin/python3', '-c', "print('hola')"]' returned non-zero exit status -6
Now, using the sanitized environment, this one succeeds:
jcfr
(Jean Christophe Fillion Robin (Kitware))
#16
The topic is now read for final review
601: Test timeout computed to be: 1800
601: Number of registered modules: 1
601: Number of instantiated modules: 1
601: Number of loaded modules: 1
601: -------------------------------------------
601: path: ['/home/jcfr/Projects/Slicer-2-build/Slicer-build/Applications/SlicerApp/Testing/Python', '/home/jcfr/Projects/Slicer-2/Base/Python/slicer/tests']
601: testname: test_slicer_environment
601: -------------------------------------------
601: test_slicer_app_environment (test_slicer_environment.SlicerEnvironmentTests) ... ok
601: test_slicer_app_startupEnvironment (test_slicer_environment.SlicerEnvironmentTests) ... ok
601: test_slicer_util_startupEnvironment (test_slicer_environment.SlicerEnvironmentTests) ... ok
601:
601: ----------------------------------------------------------------------
601: Ran 3 tests in 0.002s
601:
601: OK
601: vtkDebugLeaks has found no leaks.
1/1 Test #601: py_nomainwindow_test_slicer_environment ... Passed 1.23 sec
jcfr
(Jean Christophe Fillion Robin (Kitware))
#17
Starting with r26351, a new public API allowing to get the startup environment is available.
In c++: qSlicerCoreApplication::startupEnvironment()
In python: slicer.util.startupEnvironment()
We are still discussing some of the internals but that will not affect the public API.