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
12 here
= os
.path
.dirname(os
.path
.realpath(__file__
))
13 topsrcdir
= os
.path
.join(here
, os
.pardir
, os
.pardir
)
17 proc
= subprocess
.Popen(cmd
)
19 # ignore SIGINT, the mozlint subprocess should exit quickly and gracefully
20 orig_handler
= signal
.signal(signal
.SIGINT
, signal
.SIG_IGN
)
22 signal
.signal(signal
.SIGINT
, orig_handler
)
23 return proc
.returncode
26 def run_mozlint(hooktype
, args
):
27 if isinstance(hooktype
, bytes
):
28 hooktype
= hooktype
.decode("UTF-8", "replace")
30 python
= find_executable("python3")
32 print("error: Python 3 not detected on your system! Please install it.")
35 cmd
= [python
, os
.path
.join(topsrcdir
, "mach"), "lint"]
37 if "commit" in hooktype
:
38 # don't prevent commits, just display the lint results
39 run_process(cmd
+ ["--workdir=staged"])
41 elif "push" in hooktype
:
42 return run_process(cmd
+ ["--outgoing"] + args
)
44 print("warning: '{}' is not a valid mozlint hooktype".format(hooktype
))
48 def hg(ui
, repo
, **kwargs
):
49 hooktype
= kwargs
["hooktype"]
50 return run_mozlint(hooktype
, kwargs
.get("pats", []))
54 hooktype
= os
.path
.basename(__file__
)
55 if hooktype
== "hooks.py":
57 return run_mozlint(hooktype
, [])
60 if __name__
== "__main__":