Download:
child 180:d13fecc86d03
parent 178:290623d1275c
179:572fc0f25c6b
Anton Shestakov <av6@dwimlabs.net>, Sun, 24 Jul 2016 09:24:14 +0800
checker: support running linters with custom environment

1 файлов изменено, 25 вставок(+), 8 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
--- a/checker.py Sun Jul 24 09:08:17 2016 +0800
+++ b/checker.py Sun Jul 24 09:24:14 2016 +0800
@@ -13,27 +13,32 @@
from candolint.utils import rel, timestamp
-def run_ignore_codes(fn, args, codes):
+def run_ignore_codes(fn, args, codes, **kwargs):
try:
- return fn(args)
+ return fn(args, **kwargs)
except CalledProcessError as e:
if e.returncode not in codes:
raise
return e.output
-def run(args, silent=False, get_output=False, ignore_codes=None):
+def run(args, silent=False, get_output=False, ignore_codes=None, env=None):
if get_output:
fn = check_output
else:
fn = check_call
+ if env:
+ full_env = os.environ.copy()
+ full_env.update(env)
+ else:
+ full_env = None
try:
if not silent:
print('$ ' + ' '.join(args))
if ignore_codes:
- result = run_ignore_codes(fn, args, ignore_codes)
+ result = run_ignore_codes(fn, args, ignore_codes, env=full_env)
else:
- result = fn(args)
+ result = fn(args, env=full_env)
if get_output:
return result
else:
@@ -74,6 +79,15 @@
return ok
+def combined_env(lenv, penv):
+ if lenv and penv:
+ env = lenv.copy()
+ env.update(penv)
+ else:
+ env = lenv or penv
+ return env
+
+
def git_clone(url, dest):
return run(['git', 'clone', url, dest])
@@ -211,8 +225,10 @@
if not run(item):
return False
- if 'version' in lc and not run(lc['exec'] + lc['version']):
- return False
+ if 'version' in lc:
+ env = combined_env(lc.get('env'), linter.get('env'))
+ if not run(lc['exec'] + lc['version'], env=env):
+ return False
print('# C&O linters installed: {}'.format(' '.join(linter_config.keys())))
@@ -238,7 +254,8 @@
flags = lc.get('flags', []) + linter.get('flags', [])
pf = lc.get('post_flags', []) + linter.get('post_flags', [])
codes = lc.get('codes', (1,))
- if not run(cmd + flags + [f] + pf, ignore_codes=codes):
+ env = combined_env(lc.get('env'), linter.get('env'))
+ if not run(cmd + flags + [f] + pf, ignore_codes=codes, env=env):
return False
return True