Mercurial > hg
changeset 28430:17b85d739b62
setup: create a module for the modulepolicy
Instead of rewriting __init__ to define the modulepolicy,
write out a __modulepolicy__.py file like __version__.py
This should work for both system-wide installation and in-place build. Therefore
we can avoid relying on two separate modulepolicy rules, '@MODULELOADPOLICY@'
and 'mercurial/modulepolicy'.
author | timeless <timeless@mozdev.org> |
---|---|
date | Wed, 09 Mar 2016 15:47:01 +0000 |
parents | a47881680402 |
children | a7e3b72cf756 |
files | .hgignore Makefile mercurial/__init__.py setup.py |
diffstat | 4 files changed, 18 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed Mar 09 08:08:27 2016 -0800 +++ b/.hgignore Wed Mar 09 15:47:01 2016 +0000 @@ -40,6 +40,7 @@ MANIFEST MANIFEST.in patches +mercurial/__modulepolicy__.py mercurial/__version__.py mercurial/hgpythonlib.h mercurial.egg-info
--- a/Makefile Wed Mar 09 08:08:27 2016 -0800 +++ b/Makefile Wed Mar 09 15:47:01 2016 +0000 @@ -63,6 +63,7 @@ \( -name '*.py[cdo]' -o -name '*.so' \) -exec rm -f '{}' ';' rm -f $(addprefix mercurial/,$(notdir $(wildcard mercurial/pure/[a-z]*.py))) rm -f MANIFEST MANIFEST.in hgext/__index__.py tests/*.err + rm -f mercurial/__modulepolicy__.py if test -d .hg; then rm -f mercurial/__version__.py; fi rm -rf build mercurial/locale $(MAKE) -C doc clean
--- a/mercurial/__init__.py Wed Mar 09 08:08:27 2016 -0800 +++ b/mercurial/__init__.py Wed Mar 09 15:47:01 2016 +0000 @@ -19,11 +19,14 @@ # c - require C extensions # allow - allow pure Python implementation when C loading fails # py - only load pure Python modules -modulepolicy = '@MODULELOADPOLICY@' - +# # By default, require the C extensions for performance reasons. -if modulepolicy == '@' 'MODULELOADPOLICY' '@': - modulepolicy = 'c' +modulepolicy = 'c' +try: + from . import __modulepolicy__ + modulepolicy = __modulepolicy__.modulepolicy +except ImportError: + pass # PyPy doesn't load C extensions. #
--- a/setup.py Wed Mar 09 08:08:27 2016 -0800 +++ b/setup.py Wed Mar 09 15:47:01 2016 +0000 @@ -314,21 +314,16 @@ raise SystemExit('Python headers are required to build ' 'Mercurial but weren\'t found in %s' % h) - def copy_file(self, *args, **kwargs): - dst, copied = build_py.copy_file(self, *args, **kwargs) + def run(self): + if self.distribution.pure: + modulepolicy = 'py' + else: + modulepolicy = 'c' + with open("mercurial/__modulepolicy__.py", "w") as f: + f.write('# this file is autogenerated by setup.py\n') + f.write('modulepolicy = "%s"\n' % modulepolicy) - if copied and dst.endswith('__init__.py'): - if self.distribution.pure: - modulepolicy = 'py' - else: - modulepolicy = 'c' - content = open(dst, 'rb').read() - content = content.replace(b'@MODULELOADPOLICY@', - modulepolicy.encode(libdir_escape)) - with open(dst, 'wb') as fh: - fh.write(content) - - return dst, copied + build_py.run(self) class buildhgextindex(Command): description = 'generate prebuilt index of hgext (for frozen package)'