Skip to content

Commit 81d34ad

Browse files
committed
Merge remote-tracking branch 'sofa-framework/master' into robosoft2022_integration
2 parents f8d0895 + 483597f commit 81d34ad

12 files changed

Lines changed: 53 additions & 26 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Remove old artifacts
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
remove-old-artifacts:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 10
10+
11+
steps:
12+
- name: Remove old artifacts
13+
uses: c-hive/gha-remove-artifacts@v1
14+
with:
15+
age: '1 day' # '<number> <unit>', e.g. 5 days, 2 years, 90 seconds, parsed by Moment.js
16+
# Optional inputs
17+
# skip-tags: true
18+
# skip-recent: 5

CMake/SofaPython3Tools.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ function(SP3_add_python_module)
348348
LIBRARY DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
349349
ARCHIVE DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
350350
)
351+
elseif (DESTINATION)
352+
install(
353+
TARGETS ${A_TARGET}
354+
RUNTIME DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT applications
355+
LIBRARY DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
356+
ARCHIVE DESTINATION "lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}" COMPONENT libraries
357+
)
351358
endif()
352359

353360
foreach(header ${A_HEADERS})

Plugin/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(Plugin VERSION 1.0)
22

33
set(HEADER_FILES
4-
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/config.h
4+
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/config.h.in
55
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/initModule.h
66
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/PythonEnvironment.h
77
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SceneLoaderPY3.h
@@ -81,6 +81,8 @@ set_target_properties(
8181
CUDA_VISIBILITY_PRESET "hidden"
8282
)
8383

84+
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>")
85+
8486
sofa_create_component_in_package_with_targets(
8587
COMPONENT_NAME ${PROJECT_NAME}
8688
COMPONENT_VERSION ${SofaPython3_VERSION}

Plugin/src/SofaPython3/DataCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#pragma once
2222

2323
#include <pybind11/numpy.h>
24-
#include "config.h"
24+
#include <SofaPython3/config.h>
2525

2626
////////////////////////// FORWARD DECLARATION ///////////////////////////
2727
namespace sofa {

Plugin/src/SofaPython3/DataHelper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ size_t getSize(BaseData* self)
294294

295295
py::buffer_info toBufferInfo(BaseData& m)
296296
{
297+
scoped_read_access guard(&m);
298+
297299
const AbstractTypeInfo& nfo { *m.getValueTypeInfo() };
298300
auto itemNfo = nfo.BaseType();
299301

@@ -411,7 +413,7 @@ py::array resetArrayFor(BaseData* d)
411413
py::array getPythonArrayFor(BaseData* d)
412414
{
413415
auto& memcache = getObjectCache();
414-
if(memcache.find(d) == memcache.end())
416+
if(d->isDirty() || memcache.find(d) == memcache.end())
415417
{
416418
auto capsule = py::capsule(new Base::SPtr(d->getOwner()));
417419

Plugin/src/SofaPython3/PythonEnvironment.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ SOFAPYTHON3_API py::module PythonEnvironment::importFromFile(const std::string&
131131
if (globals == nullptr)
132132
globals = &globs;
133133
py::eval<py::eval_statements>( // tell eval we're passing multiple statements
134-
"import imp\n"
135-
"new_module = imp.load_module(module_name, open(path), path, ('py', 'U', imp.PY_SOURCE))\n",
134+
"import importlib.util \n"
135+
"spec = importlib.util.spec_from_file_location(module_name, path) \n"
136+
"new_module = importlib.util.module_from_spec(spec) \n"
137+
"spec.loader.exec_module(new_module)",
136138
*globals,
137139
locals);
138140
py::module m = py::cast<py::module>(locals["new_module"]);
@@ -233,25 +235,16 @@ void PythonEnvironment::Init()
233235
// Lastly, we (try to) add modules from the root of SOFA
234236
addPythonModulePathsFromDirectory( Utils::getSofaPathPrefix() );
235237

236-
try
237-
{
238-
py::module::import("SofaRuntime");
239-
}
240-
catch (pybind11::error_already_set)
241-
{
242-
msg_error("SofaPython3") << "Could not import SofaRuntime module, initializing python3 for SOFA is not possible";
243-
return;
244-
}
245238
getStaticData()->m_sofamodule = py::module::import("Sofa");
246-
239+
PyRun_SimpleString("import SofaRuntime");
247240

248241
// python livecoding related
249242
PyRun_SimpleString("from Sofa.livecoding import onReimpAFile");
250243

251244
// general sofa-python stuff
252245

253246
// python modules are automatically reloaded at each scene loading
254-
//setAutomaticModuleReload( true );
247+
setAutomaticModuleReload( true );
255248

256249
// Initialize pluginLibraryPath by reading PluginManager's map
257250
std::map<std::string, Plugin>& map = PluginManager::getInstance().getPluginMap();

Plugin/src/SofaPython3/PythonEnvironment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include <pybind11/pybind11.h>
4545
#include <pybind11/eval.h>
4646

47-
#include "config.h"
47+
#include <SofaPython3/config.h>
4848

4949
namespace sofapython3
5050
{

Plugin/src/SofaPython3/PythonFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sofa/core/objectmodel/Base.h>
2626
#include <sofa/core/objectmodel/Event.h>
2727
#include <pybind11/pybind11.h>
28-
#include "config.h"
28+
#include <SofaPython3/config.h>
2929

3030
/////////////////////////////// DECLARATION //////////////////////////////
3131
namespace sofapython3

Plugin/src/SofaPython3/SceneLoaderPY3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <sofa/simulation/Visitor.h>
2828
#include <sofa/simulation/Node.h>
2929

30-
#include "config.h"
30+
#include <SofaPython3/config.h>
3131

3232
namespace sofapython3
3333
{
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@
4040
#endif
4141

4242
// define own pybind version macro, much easier to test/read
43-
#define PYBIND11_SOFA_VERSION (PYBIND11_VERSION_MAJOR * 10000 \
44-
+ PYBIND11_VERSION_MINOR * 100 \
45-
+ PYBIND11_VERSION_PATCH)
43+
#define PYBIND11_SOFA_VERSION_MAJOR @pybind11_VERSION_MAJOR@
44+
#define PYBIND11_SOFA_VERSION_MINOR @pybind11_VERSION_MINOR@
45+
#define PYBIND11_SOFA_VERSION_PATCH @pybind11_VERSION_PATCH@
46+
#define PYBIND11_SOFA_VERSION ( \
47+
PYBIND11_SOFA_VERSION_MAJOR * 10000 \
48+
+ PYBIND11_SOFA_VERSION_MINOR * 100 \
49+
+ PYBIND11_SOFA_VERSION_PATCH )
50+
4651
// pybind11 already bind the attributeError starting from 2.8.1 version.
4752
// so if the version is >= 2.8.1, macro does nothing, otherwise bind attribute_error
4853
#if PYBIND11_SOFA_VERSION >= 20801

0 commit comments

Comments
 (0)