Re: [xml] Building Python wrappers for libxml2 and libxslt under Python 2.2



On Tue, 2002-09-10 at 17:21, Daniel Veillard wrote:
On Tue, Sep 10, 2002 at 12:24:12PM -0400, Tres Seaver wrote:
On a box where libxml2 and libxslt are installed via RPM, I need to
build the Python wrappers for a Python which is *not* the system
Python.  Under Python 2.1.3, this recipe works:

  $ cd opt/libxml2-python-2.4.24
  $ ../../bin/python setup.py build install

Under Python 2.2.1, the same compile fails, because each C module tries
to include the header file, "config.h".  My guess is that the 2.1.3
builds are working (or at least appearing to) because Python's own
include directory contains a config.h;  for Python >= 2.2, that file was
renamed pyconfig.h.  In either case, the Python.h includes the
appropriate file, and so including it directly has no effect.

  Hum, right ... BTW my RPM spec file (and Red Hat ones since they are
the same :-) build libxml2-python and libxslt-python with modules
for all the python installations found at RPM generation time.

I need to use the wrappers for a Python which RPM doesn't know about (we
build a custom one in order to guarantee that it has the configuration
we need).

And 
this does not use the setup.py stuff (make rpm in the directory does it).

Is this header file supposed to be one generated by the libxml2/libxslt
configure process, rather than the Python one?  If so, how will this
configuration be available in an environment where the base packages
were compiled via RPM?  config.h is not installed into
/usr/include/libxml2, for instance.

  Possibly including <libxml/xmlversion.h> should do it.

I started to look at this again last night.

I tried building the Python wrappers via distutils after commenting out
the '#include <config.h>' lines;  the compile succeeds, which suggests
that the lines are not needed.  Can you suggest a way to test that the
wrappers are OK?  The wrapper modules import without problems.

BTW I was unable to find how to lookup/associate Include directories
from the setup.py scripts. If libxml2 is installed in /usr it's easy
to spot but otherwise one would have to run xml-config, extract the
parameter and use them from the script. And for Windows I have really
no idea how to do this.

'distutils.sysconfig' has an API, 'get_config_vars', which can tell you
where the Python configuration expects to find "system" includes:

  >>> from distutils.sysconfig import get_config_vars
  >>> get_config_vars( 'INCLUDEDIR' )
  ['/usr/include']

The PyXML package allows setting the path for the Expat parser via a
'--with-expat=' parameter to setup.py:

  for arg in args:
      if string.find(arg, '--with-libexpat=') == 0:
          LIBEXPAT = string.split(arg, '=')[1]
          sys.argv.remove(arg)

That package then passes that path through to the builder step for
the Expat wrapper module:

  expat_prefix = get_expat_prefix()

  sources = ['extensions/pyexpat.c']
  if expat_prefix:
      define_macros = [('HAVE_EXPAT_H', None)]
      include_dirs = [os.path.join(expat_prefix, "include")]
      libraries = ['expat']
      library_dirs = [os.path.join(expat_prefix, "lib")]
  # ...
    
  ext_modules.append(
      Extension(xml('.parsers.pyexpat'),
                define_macros=define_macros,
                include_dirs=include_dirs,
                library_dirs=library_dirs,
                libraries=libraries,
                extra_link_args=LDFLAGS,
                sources=sources
              ))

I think that running 'xml-config' via 'os.popen' would work:

  >>> foo = os.popen( 'xml-config --cflags' )
  >>> bar = foo.read()
  >>> print bar
  -I/usr/include/gnome-xml

Tres.
-- 
===============================================================
Tres Seaver                                tseaver zope com
Zope Corporation      "Zope Dealers"       http://www.zope.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]