Many thanks for your answers. I had a look into the code after asking and came to the same conclusion: we would have to modify generateGettersAndSetters (maybe combined with --user-method).

I will try to add it as an option (pre/post-processing for setters), so it can be integrated in your next version if wanted.

I never used bitbucket before but I suppose it is similar to git (which I use). So yes, I think we could manage it.

It would be great if you came to a solution with the parent reference, let me know, otherwise I think I could manage something by my self (i.e. assign the parent variable in setters).


Another question by the way, is there a reason class checkers (isinstance) in setters or cast is not use in setters (only in constructor)?

Cheers

Florian



On 09/10/2018 23:09, Dave Kuhlman wrote:
Florian,

Good to hear from you.  Glad to that generateDS has been useful.

- is there a way to customize setters/adders/constructor?
Take a look at function `generateGettersAndSetters` in file
`generateDS.py`.  It should be reasonably easy to patch that so as
to get the results you want.  Actually, I've attached a patch which
should get you part way there.  Apply that patch file to
`generateDS.py` (using the `patch` program), then look at the 4
places where there is the comment "# add custom code here".
The patch file, by the way, is a diff from version 2.29.25 from
Bitbucket (https://bitbucket.org/dkuhlman/generateds).

The problem with doing that is that then you have a fork.  And, so,
when I release a new version, you'd have to worry about migrating
your changes to the new version.

One, strategy that might help with this problem of preserving your
changes would be to clone the generateDS repository from Bitbucket
using Mercurial:

     $ hg clone https://bitbucket.org/dkuhlman/generateds

Then, whenever there is a new version, instead of downloading a
release file or installing from `pypi.python.org`, you could update your
repository with the following:

     $ cd generateds
     $ hg pull
     $ hg up

And, unless I had made changes in the specific area where you made
*your* change, you'd likely be good.

What do you think?  Would that work for you.

It adds a little bulk, but the `pass` statements disappear, I
believe, at runtime.

Another alternative is to add another method to the class
`GeneratedsSuper`, which is the superclass of all the generated data
binding classes, then have the getter and setter methods call that.

Do you have an opinion or suggestion on this?

- is there a way to add a "parent" attribute to each class that would
reference the parent object?
Let me think on this one for a bit.  It seems like a good
suggestion.  When I use Lxml, I've sometimes had need of a reference
to the parent of a node, which Lxml provides, but ElementTree (which
Lxml mimics) does not.  So, you'd think I'd have thought of that.
Just a little slow, I guess.

We could hard-wire the generation of that specific behavior into
`generateDS.py`.  Possibly, the build method that it generates in
each data binding class could create an instance variable holding a
reference to the parent.  But, I'm wondering if there might be some
way to do something more generic and flexible so that others could
solve other problems and use it for other purposes, as well.  And,
I'm *still* looking for a use case for Python descriptors.

Give me a day or so.

Dave

On Tue, Oct 09, 2018 at 05:22:41PM +0200, Florian de Boissieu wrote:
Dear M. Kuhman,

I am trying to use your package generateDS. All is good except a few things
that I couldn't manage:

- is there a way to customize setters/adders/constructor? As an example, I
would like, at the end of each setter, a call to an "update" function
defined externally following a template.

- is there a way to add a "parent" attribute to each class that would
reference the parent object?

Many thanks for this package that is very useful.

Best regards

Florian


--
Florian de Boissieu
Ph.D. in Signal Processing
Post-doc in Remote Sensing of Environment

UMR TETIS, Maison de la Télédétection
500 rue Jean-François Breton, 34000 Montpellier

e-mail: florian.de-boiss...@teledetection.fr
tel: 04.67.54.87.29   mob: 06.25.92.16.09


--
Florian de Boissieu
Ph.D. in Signal Processing
Post-doc in Remote Sensing of Environment

UMR TETIS, Maison de la Télédétection
500 rue Jean-François Breton, 34000 Montpellier

e-mail: florian.de-boiss...@teledetection.fr
tel: 04.67.54.87.29   mob: 06.25.92.16.09



_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to