Closed matthieu-nesme closed 6 years ago
I just cherry-picked Anatoscope's changes related to SofaPython (excl. PythonScriptController that comes in #283). It seems huge, but it is simply:
More cleanings are coming, and waiting for #283 and #286.
@matthieu-nesme I like this PR a lot :)
It looks huge, for sure ;-)
A little update:
wrap/unwrap
mechanism: there are wrapping traits in PythonToSofa.inl
specifying wrapped type (PySPtr
or PyPtr
) for a given type (defaults to PyPtr
)Base
, BaseData
and BaseLink
-derived classes. Base
-derived classes are wrapped as PySPtr<Base>
, BaseData
-derived as PyPtr<BaseData>
, etc. this should cover most cases.unwrap<T>(py_obj)
first recovers the wrapped type and the object pointer, then dynamic_casts<T*>
unwrap_self<T>(py_obj)
does the same but with static_cast
(this is for self
arguments, python enforces that self
is an instance of this type).Extension code should look like this now:
Node* node = sofa::py::unwrap_self<Node>(self);
BaseObject* obj = sofa::py::unwrap<BaseObject>(py_obj); if(!obj) { ... }
Nice work guys, but such a work is more dedicated to a branch and pull-request little by little the features ! here the work is un-readable for other devs.
@matthieu-nesme and @maxime-tournier do you agree if we cut this PR in four on a per files basis instead of per commit ? It could be:
[ci-build]
@hugtalbot To me this PR is a prefect example of where we could "relax/ease" the merging process.
From the submitter point of view we are "giving" to the community more than 50h of work and then we are requested to do more to split the PR. At some point we need to be a bit more pragmatic, having a "industrial grade" reviewing process is great, but do we have the budget for that ?
In this PR, mathieu, maxime and I contributed...if it breaks something in master, which is a development branch anyway, ...we will be there to fix it a-posteriori.
But you are right, this PR should have a better description and this will be done when it will be taggued to review :)
@damienmarchal ok for splitting, this is getting too big anyways :-)
Ok, I will do that this evening.
I am not sure it is doable as things must depend on each other.
[ci-build]
@hugtalbot, @guparan
I really would like to take the easy path of merging the whole PR.
This PR can break compatibility...but to me this important to allow breaking cleaning (and to have that done in a single step is far easier (in term of extra management work) than doing that in multiple small PR.
[ci-build]
sorry for the delay @damienmarchal , I merge it today as soon as the build is done
hey @damienmarchal is it normal that the test testCreateObjectDataConversionWarning is failing since your last commit ?
@hugtalbot No it is not..sorry for that.. I will fix the conflict and the failing test.
@hugtalbot I fixed the test, is was not updated to handle the change between repr and str as well as the commit.
@damienmarchal sure ? it's look like the test is still failing, isn't it ?
My bad (again). I forgot to push to upstream and not origin.
[ci-build]
EDITED: Damien
Currently the SofaPython plugin is in a very poor shapes with two serious problems. The first one is a problem for developper with a lot of duplicated or invalid or in-elegant code which impact maintainability of our code base. The second problem is the lack of consistency in the way warning and errors are reported. In sofa some component rise en exception while others prints a message and return None which is very problematic to users.
In this PR we addressed these two issues through a major cleaning set of changes:
[SofaPython]:
[Flexible/python] Fix the examples & the tests to take into account the changes in SofaPython
[Compliant/python] Fix the examples & the tests to take into account the changes in SofaPython
To simplify the submitter's life (and don't waste their time) some extras (read not really relevant) changes are also added to the PR:
There is still some work todo (if you have free time to offer): Eg: in Compliant there is still patterns like:
The SP_MESSAGE_ERROR is probably not needed as it duplicate the one provided by the python exception.
While in
PyExc_SetString() should replace the message error & the bad argument.
More generally there is still a lot of SPMESSAGE() instead of msg_ and there is a lot of method that haven't their docstring.
This PR:
Reviewers will merge only if all these checks are true.