Changeset a93896 for src/Python
- Timestamp:
- Aug 30, 2025, 2:41:40 PM (8 weeks ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 454d7a
- Parents:
- 9928ece
- git-author:
- Frederik Heber <frederik.heber@…> (08/14/25 14:36:30)
- git-committer:
- Frederik Heber <frederik.heber@…> (08/30/25 14:41:40)
- Location:
- src/Python
- Files:
-
- 2 edited
-
PythonScripting.cpp (modified) (4 diffs)
-
PythonScripting.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting.cpp
r9928ece ra93896 37 37 #include "PythonScripting.hpp" 38 38 39 #include <string> 40 39 41 //#include "CodePatterns/MemDebug.hpp" 40 42 … … 58 60 // move all lines with "import" to the beginning 59 61 std::string current_line; 62 std::string moduleName; 60 63 while(std::getline(input,current_line,'\n')){ 61 if (current_line.find("import ") != std::string::npos) 62 buffer_import << current_line << std::endl; 63 else 64 if (current_line.find("import ") != std::string::npos) { 65 if (current_line.find(PYMOLECUILDER_MODULE_NAME) != std::string::npos) { 66 // ignore a PyMoleCuilder import, use the AS however. 67 const size_t lowerCaseAsPos = current_line.find("as"); 68 const size_t upperCaseAsPos = current_line.find("AS"); 69 size_t moduleNameStart = std::string::npos; 70 if (lowerCaseAsPos != std::string::npos) 71 moduleNameStart = lowerCaseAsPos+2+1; 72 if (upperCaseAsPos != std::string::npos) 73 moduleNameStart = upperCaseAsPos+2+1; 74 if (moduleNameStart != std::string::npos) { 75 const size_t moduleNameEnd = current_line.find(" ", moduleNameStart); 76 moduleName = current_line.substr( 77 moduleNameStart, 78 moduleNameEnd == std::string::npos ? moduleNameEnd : moduleNameEnd - moduleNameStart 79 ); 80 ELOG(2, "Ignoring found " << PYMOLECUILDER_MODULE_NAME << " import, but keeping AS name " << moduleName << "."); 81 } else { 82 ELOG(2, "Ignoring found " << PYMOLECUILDER_MODULE_NAME << " import."); 83 } 84 } else { 85 buffer_import << current_line << std::endl; 86 } 87 } else { 64 88 buffer_else << current_line << std::endl; 89 } 65 90 } 66 91 std::string pythonscript_import( std::istreambuf_iterator<char>(buffer_import), … … 71 96 try { 72 97 #ifdef HAVE_PYTHON2 73 PyImport_AppendInittab( "pyMoleCuilder", &initpyMoleCuilder );98 PyImport_AppendInittab( PYMOLECUILDER_MODULE_NAME.c_str(), &initpyMoleCuilder ); 74 99 #else 75 PyImport_AppendInittab( "pyMoleCuilder", &PyInit_pyMoleCuilder );100 PyImport_AppendInittab( PYMOLECUILDER_MODULE_NAME.c_str(), &PyInit_pyMoleCuilder ); 76 101 #endif 77 102 … … 89 114 90 115 boost::python::object molecuilder_module( (boost::python::handle<>(PyImport_ImportModule("pyMoleCuilder"))) ); 91 main_namespace["pyMoleCuilder"] = molecuilder_module; 116 main_namespace[PYMOLECUILDER_MODULE_NAME] = molecuilder_module; 117 if (moduleName.size() > 0) 118 main_namespace[moduleName] = molecuilder_module; 92 119 93 120 std::string enveloped_script("print(\"BEGIN of "+python_scripttitle+":\")\n"); -
src/Python/PythonScripting.hpp
r9928ece ra93896 20 20 bool executePythonScript(const std::string &python_string, const std::string &python_scripttitle); 21 21 22 const std::string PYMOLECUILDER_MODULE_NAME = "pyMoleCuilder"; 23 22 24 #endif /* PYTHONSCRIPTING_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.
