On Sun, Jun 07, 2015 at 01:47:10AM +0800, Huang, Nan wrote:
> Hi, Dave,
> 
> Thanks for your reply.
> 
> Sorry, I think I might not be quite specific in describing the issue I
> encountered.
> 
> Actually, I mean, in the below xsd:
> 
>     <xs:complexType name="TEntityType">
>         <xs:sequence>
>           <xs:element name="Documentation" type="edm:TDocumentation"
>     minOccurs="0" maxOccurs="1" />
>           <xs:element name="Key" type="edm:TEntityKeyElement"
>     minOccurs="0" maxOccurs="1" />      <xs:choice minOccurs="0"
>     maxOccurs="unbounded">
>             <xs:element name="Property" type="edm:TEntityProperty"
>     minOccurs="0" maxOccurs="unbounded" />
>             <xs:element name="NavigationProperty"
>     type="edm:TNavigationProperty" minOccurs="0" maxOccurs="unbounded" />
>           </xs:choice>
>           <xs:any namespace="##other" processContents="lax" minOccurs="0"
>     maxOccurs="unbounded" />
>         </xs:sequence>
>         <xs:attributeGroup ref="edm:TDerivableTypeAttributes" />
>         <xs:attribute ref="cg:TypeAccess" use="optional" />
>         <xs:anyAttribute namespace="##other" processContents="lax" />
>       </xs:complexType>
> 
> For TEntityType python class, the corresponding python class code should
> have a get_NavigationProperty(self) method generated, as what is has done
> for get_Property(self) method, but it isn't the case.
> 
> I confirm that the class for TNavigationProperty is well generated in my
> output python code.
> 
> The below is the code generated for TEntityType , use can see that
> get_NavigationProperty(self) methos is missing:

Nan,

Thanks for your explanation.  That makes clear what the problem is.
Yes, in your generated code class TEntityType is missing methods
get_NavigationProperty and set_NavigationProperty.

However, in the code I generate, both of those methods are present.
I've generated code with both csdl_1.0.xsd and csdl_3.0.xsd.  In
both cases, class TEntityType contains methods
get_NavigationProperty and set_NavigationProperty.

In a separate message (so as not to fill the mail boxes of other
list members), I've attached generated files tmp04sup.py (generated
from csdl_1.0.xsd) and tmp05sup.py (generated from csdl_3.0.xsd).
You can look near the top of the file to find a comment that shows
the command line and arguments used to generate the file.  I've also
included the schema files I used.

So, we have to figure out what is different on your end so that your
results (generated code) is different from mine.

Some possible differences:

- I might be using a different version of generateDS.py.  You can
  try the version at Bitbucket, which should be the same as mine.

- I might be using different command line options when I run
  generateDS.py.  You can look at the top of the generated file to
  see the options and command line that was used to generate it.

- I might be using a different version of the CSDL schema.  I've
  attached the schema files I'm using so that you can compare with
  yours.  If I am using a different version of the schema, could you
  please attach and email yours back to me.  Then I'll run another
  test.  By the way, I've tried this with both csdl_1.0.xsd and
  csdl_3.0.xsd.  With both of these versions of the schema, class
  TEntityType contains get_NavigationProperty and
  set_NavigationProperty.

  It's also possible that the version of the file imported by the
  csdl schema is different, although it seems unlikely that this
  would make a difference, since the definition of TEntityType is in
  the main schema file.  I've also attached those imported schema
  files.

Or, is there *still* something I'm missing here?  I apologize in
advance if I'm slow or dense.

And, a few more notes about the requirement that users must install
Lxml:

1. Lxml can be installed with the command "pip install lxml", which
   I've tested on both Linux and MS Windows.  So, for any users that
   have pip installed, installing Lxml really is very easy.  If they
   don't have pip, they probably should have, and installing it from
   pypi.python.org is also easy.

2. In response to your question, I've been trying to use PyInstaller
   (see https://pypi.python.org/pypi/PyInstaller/2.1) to bundle the
   module generated by generateDS.py and the modules required to run
   it into a single file.  I've had trouble so far with some
   undefined items.  But, if I can figure that out, perhaps it would
   enable you to create and ship a single file that could be run
   without the need to install Lxml or any other Python modules that
   are not in the Python standard library.  If you have had any
   experience with PyInstaller, let me know.  And, I'll be sure to
   report back, if and when I make progress with this.

Dave

> 
>     class TEntityType(GeneratedsSuper):
>         subclass = None
>         superclass = None
>         def __init__(self, Name=None, Documentation=None, Key=None,
>     Property=None, anytypeobjs_=None):
>             self.original_tagname_ = None
>             self.Name = _cast(None, Name)
>             self.Documentation = Documentation
>             self.Key = Key
>             if Property is None:
>                 self.Property = []
>             else:
>                 self.Property = Property
>             if anytypeobjs_ is None:
>                 self.anytypeobjs_ = []
>             else:
>                 self.anytypeobjs_ = anytypeobjs_
>             self.anyAttributes_ = {}
>         def factory(*args_, **kwargs_):
>             if TEntityType.subclass:
>                 return TEntityType.subclass(*args_, **kwargs_)
>             else:
>                 return TEntityType(*args_, **kwargs_)
>         factory = staticmethod(factory)
>         def get_Documentation(self): return self.Documentation
>         def set_Documentation(self, Documentation): self.Documentation = 
> Documentation
>         def get_Key(self): return self.Key
>         def set_Key(self, Key): self.Key = Key
>         def get_Property(self): return self.Property
>         def set_Property(self, Property): self.Property = Property
>         def add_Property(self, value): self.Property.append(value)
>         def insert_Property_at(self, index, value): 
> self.Property.insert(index,
>     value)
>         def replace_Property_at(self, index, value): self.Property[index] = 
> value
>         def get_anytypeobjs_(self): return self.anytypeobjs_
>         def set_anytypeobjs_(self, anytypeobjs_): self.anytypeobjs_ = 
> anytypeobjs_
>         def add_anytypeobjs_(self, value): self.anytypeobjs_.append(value)
>         def insert_anytypeobjs_(self, index, value): 
> self._anytypeobjs_[index] = value
>         def get_Name(self): return self.Name
>         def set_Name(self, Name): self.Name = Name
>         def get_anyAttributes_(self): return self.anyAttributes_
>         def set_anyAttributes_(self, anyAttributes_): self.anyAttributes_ = 
> anyAttributes_
> 
> Regards
> 
> Nan
> 
> 
> On Fri, Jun 5, 2015 at 2:35 AM, Dave Kuhlman <dkuhl...@davekuhlman.org>
> wrote:
> 
> > On Tue, Jun 02, 2015 at 11:36:19PM +0800, Huang, Nan wrote:
> > > Today I tried to work with generatedDS for my OData related project, we
> > > have a XSD file in hands, and tried to generated the corresponding python
> > > model for it, but we encountered an issue regarding a missing element in
> > > the generated python code. We tried with the latest 2.16a0, and older
> > ones,
> > > 2.14a, 2,4c, all of them have the same issue.
> > >
> > > The XSD we tried to use is here:
> > > https://msdn.microsoft.com/en-us/library/hh879817.aspx
> > >
> > > You can see that in this xsd, there is a section:
> > >
> > > <xs:complexType name="TEntityType">
> > >     <xs:sequence>
> > >       <xs:element name="Documentation" type="edm:TDocumentation"
> > > minOccurs="0" maxOccurs="1" />
> > >       <xs:element name="Key" type="edm:TEntityKeyElement"
> > > minOccurs="0" maxOccurs="1" />      <xs:choice minOccurs="0"
> > > maxOccurs="unbounded">
> > >         <xs:element name="Property" type="edm:TEntityProperty"
> > > minOccurs="0" maxOccurs="unbounded" />
> > >         <xs:element name="NavigationProperty"
> > > type="edm:TNavigationProperty" minOccurs="0" maxOccurs="unbounded" />
> > >       </xs:choice>
> > >       <xs:any namespace="##other" processContents="lax" minOccurs="0"
> > > maxOccurs="unbounded" />
> > >     </xs:sequence>
> > >     <xs:attributeGroup ref="edm:TDerivableTypeAttributes" />
> > >     <xs:attribute ref="cg:TypeAccess" use="optional" />
> > >     <xs:anyAttribute namespace="##other" processContents="lax" />
> > >   </xs:complexType>
> > >
> > > In the <xs:choice> element, there are two sub-elements, Property and
> > > NavigationProperty. But in the generated code, we found only Property
> > > under TEntityType, no NavigationProperty.
> >
> > Nan Huang,
> >
> > Thanks for your report.  Your description of the problem was very
> > helpful in trying to reproduce the problem.
> >
> > I've generated code using the XML schema you referred to.  I also
> > searched for, found, and downloaded a schema imported by that one.
> > The schemas I'm using are at these locations:
> >
> > - https://msdn.microsoft.com/en-us/library/hh879817.aspx
> > -
> > https://code.google.com/p/edmx/source/browse/trunk/Source/Edmx/Schema/System.Data.Resources.CodeGenerationSchema.xsd
> >
> > I've attached those schemas to this message in case you want to
> > compare them with yours.
> >
> > The code I generated contains definitions of classes TEntityProperty
> > and TNavigationProperty.  And in method buildChildren in class
> > TEntityType, it builds Property as an instance of class
> > TEntityProperty and it builds NavigationProperty as an instance of
> > class TNavigationProperty.  It also looks like they are both being
> > exported in method exportChildren of class TEntityType.
> >
> > That all seems correct to me.
> >
> > So, which is the piece that is missing?
> >
> > I've attached the file that I generated (tmp01sup.py) so that you
> > can check to see whether it contains something that is missing in
> > that files that you generate.
> >
> > You can look at the top of that generated file to see the command
> > line and options that I used to generate this file.  I also tried it
> > with other/fewer options and got similar results.
> >
> > I appologize for being a bit slow to see this problem.  Perhaps you
> > can tell me more specifically what is missing.
> >
> > I'm using generateDS.py 2.16a.  That's the same as 2.16a0.  For some
> > reason, setuptools (or whatever it is) added the zero when I
> > uploaded that version to the Python Package Index.
> >
> > >
> > > Is this a bug or we miss-used the library? We simply used the -o
> > > option in your tutorial.
> > >
> > > BTW, in recent version, we only support lxml instead of both lxml and
> > > ET in generated code, this is a bit inconvenient as lxml is platform
> > > dependent and need native library, and we cannot continue to have a
> > > single pure python dist for all platforms.
> >
> > As I recall, I had problems with ElementTree at one point.  It had
> > something to do with namespaces and namespace prefixes in
> > process_includes.py (which is imported by generateDS.py.  My belief
> > is that ElementTree is pretty strong in its support of namespaces,
> > so we can wonder about whether that was my mistake.
> >
> > It is possible, maybe even likely, that you can patch the generated
> > file so that it uses ElementTree instead of Lxml.  You could even
> > patch generateDS.py itself so that it produces files that use
> > ElementTree instead of Lxml.  It would require changing just a few
> > lines of boiler plate, after all.  Here is a diff that will give you
> > an idea of what to change:
> >
> >     --- tmp26sup.py 2015-06-04 11:15:02.236588923 -0700
> >     +++ test01.py   2015-06-04 11:17:36.094327799 -0700
> >     @@ -31,18 +31,14 @@
> >      import base64
> >      import datetime as datetime_
> >      import warnings as warnings_
> >     -from lxml import etree as etree_
> >     +from xml.etree import ElementTree as etree_
> >
> >
> >      Validate_simpletypes_ = True
> >
> >
> >      def parsexml_(infile, parser=None, **kwargs):
> >     -    if parser is None:
> >     -        # Use the lxml ElementTree compatible parser so that, e.g.,
> >     -        #   we ignore comments.
> >     -        parser = etree_.ETCompatXMLParser()
> >     -    doc = etree_.parse(infile, parser=parser, **kwargs)
> >     +    doc = etree_.parse(infile, **kwargs)
> >          return doc
> >
> > There may be features that require Lxml in the generated code.  But,
> > if your use case does not use those features, ElementTree might work
> > for you.  You will have to do testing yourself to find out.
> >
> > If that works, at least your users will not need to install Lxml,
> > even though you (or whoever generates the code) will still need
> > Lxml.
> >
> > Hope this helps.
> >
> > Dave
> >
> > >
> > > Regards
> > >
> > > Nan Huang
> >
> > --
> >
> > Dave Kuhlman
> > http://www.davekuhlman.org
> >

-- 

Dave Kuhlman
http://www.davekuhlman.org

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

Reply via email to