Skip to content

Commit b58e413

Browse files
Merge branch 'master' into pr-fix-callpoint-api
2 parents 040e394 + 74feb01 commit b58e413

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
matrix:
2121
os: [ubuntu-20.04, macos-10.15, windows-2019]
2222
sofa_branch: [master]
23-
python_version: ['3.9']
23+
python_version: ['3.8']
2424

2525
steps:
2626
- name: Setup SOFA and environment

Plugin/src/SofaPython3/DataHelper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ void copyScalar(BaseData* a, const AbstractTypeInfo& nfo, pybind11::array_t<T, p
221221
void* ptr = a->beginEditVoidPtr();
222222

223223
auto r = src.unchecked();
224-
for (ssize_t i = 0; i < r.shape(0); i++)
224+
for (pybind11::ssize_t i = 0; i < r.shape(0); i++)
225225
{
226-
for (ssize_t j = 0; j < r.shape(1); j++)
226+
for (pybind11::ssize_t j = 0; j < r.shape(1); j++)
227227
{
228228
nfo.setScalarValue( ptr, i*r.shape(1)+j, r(i,j) );
229229
}

Plugin/src/SofaPython3/PythonEnvironment.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,27 +181,26 @@ void PythonEnvironment::Init()
181181
}
182182

183183
PyEval_InitThreads();
184-
gil lock;
185184

186185
// Required for sys.path, used in addPythonModulePath().
187-
PyRun_SimpleString("import sys");
186+
executePython([]{ PyRun_SimpleString("import sys");});
188187

189188
// Force C locale.
190-
PyRun_SimpleString("import locale");
191-
PyRun_SimpleString("locale.setlocale(locale.LC_ALL, 'C')");
189+
executePython([]{ PyRun_SimpleString("import locale");});
190+
executePython([]{ PyRun_SimpleString("locale.setlocale(locale.LC_ALL, 'C')");});
192191

193192
// Workaround: try to import numpy and to launch numpy.finfo to cache data;
194193
// this prevents a deadlock when calling numpy.finfo from a worker thread.
195-
PyRun_SimpleString("try:\n\timport numpy;numpy.finfo(float)\nexcept:\n\tpass");
194+
executePython([]{ PyRun_SimpleString("try:\n\timport numpy;numpy.finfo(float)\nexcept:\n\tpass");});
196195

197196
// Workaround: try to import scipy from the main thread this prevents a deadlock when importing
198197
// scipy from a worker thread when we use the SofaScene asynchronous loading
199-
PyRun_SimpleString("try:\n\tfrom scipy import misc, optimize\nexcept:\n\tpass\n");
198+
executePython([]{ PyRun_SimpleString("try:\n\tfrom scipy import misc, optimize\nexcept:\n\tpass\n");});
200199

201200
// If the script directory is not available (e.g. if the interpreter is invoked interactively
202201
// or if the script is read from standard input), path[0] is the empty string,
203202
// which directs Python to search modules in the current directory first.
204-
PyRun_SimpleString(std::string("sys.path.insert(0,\"\")").c_str());
203+
executePython([]{ PyRun_SimpleString(std::string("sys.path.insert(0,\"\")").c_str());});
205204

206205
// Add the paths to the plugins' python modules to sys.path. Those paths
207206
// are read from all the files in 'etc/sofa/python.d'
@@ -238,12 +237,12 @@ void PythonEnvironment::Init()
238237
// Lastly, we (try to) add modules from the root of SOFA
239238
addPythonModulePathsFromDirectory( Utils::getSofaPathPrefix() );
240239

241-
getStaticData()->m_sofaModule = py::module::import("Sofa");
242-
getStaticData()->m_sofaRuntimeModule = py::module::import("SofaRuntime");
243-
PyRun_SimpleString("import SofaRuntime");
240+
executePython([]{ getStaticData()->m_sofamodule = py::module::import("Sofa"); });
241+
executePython([]{ getStaticData()->m_sofaRuntimeModule = py::module::import("SofaRuntime"); });
242+
executePython([]{ PyRun_SimpleString("import SofaRuntime");});
244243

245244
// python livecoding related
246-
PyRun_SimpleString("from Sofa.livecoding import onReimpAFile");
245+
executePython([]{ PyRun_SimpleString("from Sofa.livecoding import onReimpAFile");});
247246

248247
// general sofa-python stuff
249248

@@ -313,16 +312,14 @@ void PythonEnvironment::Release()
313312
void PythonEnvironment::addPythonModulePath(const std::string& path)
314313
{
315314
PythonEnvironmentData* data = getStaticData() ;
316-
if ( data->addedPath.find(path)==data->addedPath.end()) {
315+
if ( data->addedPath.find(path)==data->addedPath.end())
316+
{
317317
// note not to insert at first 0 place
318318
// an empty string must be at first so modules can be found in the current directory first.
319319

320-
{
321-
gil lock;
322-
PyRun_SimpleString(std::string("sys.path.insert(1,\""+path+"\")").c_str());
323-
}
320+
executePython([&]{ PyRun_SimpleString(std::string("sys.path.insert(1,\""+path+"\")").c_str());});
324321

325-
msg_info("SofaPython3") << "Added '" + path + "' to sys.path";
322+
msg_info("SofaPython3")<< "Added '" + path + "' to sys.path";
326323
data->addedPath.insert(path);
327324
}
328325
}
@@ -541,9 +538,8 @@ void PythonEnvironment::setArguments(const std::string& filename, const std::vec
541538

542539
void PythonEnvironment::SceneLoaderListerner::rightBeforeLoadingScene()
543540
{
544-
gil lock;
545541
// unload python modules to force importing their eventual modifications
546-
PyRun_SimpleString("SofaRuntime.unloadModules()");
542+
executePython([]{ PyRun_SimpleString("SofaRuntime.unloadModules()");});
547543
}
548544

549545
void PythonEnvironment::setAutomaticModuleReload( bool b )
@@ -556,8 +552,7 @@ void PythonEnvironment::setAutomaticModuleReload( bool b )
556552

557553
void PythonEnvironment::excludeModuleFromReload( const std::string& moduleName )
558554
{
559-
gil lock;
560-
PyRun_SimpleString( std::string( "try: SofaRuntime.__SofaPythonEnvironment_modulesExcludedFromReload.append('" + moduleName + "')\nexcept:pass" ).c_str() );
555+
executePython([&]{ PyRun_SimpleString( std::string( "try: SofaRuntime.__SofaPythonEnvironment_modulesExcludedFromReload.append('" + moduleName + "')\nexcept:pass" ).c_str() );});
561556
}
562557

563558
static const bool debug_gil = false;

bindings/Sofa/Bindings.SofaConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin)
77

88
# Required by Bindings.Sofa.Components, Bindings.Sofa.Core, Bindings.Sofa.Helper, Bindings.Sofa.Simulation, Bindings.Sofa.Types, Bindings.SofaGui
99
find_package(SofaFramework QUIET REQUIRED)
10+
# Required by Bindings.Sofa.Core
11+
find_package(SofaBaseCollision QUIET REQUIRED)
12+
find_package(SofaBaseVisual QUIET REQUIRED)
13+
find_package(SofaBaseUtils QUIET REQUIRED)
1014
# Required by Bindings.Sofa.Simulation, Bindings.SofaRuntime
1115
find_package(SofaSimulationGraph QUIET REQUIRED)
1216

0 commit comments

Comments
 (0)