sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
871 stars 297 forks source link

[SofaPython] General SofaPython cleaning #304

Closed matthieu-nesme closed 6 years ago

matthieu-nesme commented 6 years ago

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:

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:

     SP_MESSAGE_ERROR( "_Compliant_getAssembledImplicitMatrix: wrong arguments" );
     return NULL;

The SP_MESSAGE_ERROR is probably not needed as it duplicate the one provided by the python exception.

While in

   SP_MESSAGE_ERROR( "_Compliant_getAssembledImplicitMatrix: first argument is not a BaseNode" );
  PyErr_BadArgument();
  return NULL;

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.

matthieu-nesme commented 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.

damienmarchal commented 6 years ago

@matthieu-nesme I like this PR a lot :)

bcarrez commented 6 years ago

It looks huge, for sure ;-)

maxime-tournier commented 6 years ago

A little update:

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) { ... }
hugtalbot commented 6 years ago

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.

damienmarchal commented 6 years ago

@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:

bcarrez commented 6 years ago

[ci-build]

damienmarchal commented 6 years ago

@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 :)

maxime-tournier commented 6 years ago

@damienmarchal ok for splitting, this is getting too big anyways :-)

damienmarchal commented 6 years ago

Ok, I will do that this evening.

matthieu-nesme commented 6 years ago

I am not sure it is doable as things must depend on each other.

damienmarchal commented 6 years ago

[ci-build]

damienmarchal commented 6 years ago

@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.

hugtalbot commented 6 years ago

[ci-build]

hugtalbot commented 6 years ago

sorry for the delay @damienmarchal , I merge it today as soon as the build is done

hugtalbot commented 6 years ago

hey @damienmarchal is it normal that the test testCreateObjectDataConversionWarning is failing since your last commit ?

damienmarchal commented 6 years ago

@hugtalbot No it is not..sorry for that.. I will fix the conflict and the failing test.

damienmarchal commented 6 years ago

@hugtalbot I fixed the test, is was not updated to handle the change between repr and str as well as the commit.

hugtalbot commented 6 years ago

@damienmarchal sure ? it's look like the test is still failing, isn't it ?

damienmarchal commented 6 years ago

My bad (again). I forgot to push to upstream and not origin.

hugtalbot commented 6 years ago

[ci-build]