2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 from distutils
.spawn
import find_executable
14 here
= os
.path
.dirname(os
.path
.realpath(__file__
))
15 topsrcdir
= os
.path
.join(here
, os
.pardir
, os
.pardir
)
19 proc
= subprocess
.Popen(cmd
)
21 # ignore SIGINT, the mozlint subprocess should exit quickly and gracefully
22 orig_handler
= signal
.signal(signal
.SIGINT
, signal
.SIG_IGN
)
24 signal
.signal(signal
.SIGINT
, orig_handler
)
25 return proc
.returncode
28 def run_mozlint(hooktype
, args
):
29 if isinstance(hooktype
, six
.binary_type
):
30 hooktype
= hooktype
.decode("UTF-8", "replace")
32 python
= find_executable("python3")
34 print("error: Python 3 not detected on your system! Please install it.")
37 cmd
= [python
, os
.path
.join(topsrcdir
, "mach"), "lint"]
39 if "commit" in hooktype
:
40 # don't prevent commits, just display the lint results
41 run_process(cmd
+ ["--workdir=staged"])
43 elif "push" in hooktype
:
44 return run_process(cmd
+ ["--outgoing"] + args
)
46 print("warning: '{}' is not a valid mozlint hooktype".format(hooktype
))
50 def hg(ui
, repo
, **kwargs
):
51 hooktype
= kwargs
["hooktype"]
52 return run_mozlint(hooktype
, kwargs
.get("pats", []))
56 hooktype
= os
.path
.basename(__file__
)
57 if hooktype
== "hooks.py":
59 return run_mozlint(hooktype
, [])
62 if __name__
== "__main__":