Rev 2442: (robertc) Add the infrastructure for having C extension modules based on pyrex in bzrlib. (Robert Collins). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Apr 23 04:02:00 BST 2007


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

------------------------------------------------------------
revno: 2442
revision-id: pqm at pqm.ubuntu.com-20070423030158-cu7c1gqoom0rq2cd
parent: pqm at pqm.ubuntu.com-20070423020944-lcu3twk2zj27bw5a
parent: robertc at robertcollins.net-20070423022935-9hhongamvk6bfdso
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-04-23 04:01:58 +0100
message:
  (robertc) Add the infrastructure for having C extension modules based on pyrex in bzrlib. (Robert Collins).
modified:
  HACKING                        HACKING-20050805200004-2a5dc975d870f78c
  Makefile                       Makefile-20050805140406-d96e3498bb61c5bb
  setup.py*                      setup.py-20050314065409-02f8a0a6e3f9bc70
    ------------------------------------------------------------
    revno: 1739.1.6
    merged: robertc at robertcollins.net-20070423022935-9hhongamvk6bfdso
    parent: robertc at robertcollins.net-20070423022112-7nnzyf20z3od273b
    parent: pqm at pqm.ubuntu.com-20070423020944-lcu3twk2zj27bw5a
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Mon 2007-04-23 12:29:35 +1000
    message:
      Resolve conflicts with bzr.dev.
    ------------------------------------------------------------
    revno: 1739.1.5
    merged: robertc at robertcollins.net-20070423022112-7nnzyf20z3od273b
    parent: robertc at robertcollins.net-20070311233427-z8skxqrx8shqy1de
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Mon 2007-04-23 12:21:12 +1000
    message:
      Review feedback.
    ------------------------------------------------------------
    revno: 1739.1.4
    merged: robertc at robertcollins.net-20070311233427-z8skxqrx8shqy1de
    parent: robertc at robertcollins.net-20070308040606-84gsniv56huiyjt4
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Mon 2007-03-12 10:34:27 +1100
    message:
      Fix building of C modules without pyrex installed.
    ------------------------------------------------------------
    revno: 1739.1.3
    merged: robertc at robertcollins.net-20070308040606-84gsniv56huiyjt4
    parent: robertc at robertcollins.net-20060609141337-4ea84d88e8d4dc0f
    parent: robertc at robertcollins.net-20070307120012-cgx5yk2cob9v0i92
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Thu 2007-03-08 15:06:06 +1100
    message:
      Merge bzr.dev.
    ------------------------------------------------------------
    revno: 1739.1.2
    merged: robertc at robertcollins.net-20060609141337-4ea84d88e8d4dc0f
    parent: robertc at robertcollins.net-20060604173418-51fbd7c12775039e
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Sat 2006-06-10 00:13:37 +1000
    message:
      More pyrex finesse, documentation.
    ------------------------------------------------------------
    revno: 1739.1.1
    merged: robertc at robertcollins.net-20060604173418-51fbd7c12775039e
    parent: pqm at pqm.ubuntu.com-20060603212040-9ec7af97aa11d4d7
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: pyrex
    timestamp: Mon 2006-06-05 03:34:18 +1000
    message:
      First cut at adding pyrex facilities.
=== modified file 'HACKING'
--- a/HACKING	2007-04-18 08:39:02 +0000
+++ b/HACKING	2007-04-23 02:29:35 +0000
@@ -654,6 +654,41 @@
 so, please reply and say so.)
 
 
+C Extension Modules
+===================
+
+We write some extensions in C using pyrex. We design these to work in
+three scenarios:
+ * User with no C compiler
+ * User with C compiler
+ * Developers
+
+The recommended way to install bzr is to have a C compiler so that the
+extensions can be built, but if no C compiler is present, the pure python
+versions we supply will work, though more slowly.
+
+For developers we recommend that pyrex be installed, so that the C
+extensions can be changed if needed.
+
+For the C extensions, the extension module should always match the
+original python one in all respects (modulo speed). This should be
+maintained over time.
+
+To create an extension, add rules to setup.py for building it with pyrex,
+and with distutils. Now start with an empty .pyx file. At the top add
+"include 'yourmodule.py'". This will import the contents of foo.py into this 
+file at build time - remember that only one module will be loaded at
+runtime. Now you can subclass classes, or replace functions, and only your
+changes need to be present in the .pyx file.
+
+Note that pyrex does not support all 2.4 programming idioms, so some
+syntax changes may be required. I.e. 
+ - 'from foo import (bar, gam)' needs to change to not use the brackets. 
+ - 'import foo.bar as bar' needs to be 'import foo.bar; bar = foo.bar' 
+If the changes are too dramatic, consider
+maintaining the python code twice - once in the .pyx, and once in the .py,
+and no longer including the .py file.
+
 Making installers for OS Windows
 ================================
 To build a win32 installer, see the instructions on the wiki page:

=== modified file 'Makefile'
--- a/Makefile	2007-04-19 22:03:15 +0000
+++ b/Makefile	2007-04-23 02:29:35 +0000
@@ -17,12 +17,15 @@
 # A relatively simple Makefile to assist in building parts of bzr. Mostly for
 # building documentation, etc.
 
-.PHONY: all clean pyflakes api-docs
-
-
-all:
-
-check:
+.PHONY: all clean extensions pyflakes api-docs
+
+all: extensions
+
+extensions:
+	@echo "building extension modules."
+	./setup.py build_ext -i
+
+check: extensions
 	python -Werror ./bzr selftest -v $(tests)
 	@echo "Running all tests with no locale."
 	LC_CTYPE= LANG=C LC_ALL= ./bzr selftest -v $(tests)

=== modified file 'setup.py' (properties changed)
--- a/setup.py	2007-01-30 12:13:18 +0000
+++ b/setup.py	2007-03-11 23:34:27 +0000
@@ -147,6 +147,25 @@
 ## Setup
 ########################
 
+command_classes = {'install_scripts': my_install_scripts,
+                  'build': bzr_build}
+ext_modules = []
+try:
+    from Pyrex.Distutils import build_ext
+except ImportError:
+    # try to build the extension from the prior generated source.
+    print ("Pyrex not available, while bzr will build, "
+           "you cannot modify the C extensions.")
+    from distutils.command.build_ext import build_ext
+    from distutils.extension import Extension
+    #ext_modules.append(
+    #    Extension("bzrlib.modulename", ["bzrlib/foo.c"], libraries = []))
+else:
+    from distutils.extension import Extension
+    #ext_modules.append(
+    #    Extension("bzrlib.modulename", ["bzrlib/foo.pyx"], libraries = []))
+command_classes['build_ext'] = build_ext
+
 if 'bdist_wininst' in sys.argv:
     import glob
     # doc files
@@ -218,9 +237,8 @@
     # std setup
     ARGS = {'scripts': ['bzr'],
             'data_files': [('man/man1', ['bzr.1'])],
-            'cmdclass': {'build': bzr_build,
-                         'install_scripts': my_install_scripts,
-                        },
+            'cmdclass': command_classes,
+            'ext_modules': ext_modules,
            }
     
     ARGS.update(META_INFO)




More information about the bazaar-commits mailing list