File: mypy-after-commit.py

package info (click to toggle)
toil 9.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,908 kB
  • sloc: python: 58,029; makefile: 313; sh: 168
file content (35 lines) | stat: -rwxr-xr-x 1,108 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3

"""
mypy-after-commit.py: Git post-commit script to type-check commits in the background.

Install with:

ln -rs ./contrib/hooks/mypy-after-commit.py .git/hooks/post-commit
"""

import sys
import subprocess
import os

from lib import announce, complain, file_link, in_acceptable_environment, check_to_cache, get_current_commit, is_rebase

def main(argc, argv):
    # No input; we want to run in the background
    if in_acceptable_environment() and not is_rebase():
        announce('Type-checking commit')
        commit = get_current_commit()
        result, log, filename = check_to_cache(commit, timeout=10)
        if result is None:
            # Type checking timed out
            announce('This is taking a while. Type-checking in the background.')
            if os.fork() == 0:
                check_to_cache(commit)
        elif result:
            announce('Commit OK')
        else:
            complain('Commit did not type-check! ' + file_link(filename, 'See the log for details.'))
    return 0

if __name__ == "__main__":
    sys.exit(main(len(sys.argv), sys.argv))