Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

COMP: Add HAVE_PYRUN_{CLOSE, OPEN}FILE anticipating build against sys…

…tem python

Anticipating the possibility to build Slicer against a system python,
introduced variable HAVE_PYRUN_CLOSEFILE and HAVE_PYRUN_OPENFILE variable
to be able to conditionally build Slicer library with fopen/fclose
built-in the python library.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21848 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
commit c7eab13280bd778b6cb7a734a86a00f7d8755556 1 parent 12b3e67
@jcfr jcfr authored
View
10 Base/Logic/vtkSlicerScriptedLoadableModuleLogic.cxx
@@ -178,7 +178,11 @@ bool vtkSlicerScriptedLoadableModuleLogic::SetPythonSource(const std::string& py
assert(pythonSource.find(".py") != std::string::npos);
// Open the file
+#ifdef HAVE_PYRUN_OPENFILE
+ FILE* pyfile = PyRun_OpenFile(pythonSource.c_str());
+#else
FILE* pyfile = fopen(pythonSource.c_str(), "r");
+#endif
if (!pyfile)
{
vtkErrorMacro(<< "SetPythonSource - File " << pythonSource << " doesn't exist !");
@@ -208,6 +212,12 @@ bool vtkSlicerScriptedLoadableModuleLogic::SetPythonSource(const std::string& py
return false;
}
+#ifdef HAVE_PYRUN_CLOSEFILE
+ PyRun_CloseFile(pyfile);
+#else
+ fclose(pyfile);
+#endif
+
//std::cout << "classToInstantiate:" << classToInstantiate << std::endl;
PyObject * arguments = PyTuple_New(1);
View
4 Base/QTGUI/qSlicerScriptedLoadableModule.cxx
@@ -139,7 +139,7 @@ bool qSlicerScriptedLoadableModule::setPythonSource(const QString& newPythonSour
Q_ASSERT(newPythonSource.endsWith(".py"));
// Open the file
-#ifdef _WIN32
+#ifdef HAVE_PYRUN_OPENFILE
FILE* pyfile = PyRun_OpenFile(newPythonSource.toLatin1());
#else
FILE* pyfile = fopen(newPythonSource.toLatin1(), "r");
@@ -169,7 +169,7 @@ bool qSlicerScriptedLoadableModule::setPythonSource(const QString& newPythonSour
classToInstantiate = PyDict_GetItemString(global_dict, className.toLatin1());
PyDict_SetItemString(global_dict, "__name__", PyString_FromString("__main__"));
}
-#ifdef _WIN32
+#ifdef HAVE_PYRUN_CLOSEFILE
PyRun_CloseFile(pyfile);
#else
fclose(pyfile);
View
4 Base/QTGUI/qSlicerScriptedLoadableModuleWidget.cxx
@@ -123,7 +123,7 @@ bool qSlicerScriptedLoadableModuleWidget::setPythonSource(const QString& newPyth
Q_ASSERT(newPythonSource.endsWith(".py"));
// Open the file
-#ifdef _WIN32
+#ifdef HAVE_PYRUN_OPENFILE
FILE* pyfile = PyRun_OpenFile(newPythonSource.toLatin1());
#else
FILE* pyfile = fopen(newPythonSource.toLatin1(), "r");
@@ -170,7 +170,7 @@ bool qSlicerScriptedLoadableModuleWidget::setPythonSource(const QString& newPyth
return false;
}
-#ifdef _WIN32
+#ifdef HAVE_PYRUN_CLOSEFILE
PyRun_CloseFile(pyfile);
#else
fclose(pyfile);
View
2  CMake/vtkSlicerConfigure.h.in
@@ -71,6 +71,8 @@
#ifdef Slicer_USE_PYTHONQT
# define Slicer_PYTHON_VERSION_DOT "@Slicer_PYTHON_VERSION_DOT@"
# define Slicer_PYTHON_VERSION "@Slicer_PYTHON_VERSION@"
+#cmakedefine HAVE_PYRUN_CLOSEFILE
+#cmakedefine HAVE_PYRUN_OPENFILE
#endif //Slicer_USE_PYTHONQT
#cmakedefine Slicer_BUILD_QTLOADABLEMODULES
View
3  Libs/MRML/Core/vtkMRMLConfigure.h.in
@@ -15,4 +15,7 @@
#cmakedefine MRML_USE_TEEM
#cmakedefine MRML_USE_vtkTeem
+#cmakedefine HAVE_PYRUN_CLOSEFILE
+#cmakedefine HAVE_PYRUN_OPENFILE
+
#define MRML_SUPPORT_VERSION @MRML_SUPPORT_VERSION@
View
10 Libs/MRML/DisplayableManager/vtkMRMLScriptedDisplayableManager.cxx
@@ -278,7 +278,11 @@ void vtkMRMLScriptedDisplayableManager::SetPythonSource(const std::string& pytho
assert(pythonSource.find(".py") != std::string::npos);
// Open the file
+#ifdef HAVE_PYRUN_OPENFILE
+ FILE* pyfile = PyRun_OpenFile(pythonSource.c_str());
+#else
FILE* pyfile = fopen(pythonSource.c_str(), "r");
+#endif
if (!pyfile)
{
vtkErrorMacro(<< "SetPythonSource - File " << pythonSource << " doesn't exist !");
@@ -307,6 +311,12 @@ void vtkMRMLScriptedDisplayableManager::SetPythonSource(const std::string& pytho
return;
}
+#ifdef HAVE_PYRUN_CLOSEFILE
+ PyRun_CloseFile(pyfile);
+#else
+ fclose(pyfile);
+#endif
+
//std::cout << "classToInstantiate:" << classToInstantiate << std::endl;
PyObject * arguments = PyTuple_New(1);
View
2  SuperBuild.cmake
@@ -182,6 +182,8 @@ set(ep_cmake_boolean_args
DOCUMENTATION_TARGET_IN_ALL
BUILD_TESTING
BUILD_SHARED_LIBS
+ HAVE_PYRUN_OPENFILE
+ HAVE_PYRUN_CLOSEFILE
WITH_COVERAGE
WITH_MEMCHECK
Slicer_BUILD_CLI
View
2  SuperBuild/External_python_win.cmake
@@ -54,6 +54,8 @@ if(Slicer_USE_PYTHONQT_WITH_TCL)
file(TO_CMAKE_PATH "${out}" out)
file(TO_CMAKE_PATH "${script}" script)
set(python_SOURCE_DIR ${python_build})
+ set(HAVE_PYRUN_CLOSEFILE 1)
+ set(HAVE_PYRUN_OPENFILE 1)
configure_file(SuperBuild/python_patch_step_win.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/python_patch_step.cmake
@ONLY)
Please sign in to comment.
Something went wrong with that request. Please try again.