AttributeError: 'module' object has no attribute 'match'

stanio avatarstanio created an issue

Using:

https://bitbucket.org/marcusl/ml-hgext/src/3b8498bbfc4f/checkfiles.py

Trying hg checkfiles --debug --traceback, I get the following:

checkfiles: checking modified files for tabs or trailing whitespace...
checkfiles: checked extensions:
checkfiles: ignored extensions: .sln .suo .vcproj .csproj .ui
checkfiles: ignored files:
checkfiles: check diffs only: True
checkfiles: use spaces: True
checkfiles: considering files:
  HelloWorld.java
Traceback (most recent call last):
  File "mercurial\dispatch.pyo", line 87, in _runcatch
  File "mercurial\dispatch.pyo", line 688, in _dispatch
  File "mercurial\dispatch.pyo", line 463, in runcommand
  File "mercurial\dispatch.pyo", line 742, in _runcommand
  File "mercurial\dispatch.pyo", line 696, in checkargs
  File "mercurial\dispatch.pyo", line 685, in <lambda>
  File "mercurial\util.pyo", line 385, in check
  File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 371, in check_cmd
  File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 202, in check
AttributeError: 'module' object has no attribute 'match'
** unknown exception encountered, please report by visiting
**  http://mercurial.selenic.com/wiki/BugTracker
** Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
** Mercurial Distributed SCM (version 1.9.2)
** Extensions loaded: checkfiles
Traceback (most recent call last):
  File "hg", line 42, in <module>
  File "mercurial\dispatch.pyo", line 27, in run
  File "mercurial\dispatch.pyo", line 64, in dispatch
  File "mercurial\dispatch.pyo", line 87, in _runcatch
  File "mercurial\dispatch.pyo", line 688, in _dispatch
  File "mercurial\dispatch.pyo", line 463, in runcommand
  File "mercurial\dispatch.pyo", line 742, in _runcommand
  File "mercurial\dispatch.pyo", line 696, in checkargs
  File "mercurial\dispatch.pyo", line 685, in <lambda>
  File "mercurial\util.pyo", line 385, in check
  File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 371, in check_cmd
    return cf.check()
  File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 202, in check
    cmdutil.match(self.repo)):
AttributeError: 'module' object has no attribute 'match'

My .hgrc is as follows:

[ui]
username = Stanimir Stamenkov

[extensions]
checkfiles = %USERPROFILE%\Programs\hgext\checkfiles.py

[checkfiles]
check_diffs = True

Comments (6)

  1. stanio

    Now using Mercurial 1.9.3, I don't know if 45a4024044b4 is supposed to work - after trying it I've first got:

    checkfiles: checking modified files for tabs or trailing whitespace...
    checkfiles: checked extensions:
    checkfiles: ignored extensions: .sln .suo .vcproj .csproj .ui
    checkfiles: ignored files:
    checkfiles: check diffs only: True
    checkfiles: use spaces: True
    checkfiles: considering files:
      HelloWorld.java
    Traceback (most recent call last):
      File "mercurial\dispatch.pyo", line 87, in _runcatch
      File "mercurial\dispatch.pyo", line 688, in _dispatch
      File "mercurial\dispatch.pyo", line 463, in runcommand
      File "mercurial\dispatch.pyo", line 742, in _runcommand
      File "mercurial\dispatch.pyo", line 696, in checkargs
      File "mercurial\dispatch.pyo", line 685, in <lambda>
      File "mercurial\util.pyo", line 389, in check
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 376, in check_cmd
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 199, in check
      File "mercurial\demandimport.pyo", line 85, in _demandimport
    ImportError: No module named cmdutil
    abort: No module named cmdutil!
    

    Then I've tried to modify the code like:

    diff -r 45a4024044b4 checkfiles.py
    --- a/checkfiles.py     Sun Oct 09 14:53:19 2011 +0200
    +++ b/checkfiles.py     Sun Oct 09 16:24:19 2011 +0300
    @@ -194,9 +194,9 @@
                     # XXX would be nicer if checked_exts were a proper pattern;
                     # then cmdutil.match would work naturally with it
                     try:
    -                    from scmutil import match
    +                    from mercurial.scmutil import match
                     except ImportError:
    -                    from cmdutil import match
    +                    from mercurial.cmdutil import match
    
                     file = None
                     hunk = None
    

    But further got:

    checkfiles: checking modified files for tabs or trailing whitespace...
    checkfiles: checked extensions:
    checkfiles: ignored extensions: .sln .suo .vcproj .csproj .ui
    checkfiles: ignored files:
    checkfiles: check diffs only: True
    checkfiles: use spaces: True
    checkfiles: considering files:
      HelloWorld.java
    Traceback (most recent call last):
      File "mercurial\dispatch.pyo", line 87, in _runcatch
      File "mercurial\dispatch.pyo", line 688, in _dispatch
      File "mercurial\dispatch.pyo", line 463, in runcommand
      File "mercurial\dispatch.pyo", line 742, in _runcommand
      File "mercurial\dispatch.pyo", line 696, in checkargs
      File "mercurial\dispatch.pyo", line 685, in <lambda>
      File "mercurial\util.pyo", line 389, in check
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 376, in check_cmd
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 207, in check
      File "mercurial\scmutil.pyo", line 569, in match
    AttributeError: 'localrepository' object has no attribute 'match'
    ** unknown exception encountered, please report by visiting
    **  http://mercurial.selenic.com/wiki/BugTracker
    ** Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
    ** Mercurial Distributed SCM (version 1.9.3)
    ** Extensions loaded: checkfiles
    Traceback (most recent call last):
      File "hg", line 42, in <module>
      File "mercurial\dispatch.pyo", line 27, in run
      File "mercurial\dispatch.pyo", line 64, in dispatch
      File "mercurial\dispatch.pyo", line 87, in _runcatch
      File "mercurial\dispatch.pyo", line 688, in _dispatch
      File "mercurial\dispatch.pyo", line 463, in runcommand
      File "mercurial\dispatch.pyo", line 742, in _runcommand
      File "mercurial\dispatch.pyo", line 696, in checkargs
      File "mercurial\dispatch.pyo", line 685, in <lambda>
      File "mercurial\util.pyo", line 389, in check
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 376, in check_cmd
        return cf.check()
      File "C:\Users\stanimir\Programs\hgext\checkfiles.py", line 207, in check
        match(self.repo)):
      File "mercurial\scmutil.pyo", line 569, in match
    AttributeError: 'localrepository' object has no attribute 'match'
    

    Does the last one appear a bug in Mercurial itself?

  2. stanio

    O.k. Applying the following change appears to work for me:

    diff -r 45a4024044b4 checkfiles.py
    --- a/checkfiles.py     Sun Oct 09 14:53:19 2011 +0200
    +++ b/checkfiles.py     Sun Oct 09 16:45:00 2011 +0300
    @@ -193,10 +193,7 @@
                 if len(self.ctx.parents()) == 1:
                     # XXX would be nicer if checked_exts were a proper pattern;
                     # then cmdutil.match would work naturally with it
    -                try:
    -                    from scmutil import match
    -                except ImportError:
    -                    from cmdutil import match
    +                from mercurial.scmutil import match
    
                     file = None
                     hunk = None
    @@ -204,7 +201,7 @@
                     for chunk, label in patch.diffui(self.repo,
                                                      self.ctx.p1().node(),
                                                      self.ctx.node(),
    -                                                 match(self.repo)):
    +                                                 match(self.repo[None])):
                         if len(label) > 0 or chunk != '\n':
                             self.ui.debug('checkfiles: %s="%s"\n' % (label, chunk))
                         if label == 'diff.file_b':
    

    This appears related to the following Mercurial change:

    http://selenic.com/hg/rev/35c2cc322ba8

    I'm not a Python programmer and I don't really know how it should be made backwards compatible with Mercurial versions prior 1.9.

  3. stanio

    Not sure if the following is proper Python but the change works for me:

    diff -r 45a4024044b4 checkfiles.py
    --- a/checkfiles.py     Sun Oct 09 14:53:19 2011 +0200
    +++ b/checkfiles.py     Sun Oct 09 16:55:47 2011 +0300
    @@ -194,9 +194,11 @@
                     # XXX would be nicer if checked_exts were a proper pattern;
                     # then cmdutil.match would work naturally with it
                     try:
    -                    from scmutil import match
    +                    from mercurial.scmutil import match
    +                    ctx = self.repo[None]
                     except ImportError:
    -                    from cmdutil import match
    +                    from mercurial.cmdutil import match
    +                    ctx = self.repo
    
                     file = None
                     hunk = None
    @@ -204,7 +206,7 @@
                     for chunk, label in patch.diffui(self.repo,
                                                      self.ctx.p1().node(),
                                                      self.ctx.node(),
    -                                                 match(self.repo)):
    +                                                 match(ctx)):
                         if len(label) > 0 or chunk != '\n':
                             self.ui.debug('checkfiles: %s="%s"\n' % (label, chunk))
                         if label == 'diff.file_b':
    
  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.