-
Notifications
You must be signed in to change notification settings - Fork 0
/
.tox_env_exe_runner.py
executable file
·46 lines (33 loc) · 1.07 KB
/
.tox_env_exe_runner.py
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
36
37
38
39
40
41
42
43
44
45
46
"""Script to call executables in `tox` envs.
The script takes two mandatory arguments:
1. the executable to call like e.g. `pylint`
2. a string with comma separated `tox` envs to check for the executable
All other arguments after are passed to the tool on call.
The script considers OS and calls the tool accordingly.
"""
import subprocess # nosec
import sys
from pathlib import Path
def main():
"""Call given `tool` from given `tox` env."""
tool = sys.argv[1]
if sys.platform == "win32":
exe = Path("Scripts/" + tool + ".exe")
else:
exe = Path("bin/" + tool)
tox = Path(".tox")
envs = sys.argv[2].split(",")
cmd = None
for env in envs:
path = Path(tox / env / exe)
if path.is_file():
cmd = (str(path), *sys.argv[3:])
if cmd is None:
print(
"No '{}' executable found. Make sure one of the "
"following `tox` envs is accessible: {}".format(tool, envs)
)
return 1
return subprocess.call(cmd) # nosec
if __name__ == "__main__":
sys.exit(main())