poppopjmp / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

option to only generate C++ stubs #86

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
For those who want to custom-implement the C++ routines corresponding to python 
code, and just want to keep the same general structure / interfaces that are in 
the python module, it would be great if shedskin could parse a python file for 
classes / methods / etc., and then generate an equivalent C++ file containing 
C++ classes and method stubs using whatever naming convention the user chooses.

For python modules which depend a lot on external libraries, but need to be 
translated to C++, this would save a lot of initial time, by converting 
everything to C++ classes/stubs.

Original issue reported on code.google.com by edgi...@gmail.com on 8 Jul 2010 at 4:11

GoogleCodeExporter commented 8 years ago
thanks for the suggestion. I have to say this looks a bit like a special-case, 
and I'm not sure I'd be interested in adding complexity for this..

Original comment by mark.duf...@gmail.com on 9 Jul 2010 at 8:40

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 9 Jul 2010 at 3:25

GoogleCodeExporter commented 8 years ago
As an alternative to adding this feature into shedskin's parser, one could 
create a copy of the code and replace all the function/method code with 'pass' 
and shedskin that.

Making that automatic wouldn't be very hard, but removing the code done in a 
class's declaration would require human interaction in many cases to replace, 
say, "model_name = settings.MODEL_NAME" with "model_name = ''" or similar cases.

Original comment by fahh...@gmail.com on 3 Oct 2010 at 10:39

GoogleCodeExporter commented 8 years ago
I'm afraid type inference will not work very well for such 'partial' code. for 
example, if all calls to some function disappear, there's not enough 
information to analyze its signature..

Original comment by mark.duf...@gmail.com on 4 Oct 2010 at 8:09

GoogleCodeExporter commented 8 years ago
That's true, what I've been doing is move all calls and their context into the 
__main__ portion and have the function set defaults to its args and return 
something like it normally would, like so:

#Original code
def read_file(filename='pos.csv'):
    data = open(filename)
    # infering...
    ox=oy=oz = [0.,0.,0.]
    lx=ly=lz = '1'
    line = ''

    ox,oy,oz = [],[],[]
    while True:
        line = data.readline()
        if line == '': break # only if EOF hit immediately
        try:
            lx,ly,lz = line.strip().split(' ')
        except: continue # empty line
        ox.append(float(lx))
        oy.append(float(ly))
        oz.append(float(lz))
    return ox,oy,oz

#'Stub' Code
def read_file(filename='pos.csv'):
    ox=oy=oz = [0.,0.,0.]
    return ox,oy,oz

if __name__=='__main__':
    posx,posy,posz = read_file('pos.csv')

Yes, there are some type-hints I provided to speed up shedskin.

Original comment by fahh...@gmail.com on 16 Oct 2010 at 4:06

GoogleCodeExporter commented 8 years ago
I guess there's not much difference between the original and stubbed code when 
one just wants C++ stubs: one still has to remove generated fake code, and the 
generated code is still quite ugly and can't be influenced.. 

Original comment by mark.duf...@gmail.com on 18 Oct 2010 at 2:25

GoogleCodeExporter commented 8 years ago
I appreciate the issue, but I think I will close it. I like shedskin to have a 
lot of focus, because it's a complicated and still experimental project, with 
only one active contributor. I also think we should focus on trying to avoid 
the need for manual C++ completely, rather than aiding it.. ;-) but thanks 
again for the suggestion.

Original comment by mark.duf...@gmail.com on 27 Oct 2010 at 1:51