changeset 73:d262139732f7

Fixed to work against mercurial >= 4.1 (which requires using @command decorator for commands). (internally using mercurial_extension_utils to define command portably)
author Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
date Thu, 18 May 2017 17:36:19 +0200
parents 29fa6cfad89b
children 879d1f392fa7
files HISTORY.txt README.txt mercurial_all_paths.py setup.py
diffstat 4 files changed, 103 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/HISTORY.txt	Thu May 18 17:35:36 2017 +0200
+++ b/HISTORY.txt	Thu May 18 17:36:19 2017 +0200
@@ -1,9 +1,15 @@
-1.0.3
+1.1.0
 ~~~~~~~~~~~~~
 
-Updated links after bitbucket changes.
+Fixed to work with Mercurial >= 4.1
+
+Formally tested against Mercurial 4.1 and 4.2
 
-hg 4.1 and 4.2 added to tested versions.
+Updated doc links after bitbucket changes.
+
+Note: since this version mercurial_extension_utils is required
+(for meu.command, compatibility layer for command definition
+working against various mercurial versions).
 
 1.0.2
 ~~~~~~~~~~~~~
--- a/README.txt	Thu May 18 17:35:36 2017 +0200
+++ b/README.txt	Thu May 18 17:36:19 2017 +0200
@@ -164,22 +164,27 @@
 From source
 -------------------------------------------------------
 
-Clone this repository::
+If you don't have ``pip``, or wish to follow development more closely:
+
+- clone both this repository and `mercurial_extension_utils`_ and put
+  them in the same directory, for example::
 
     cd ~/sources
+    hg clone https://bitbucket.org/Mekk/mercurial-extension_utils/
     hg clone https://bitbucket.org/Mekk/mercurial-all_paths/
 
-either::
+- update to newest tags,
 
-    pip install --user -e mercurial-all_paths
-
-and activate as above, or just activate by full path::
+- activate by::
 
     [extensions]
-    mercurial_path_pattern = ~/sources/mercurial-path_pattern/mercurial_path_pattern.py
+    mercurial_all_paths = ~/sources/mercurial-all_paths/mercurial_all_paths.py
 
 To upgrade, pull and update.
 
+Note that directory names matter. See `mercurial_extension_utils`_ for
+longer description of this kind of installation.
+
 History
 =======================================================
 
@@ -188,15 +193,15 @@
 Development
 =======================================================
 
-Main extension repository, maintained by Ludovic Chabant, is available
-at:
+Development is tracked on BitBucket, see
+
+    http://bitbucket.org/Mekk/mercurial-all_paths/
+
+Original repository, maintained by Ludovic Chabant (lagging a bit at
+the moment):
 
     https://bitbucket.org/ludovicchabant/allpaths
 
-Fork by Marcin Kasperski, which is usually in sync, but at times may
-contain some not-yet merged changes, is available at:
-
-    http://bitbucket.org/Mekk/mercurial-all_paths/
 
 Additional notes
 =======================================================
@@ -207,6 +212,7 @@
 
 .. _Path Pattern: https://bitbucket.org/Mekk/mercurial-path_pattern/
 .. _HISTORY.txt: http://bitbucket.org/Mekk/mercurial-all_paths/src/tip/HISTORY.txt
+.. _mercurial_extension_utils: https://bitbucket.org/Mekk/mercurial-extension_utils/
 
 .. |drone-badge| 
     image:: https://drone.io/bitbucket.org/Mekk/mercurial-all_paths/status.png
--- a/mercurial_all_paths.py	Thu May 18 17:35:36 2017 +0200
+++ b/mercurial_all_paths.py	Thu May 18 17:36:19 2017 +0200
@@ -12,6 +12,34 @@
 import mercurial.cmdutil
 from mercurial.i18n import _
 
+
+def import_meu():
+    """Importing mercurial_extension_utils so it can be found also outside
+    Python PATH (support for TortoiseHG/Win and similar setups)"""
+    try:
+        import mercurial_extension_utils
+    except ImportError:
+        my_dir = os.path.dirname(__file__)
+        sys.path.extend([
+            # In the same dir (manual or site-packages after pip)
+            my_dir,
+            # Developer clone
+            os.path.join(os.path.dirname(my_dir), "extension_utils"),
+            # Side clone
+            os.path.join(os.path.dirname(my_dir), "mercurial-extension_utils"),
+        ])
+        try:
+            import mercurial_extension_utils
+        except ImportError:
+            raise util.Abort(_("""Can not import mercurial_extension_utils.
+Please install this module in Python path.
+See Installation chapter in https://bitbucket.org/Mekk/mercurial-dynamic_username/ for details
+(and for info about TortoiseHG on Windows, or other bundled Python)."""))
+    return mercurial_extension_utils
+
+meu = import_meu()
+
+
 # pylint:disable=invalid-name,broad-except,line-too-long
 
 def _find_all_paths(ui, skip_ignored=False, sort_by_priority=False):
@@ -38,7 +66,7 @@
                 prior_val[item] = idx
             higher = len(prior)
             paths.sort(key = lambda it: prior_val.get(it[0], higher))
-        
+
     return paths
 
 def _find_paths(ui, group=None):
@@ -63,7 +91,7 @@
                 paths.append((item, all_paths[item]))
         if not paths:
             raise mercurial.util.Abort(_('None of the paths from group %s is defined in this repository') % group)
-            
+
         return paths
 
     # „Legacy” syntax, used also for all paths
@@ -71,7 +99,7 @@
     if not paths:
         raise mercurial.util.Abort(_('No paths defined in section %s') % group)
     return paths
-       
+
 
 def _iter_over_paths(command, ui, repo, add_sep, **opts):
     """execute given command on multiple paths"""
@@ -104,24 +132,11 @@
                 ui.warn(_('error handling %s: %s\n') % (alias, e))
                 sep = '\n'
 
-def pushall(ui, repo, **opts):
-    """execute push on multiple paths"""
-    _iter_over_paths(mercurial.commands.push, ui, repo, True, **opts)
 
-
-def pullall(ui, repo, **opts):
-    """execute pull on multiple paths"""
-    _iter_over_paths(mercurial.commands.pull, ui, repo, True, **opts)
-
-
-def incomingall(ui, repo, **opts):
-    """execute incoming on multiple paths"""
-    _iter_over_paths(mercurial.commands.incoming, ui, repo, False, **opts)
-
-
-def outgoingall(ui, repo, **opts):
-    """execute outgoing on multiple paths"""
-    _iter_over_paths(mercurial.commands.outgoing, ui, repo, False, **opts)
+EXT_OPTS = [
+    ('g', 'group', '', _('use a named group instead of all paths')),
+    ('', 'ignore-errors', None, _('continue execution despite errors')),
+]
 
 
 def _original_options(cmdname):
@@ -130,30 +145,41 @@
     return spec[1]
 
 
-EXT_OPTS = [
-    ('g', 'group', '', _('use a named group instead of all paths')),
-    ('', 'ignore-errors', None, _('continue execution despite errors')),
-]
+cmdtable = {}
+command = meu.command(cmdtable)
+
+
+@command("pushall",
+         EXT_OPTS + _original_options('push'),
+         _('[-g GROUP] [--ignore-errors] <push options>'))
+def pushall(ui, repo, **opts):
+    """execute push on multiple paths"""
+    _iter_over_paths(mercurial.commands.push, ui, repo, True, **opts)
+
+
+@command("pullall",
+         EXT_OPTS + _original_options('pull'),
+         _('[-g GROUP] [--ignore-errors] <pull options>'))
+def pullall(ui, repo, **opts):
+    """execute pull on multiple paths"""
+    _iter_over_paths(mercurial.commands.pull, ui, repo, True, **opts)
 
-cmdtable = {
-    "pushall": (
-        pushall,
-        EXT_OPTS + _original_options('push'),
-        _('[-g GROUP] [--ignore-errors] <push options>')),
-    "pullall": (
-        pullall,
-        EXT_OPTS + _original_options('pull'),
-        _('[-g GROUP] [--ignore-errors] <pull options>')),
-    # For incoming and outgoing -g is taken (--git diff format)
-    "incomingall": (
-        incomingall,
-        EXT_OPTS + _original_options('incoming'),
-        _('[--group GROUP] [--ignore-errors] <incoming options>')),
-    "outgoingall": (
-        outgoingall,
-        EXT_OPTS + _original_options('outgoing'),
-        _('[--group GROUP] [--ignore-errors] <outgoing options>')),
-}
+
+@command("incomingall",
+         EXT_OPTS + _original_options('incoming'),
+         _('[--group GROUP] [--ignore-errors] <incoming options>'))
+def incomingall(ui, repo, **opts):
+    """execute incoming on multiple paths"""
+    _iter_over_paths(mercurial.commands.incoming, ui, repo, False, **opts)
+
 
-testedwith = '2.7 2.9 3.0 3.3 3.6 3.7 3.8 4.0'
+@command("outgoingall",
+         EXT_OPTS + _original_options('outgoing'),
+         _('[--group GROUP] [--ignore-errors] <outgoing options>'))
+def outgoingall(ui, repo, **opts):
+    """execute outgoing on multiple paths"""
+    _iter_over_paths(mercurial.commands.outgoing, ui, repo, False, **opts)
+
+
+testedwith = '2.7 2.9 3.0 3.3 3.6 3.7 3.8 4.0 4.1 4.2'
 buglink = 'https://bitbucket.org/Mekk/mercurial-all_paths/issues'
--- a/setup.py	Thu May 18 17:35:36 2017 +0200
+++ b/setup.py	Thu May 18 17:36:19 2017 +0200
@@ -21,7 +21,12 @@
     description='Mercurial allpaths extension',
     long_description=LONG_DESCRIPTION,
     license='GNU General Public License v2 (GPLv2)',
-    py_modules=['mercurial_all_paths'],
+    py_modules=[
+        'mercurial_all_paths',
+    ],
+    install_requires=[
+        'mercurial_extension_utils>=1.2.0',
+    ],
     keywords="mercurial paths multi extension",
     classifiers=[
         'Development Status :: 4 - Beta',