[PATCH 0 of 2] Pure python fallback for base85
Brendan Cully
brendan at kublai.com
Wed Dec 31 00:47:25 CST 2008
On Tuesday, 30 December 2008 at 19:00, Brendan Cully wrote:
> This set of patches includes a pure python base85 implementation as
> well as a simple mechanism for allowing pure python fallbacks for C
> extensions. Fallbacks should call util.allowfallbacks before doing
> anything else. This function checks whether the environment variable
> HGALLOWFALLBACKS is 1, y, yes, or true and aborts with a warning if
> not.
>
> I looked into setting up fallbacks at install time instead of checking
> at run time but it seemed to require some trickier distutils hacking,
> so I'm posting this simple approach for posterity. The advantage of
> doing things at install time is no environment variable would be
> needed. On the other hand, it makes it easier for a clueless sysadmin
> to set up a slow hg without making it obvious to her users.
Here's a hack to setup.py to build fallbacks when called with a --pure
argument. I wouldn't be surprised if it missed some corner cases
though.
-------------- next part --------------
# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1230705272 28800
# Node ID 075491b14c8a1d0e44c54229a26c45a477b3be6c
# Parent acaa1a660c60aee940e749a6497b763e70d0640d
setup: install pure python when --pure is specified
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@
import tempfile
from distutils.core import setup, Extension
from distutils.command.install_data import install_data
+from distutils.command.build_py import build_py
from distutils.ccompiler import new_compiler
import mercurial.version
@@ -23,6 +24,12 @@
if os.name == 'nt':
scripts.append('contrib/win32/hg.bat')
+if sys.argv[1] == '--pure':
+ sys.argv.pop(1)
+ pureinstall = True
+else:
+ pureinstall = False
+
# simplified version of distutils.ccompiler.CCompiler.has_function
# that actually removes its temporary files.
def has_function(cc, funcname):
@@ -97,7 +104,7 @@
Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
Extension('mercurial.parsers', ['mercurial/parsers.c']),
]
-
+py_modules=[]
packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
'hgext.highlight', 'hgext.zeroconf', ]
@@ -111,7 +118,7 @@
import posix
ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
- if sys.platform == 'linux2' and os.uname()[2] > '2.6':
+ if sys.platform == 'linux2' and os.uname()[2] > '2.6' and not pureinstall:
# The inotify extension is only usable with Linux 2.6 kernels.
# You also need a reasonably recent C library.
cc = new_compiler()
@@ -122,6 +129,25 @@
except ImportError:
pass
+if pureinstall:
+ class hg_build_py(build_py):
+ def find_modules(self):
+ modules = build_py.find_modules(self)
+ newmods = []
+ for mod in modules:
+ if not mod[0].startswith('fallbacks.'):
+ newmods.append(mod)
+ continue
+ if mod[1] == '__init__':
+ continue
+ # strip 'fallbacks.' prefix
+ newmods.append((mod[0][10:], mod[1], mod[2]))
+ return newmods
+
+ cmdclass['build_py'] = hg_build_py
+ py_modules.extend(['fallbacks.' + ext.name for ext in ext_modules])
+ ext_modules = []
+
setup(name='mercurial',
version=mercurial.version.get_version(),
author='Matt Mackall',
@@ -131,6 +157,7 @@
license='GNU GPL',
scripts=scripts,
packages=packages,
+ py_modules=py_modules,
ext_modules=ext_modules,
data_files=[(os.path.join('mercurial', root),
[os.path.join(root, file_) for file_ in files])
More information about the Mercurial-devel
mailing list