Ticket #8 (closed enhancement: fixed)

Opened 8 years ago

Last modified 7 years ago

hook for reindentation of Python code

Reported by: zooko@… Owned by: lele
Priority: minor Milestone: VersionOne
Component: tailor Version: 0.9
Keywords: hook plugin Cc: zooko@…

Description

Somebody please take this pre-commit hook and fix it. It appears to work "some of the time" for me.

You have to find reindent.py in your Python distribution and put it in your python path.

def reindent_em(wd, changeset):
    import reindent
    import os
    for entry in changeset.entries:
        fname = os.path.join(wd.basedir, entry.name)

        try:
            if fname[-3:] == '.py':
                reindent.check(fname)
        except Exception, le:
            print "got an exception from attempt to reindent (maybe that file wasn't Python code?): changeset entry: %s, exception: %s %s %s" % (entry, type(le), repr(le), hasattr(le, 'args') and le.args,)
            raise le
    return True

Attachments

reindent-hook.py Download (516 bytes) - added by zooko@… 8 years ago.
pre-commit hook to reindent Python

Change History

Changed 8 years ago by zooko@…

pre-commit hook to reindent Python

comment:1 Changed 8 years ago by anonymous

That is: I run it on an SVN repo to convert to darcs with this pre-hook, and the first few patches that I test are all properly reindented. But then if I let it run to the end and then spot-check a few patches in the middle of the history, I find patches that have not been reindented.

comment:2 Changed 7 years ago by anonymous

I no longer think that there is a problem in this hook. Rather, the problem I experienced was probably due to me running multiple instances of tailor simultaneously on the same directory, or something.

Hm. Maybe tailor should create a lockfile...

Anyway, please add this hook to the library of useful hooks.

comment:3 Changed 7 years ago by zooko@…

http://progetti.arstecnica.it/tailor/ticket/21

causes problems when using this hook.

However, a worse problem is that if any version of the file cannot be reindented by reindent.py (for example, due to inconsistent tab usage), then it appears as though that version had a bunch of "anti-reindent.py" changes made to it (because the previous version was reindent.py'ed, but this version wasn't). This is very ugly and makes version history wrong, so I no longer use this hook.

comment:4 Changed 7 years ago by lele

  • Status changed from new to closed
  • Resolution set to fixed

Added to the README file.

Note: See TracTickets for help on using tickets.