Comments
Patch
@@ -27,4 +27,37 @@ if libdir != '@' 'LIBDIR' '@':
sys.path.insert(0, libdir)
+# {{{ remove-from-release:auto-build
+# to make developers' life easier, build outdated C modules automatically.
+try:
+ from mercurial import _dualmodules, modulepolicy
+except ImportError:
+ pass
+else:
+ if (modulepolicy == b'c' and
+ os.environ.get('HGDEVAUTOBUILD', '') != 'disable'):
+ try:
+ # test if C modules are use-able
+ for name in _dualmodules:
+ __import__(name)
+ except ImportError as ex:
+ # try rebuild them automatically
+ import subprocess
+ failed = False
+ wd = os.path.dirname(os.path.realpath(__file__))
+ try:
+ cmd = [sys.executable, 'setup.py', 'build_ext', '-i']
+ null = open(os.devnull, 'r+')
+ subprocess.check_call(cmd, cwd=wd, stdin=null, stdout=null,
+ stderr=null)
+ except Exception:
+ failed = True
+ # be friendly - tell people how to fix it
+ sys.stderr.write('abort: cannot find or build compatible C '
+ 'modules\n'
+ '(hint: run "make local" to build manually, '
+ 'or set HGMODULEPOLICY to "allow")\n')
+ raise ex
+# remove-from-release:auto-build }}}
+
# enable importing on demand to reduce startup time
try:
@@ -555,4 +555,9 @@ class hginstallscripts(install_scripts):
continue
+ # remove "remove-from-release" blocks
+ data = re.sub('\n# {{{ remove-from-release:([^\n]*).*'
+ '# remove-from-release:\\1 }}}\n', '',
+ data, flags=re.DOTALL)
+
# During local installs, the shebang will be rewritten to the final
# install path. During wheel packaging, the shebang has a special
@@ -561,7 +566,7 @@ class hginstallscripts(install_scripts):
log.info('not rewriting @LIBDIR@ in %s because install path '
'not known' % outfile)
- continue
+ else:
+ data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
- data = data.replace(b'@LIBDIR@', libdir.encode(libdir_escape))
with open(outfile, 'wb') as fp:
fp.write(data)