evolve: move extension metadata in their own module
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 07 Mar 2017 13:24:07 +0100
changeset 2049 b81d3775006b
parent 2048 05e91ba0a7a9
child 2050 604ecce27969
evolve: move extension metadata in their own module This will allow the server only extension to reuse them. As a side effect we can now simplify the config parsing in setup.py
hgext3rd/evolve/__init__.py
hgext3rd/evolve/metadata.py
setup.cfg
setup.py
--- a/hgext3rd/evolve/__init__.py	Tue Mar 07 13:12:27 2017 +0100
+++ b/hgext3rd/evolve/__init__.py	Tue Mar 07 13:24:07 2017 +0100
@@ -17,11 +17,7 @@
       this feature,
     - improves some aspect of the early implementation in Mercurial core
 """
-__version__ = '5.6.0'
-testedwith = '3.8.4 3.9.2 4.0.2 4.1'
-minimumhgversion = '3.8'
-
-buglink = 'https://bz.mercurial-scm.org/'
+
 
 evolutionhelptext = """
 Obsolescence markers make it possible to mark changesets that have been
@@ -78,8 +74,9 @@
     from mercurial import registrar
     registrar.templatekeyword # new in hg-3.8
 except ImportError:
+    from . import metadata
     raise ImportError('evolve needs version %s or above' %
-                      min(testedwith.split()))
+                      min(metadata.testedwith.split()))
 
 import mercurial
 from mercurial import util
@@ -116,10 +113,15 @@
 from . import (
     exchange,
     exthelper,
+    metadata,
     serveronly,
     utility,
 )
 
+__version__ = metadata.__version__
+testedwith = metadata.testedwith
+minimumhgversion = metadata.minimumhgversion
+buglink = metadata.buglink
 
 sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/metadata.py	Tue Mar 07 13:24:07 2017 +0100
@@ -0,0 +1,11 @@
+# define Mercurial extension metadata for evolution
+#
+# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+__version__ = '5.6.0'
+testedwith = '3.8.4 3.9.2 4.0.2 4.1'
+minimumhgversion = '3.8'
+buglink = 'https://bz.mercurial-scm.org/'
--- a/setup.cfg	Tue Mar 07 13:12:27 2017 +0100
+++ b/setup.cfg	Tue Mar 07 13:24:07 2017 +0100
@@ -24,5 +24,5 @@
          N801,
          # line break occurred before a binary operator
          W503
-builtins=xrange
+builtins=xrange, execfile
 
--- a/setup.py	Tue Mar 07 13:12:27 2017 +0100
+++ b/setup.py	Tue Mar 07 13:24:07 2017 +0100
@@ -2,25 +2,21 @@
 from distutils.core import setup
 from os.path import dirname, join
 
-def get_version(relpath):
-    '''Read version info from a file without importing it'''
-    for line in open(join(dirname(__file__), relpath), 'rb'):
-        # Decode to a fail-safe string for PY3
-        # (gives unicode object in PY2)
-        line = line.decode('utf8')
-        if '__version__' in line:
-            if "'" in line:
-                return line.split("'")[1]
+META_PATH = 'hgext3rd/evolve/metadata.py'
+
+def get_metadata():
+    meta = {}
+    fullpath = join(dirname(__file__), META_PATH)
+    execfile(fullpath, meta)
+    return meta
 
-def min_hg_version(relpath):
+def get_version():
     '''Read version info from a file without importing it'''
-    for line in open(join(dirname(__file__), relpath), 'rb'):
-        # Decode to a fail-safe string for PY3
-        # (gives unicode object in PY2)
-        line = line.decode('utf8')
-        if 'testedwith' in line:
-            if "'" in line:
-                return min(line.split("'")[1].split())
+    return get_metadata()['__version__']
+
+def min_hg_version():
+    '''Read version info from a file without importing it'''
+    return get_metadata()['minimumhgversion']
 
 py_modules = [
     'hgext3rd.evolve.serveronly',
@@ -34,19 +30,16 @@
     py_modules.append('hgext3rd.evolve.hack.inhibit')
     py_modules.append('hgext3rd.evolve.hack.directaccess')
 
-
-EVOLVE_PATH = 'hgext3rd/evolve/__init__.py'
-
 requires = []
 try:
     import mercurial
     mercurial.__all__
 except ImportError:
-    requires.append('mercurial>=%s' % min_hg_version(EVOLVE_PATH))
+    requires.append('mercurial>=%s' % min_hg_version())
 
 setup(
     name='hg-evolve',
-    version=get_version(EVOLVE_PATH),
+    version=get_version(),
     author='Pierre-Yves David',
     maintainer='Pierre-Yves David',
     maintainer_email='pierre-yves.david@ens-lyon.org',