Commit d1b77726 authored by David H's avatar David H

Got mercurial hook working, with improvements

This commit fixes a problem that caused "flake8 --install-hook mercurial" to
die with this message:

    Could not find the mercurial directory

Also fixes two usages of configparser (can't supply a non-text value when
calling .set(), and need to use .getboolean() to convert the value to a

This commit converts the hook itself from a function hook to a script hook.
This enables the hook to run even when flake8 is installed in a virtual
environment and Mercurial is installed globally (a common case.) This also
makes it possible for flake8 to be installed for Python 3; Mercurial is
Python 2.x only.

Also convert the hook event from "commit" to "pretxncommit" so that strict
mode would actually work. A regular commit hook runs only after the commit
is completed; a pretxncommit hook will cause the transaction to be rolled
back if it exits with a non-zero code.

Finally, put extensions on the hook names: pretxncommit.flake8 and
qrefresh.flake8. This allows the flake8 hook to coexist with other hooks the
user might have put in place.

I tested flake8 mercurial hook installation and execution on both Python 2.7
and Python 3.5. I did *not* test the qrefresh.flake8 hook. I could not find
documentation on qrefresh hook event; I presume it has something to do with
the Mercurial MQ extension, which I have never used. Probably this commit
does not make it any worse than it was before.

For more info see:

Closes #283
parent 348722d7
Pipeline #5446279 passed with stages
in 3 minutes and 24 seconds