Rev 2620: (John Arbash Meinel) Skip pyrex dependencies if we can't build, rather than failing in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jul 16 21:21:24 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2620
revision-id: pqm at pqm.ubuntu.com-20070716202122-hs4anrki1xzulugo
parent: pqm at pqm.ubuntu.com-20070716084122-jfjzwtbimsjv0iqv
parent: john at arbash-meinel.com-20070716181437-rrixgvv2usln0vkk
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-07-16 21:21:22 +0100
message:
  (John Arbash Meinel) Skip pyrex dependencies if we can't build, rather than failing
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
    ------------------------------------------------------------
    revno: 2617.1.4
    merged: john at arbash-meinel.com-20070716181437-rrixgvv2usln0vkk
    parent: john at arbash-meinel.com-20070715144053-09hrns6fxp9ssyj6
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: skip_pyrex
    timestamp: Mon 2007-07-16 13:14:37 -0500
    message:
      Simple NEWS entry about changes
    ------------------------------------------------------------
    revno: 2617.1.3
    merged: john at arbash-meinel.com-20070715144053-09hrns6fxp9ssyj6
    parent: john at arbash-meinel.com-20070715143330-6ddg2ay25b4pxiu1
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: skip_pyrex
    timestamp: Sun 2007-07-15 09:40:53 -0500
    message:
      Add another blank line to make it show up better
    ------------------------------------------------------------
    revno: 2617.1.2
    merged: john at arbash-meinel.com-20070715143330-6ddg2ay25b4pxiu1
    parent: john at arbash-meinel.com-20070715142444-c90zfgn3khpl1swt
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: skip_pyrex
    timestamp: Sun 2007-07-15 09:33:30 -0500
    message:
      Try another form of comment
    ------------------------------------------------------------
    revno: 2617.1.1
    merged: john at arbash-meinel.com-20070715142444-c90zfgn3khpl1swt
    parent: pqm at pqm.ubuntu.com-20070713074627-93zxs9uh528y0fki
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: skip_pyrex
    timestamp: Sun 2007-07-15 09:24:44 -0500
    message:
      Update setup.py to just skip extensions that are not available.
=== modified file 'NEWS'
--- a/NEWS	2007-07-16 08:41:22 +0000
+++ b/NEWS	2007-07-16 20:21:22 +0000
@@ -26,6 +26,10 @@
     * Merge is now faster.  Depending on the scenario, it can be more than 2x
       faster. (Aaron Bentley)
 
+    * Give a clearer warning, and allow ``python setup.py install`` to
+      succeed even if pyrex is not available.
+      (John Arbash Meinel)
+
   LIBRARY API BREAKS:
 
     * Deprecated dictionary ``bzrlib.option.SHORT_OPTIONS`` removed.

=== modified file 'setup.py'
--- a/setup.py	2007-07-13 02:23:34 +0000
+++ b/setup.py	2007-07-15 14:40:53 +0000
@@ -149,26 +149,61 @@
 
 command_classes = {'install_scripts': my_install_scripts,
                    'build': bzr_build}
+from distutils.extension import Extension
 ext_modules = []
 try:
     from Pyrex.Distutils import build_ext
 except ImportError:
+    have_pyrex = False
     # try to build the extension from the prior generated source.
-    print ("Pyrex not available, while bzr will build, "
-           "you cannot modify the C extensions.")
+    print
+    print ("The python package 'Pyrex' is not available."
+           " If the .c files are available,")
+    print ("they will be built,"
+           " but modifying the .pyx files will not rebuild them.")
+    print
     from distutils.command.build_ext import build_ext
-    from distutils.extension import Extension
-    #ext_modules.append(
-    #    Extension("bzrlib.modulename", ["bzrlib/foo.c"], libraries = []))
-    ext_modules.append(
-        Extension("bzrlib._knit_load_data_c", ["bzrlib/_knit_load_data_c.c"]))
 else:
-    from distutils.extension import Extension
-    #ext_modules.append(
-    #    Extension("bzrlib.modulename", ["bzrlib/foo.pyx"], libraries = []))
-    ext_modules.append(
-        Extension("bzrlib._knit_load_data_c", ["bzrlib/_knit_load_data_c.pyx"]))
+    have_pyrex = True
+# Override the build_ext if we have Pyrex available
 command_classes['build_ext'] = build_ext
+unavailable_files = []
+
+
+def add_pyrex_extension(module_name, **kwargs):
+    """Add a pyrex module to build.
+
+    This will use Pyrex to auto-generate the .c file if it is available.
+    Otherwise it will fall back on the .c file. If the .c file is not
+    available, it will warn, and not add anything.
+
+    You can pass any extra options to Extension through kwargs. One example is
+    'libraries = []'.
+
+    :param module_name: The python path to the module. This will be used to
+        determine the .pyx and .c files to use.
+    """
+    path = module_name.replace('.', '/')
+    pyrex_name = path + '.pyx'
+    c_name = path + '.c'
+    if have_pyrex:
+        ext_modules.append(Extension(module_name, [pyrex_name]))
+    else:
+        if not os.path.isfile(c_name):
+            unavailable_files.append(c_name)
+        else:
+            ext_modules.append(Extension(module_name, [c_name]))
+
+
+add_pyrex_extension('bzrlib._knit_load_data_c')
+
+
+if unavailable_files:
+    print 'C extension(s) not found:'
+    print '   %s' % ('\n  '.join(unavailable_files),)
+    print 'The python versions will be used instead.'
+    print
+
 
 if 'bdist_wininst' in sys.argv:
     import glob




More information about the bazaar-commits mailing list