From 9e68316bc8bd721c8058bbde79bc59d28bc1a843 Mon Sep 17 00:00:00 2001 From: scoder Date: Fri, 31 Aug 2007 19:01:53 +0200 Subject: [PATCH] [svn r2800] switch to Cython completely, currently requires fake Pyrex to satisfy setuptools --HG-- branch : trunk --- MANIFEST.in | 1 + fake_pyrex/Pyrex/Distutils/__init__.py | 1 + fake_pyrex/Pyrex/Distutils/build_ext.py | 1 + fake_pyrex/Pyrex/__init__.py | 1 + setup.py | 26 +++++++++++++++---------- setupinfo.py | 20 ++++++------------- 6 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 fake_pyrex/Pyrex/Distutils/__init__.py create mode 100644 fake_pyrex/Pyrex/Distutils/build_ext.py create mode 100644 fake_pyrex/Pyrex/__init__.py diff --git a/MANIFEST.in b/MANIFEST.in index 200332ada..8fb12e610 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -9,5 +9,6 @@ recursive-include src/lxml etree.c objectify.c pyclasslookup.c etree.h etree_def recursive-include src/lxml/tests *.rng *.xslt *.xml *.dtd recursive-include benchmark *.py recursive-include doc *.txt *.html *.css *.xml *.mgp pubkey.asc tagpython.png +recursive-include fake_pyrex *.py include doc/mkhtml.py doc/rest2html.py exclude doc/pyrex.txt src/lxml/etree.pxi diff --git a/fake_pyrex/Pyrex/Distutils/__init__.py b/fake_pyrex/Pyrex/Distutils/__init__.py new file mode 100644 index 000000000..51c8e16b8 --- /dev/null +++ b/fake_pyrex/Pyrex/Distutils/__init__.py @@ -0,0 +1 @@ +# work around broken setuptools monkey patching diff --git a/fake_pyrex/Pyrex/Distutils/build_ext.py b/fake_pyrex/Pyrex/Distutils/build_ext.py new file mode 100644 index 000000000..4f846f628 --- /dev/null +++ b/fake_pyrex/Pyrex/Distutils/build_ext.py @@ -0,0 +1 @@ +build_ext = "yes, it's there!" diff --git a/fake_pyrex/Pyrex/__init__.py b/fake_pyrex/Pyrex/__init__.py new file mode 100644 index 000000000..51c8e16b8 --- /dev/null +++ b/fake_pyrex/Pyrex/__init__.py @@ -0,0 +1 @@ +# work around broken setuptools monkey patching diff --git a/setup.py b/setup.py index c0b078aaa..5c5578e1d 100644 --- a/setup.py +++ b/setup.py @@ -1,25 +1,28 @@ import sys, os +extra_options = {} + +try: + import Cython + # may need to work around setuptools bug by providing a fake Pyrex + sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fake_pyrex")) +except ImportError: + pass + try: import pkg_resources try: pkg_resources.require("setuptools>=0.6c5") - except pkg_resources.VersionConflict, e: + except pkg_resources.VersionConflict: from ez_setup import use_setuptools use_setuptools(version="0.6c5") #pkg_resources.require("Cython==0.9.6.5") from setuptools import setup + extra_options["zip_safe"] = False except ImportError: # no setuptools installed from distutils.core import setup -try: - import Cython -except ImportError: - # need to insert this to python path so we're sure we can import versioninfo, - # setupinfo and Cython/Pyrex (!) even if we start setup.py from another location - # (such as a buildout) - sys.path.insert(0, os.path.dirname(__file__)) import versioninfo import setupinfo @@ -31,11 +34,15 @@ STATIC_LIBRARY_DIRS = [] STATIC_CFLAGS = [] + # create lxml-version.h file svn_version = versioninfo.svn_version() versioninfo.create_version_h(svn_version) print "Building lxml version", svn_version + +extra_options.update(setupinfo.extra_setup_args()) + setup( name = "lxml", version = versioninfo.version(), @@ -86,8 +93,7 @@ package_dir = {'': 'src'}, packages = ['lxml', 'lxml.html'], - zip_safe = False, ext_modules = setupinfo.ext_modules( STATIC_INCLUDE_DIRS, STATIC_LIBRARY_DIRS, STATIC_CFLAGS), - **setupinfo.extra_setup_args() + **extra_options ) diff --git a/setupinfo.py b/setupinfo.py index f149eecd8..a583e76c4 100644 --- a/setupinfo.py +++ b/setupinfo.py @@ -1,20 +1,12 @@ import sys, os -try: - from setuptools.extension import Extension -except ImportError: - from distutils.extension import Extension +from distutils.core import Extension try: from Cython.Distutils import build_ext as build_pyx print "Building with Cython." - PYREX_INSTALLED = True + CYTHON_INSTALLED = True except ImportError: - try: - from Pyrex.Distutils import build_ext as build_pyx - print "Trying to build with Pyrex." - PYREX_INSTALLED = True - except ImportError: - PYREX_INSTALLED = False + CYTHON_INSTALLED = False EXT_MODULES = [ ("etree", "lxml.etree"), @@ -27,10 +19,10 @@ def env_var(name): return value.split(os.pathsep) def ext_modules(static_include_dirs, static_library_dirs, static_cflags): - if PYREX_INSTALLED: + if CYTHON_INSTALLED: source_extension = ".pyx" else: - print ("NOTE: Trying to build without Pyrex, pre-generated " + print ("NOTE: Trying to build without Cython, pre-generated " "'src/lxml/etree.c' needs to be available.") source_extension = ".c" @@ -67,7 +59,7 @@ def ext_modules(static_include_dirs, static_library_dirs, static_cflags): def extra_setup_args(): result = {} - if PYREX_INSTALLED: + if CYTHON_INSTALLED: result['cmdclass'] = {'build_ext': build_pyx} return result