Download:
child 192:513e6162d4d6
parent 190:010899b21c6a
191:d4fb20496675
Anton Shestakov <av6@dwimlabs.net>, Sat, 30 Jul 2016 13:40:27 +0800
checker: support variables in linter config

1 файлов изменено, 51 вставок(+), 26 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
--- a/checker.py Sat Jul 30 13:35:44 2016 +0800
+++ b/checker.py Sat Jul 30 13:40:27 2016 +0800
@@ -91,13 +91,31 @@
return ok
-def combined_env(lenv, penv):
- if lenv and penv:
- env = lenv.copy()
- env.update(penv)
+def combined(a, b):
+ if a and b:
+ result = a.copy()
+ result.update(b)
else:
- env = lenv or penv
- return env
+ result = a or b
+ return result
+
+
+def process_config(lc, pc):
+ c = {
+ 'env': combined(lc.get('env'), pc.get('env')),
+ 'vars': combined(lc.get('vars', {}), pc.get('vars', {}))
+ }
+
+ def render(items):
+ return [item % c['vars'] for item in items]
+
+ for key in ('flags', 'post_flags'):
+ c[key] = render(lc.get(key, []) + pc.get(key, []))
+
+ c['setup'] = [render(steps) for steps in lc.get('setup', [])]
+ c['exec'] = render(lc['exec'])
+ c['version'] = render(lc['version'])
+ return c
def git_clone(url, dest):
@@ -223,41 +241,51 @@
if name not in distinct:
distinct.append(name)
- print('# C&O installing linters: {}'.format(' '.join(distinct)))
-
linter_config = {}
-
- for linter in linters:
- name = linter['name']
+ for name in distinct:
if name in linter_config:
continue
lc = read_linter_config(name)
-
if lc is None:
print("# C&O skipping '{}': no config".format(name))
continue
-
if 'exec' not in lc:
print("# C&O skipping '{}': no 'exec' in config".format(name))
continue
linter_config[name] = lc
- for item in lc.get('setup', []):
- if not run(item):
- return False
+ installing = [name for name in distinct if name in linter_config]
+ print('# C&O installing linters: {}'.format(' '.join(installing)))
+ installed = []
+ setup_cache = set()
+ for linter in linters:
+ name = linter['name']
+ if name not in linter_config:
+ continue
+
+ lc = process_config(linter_config[name], linter)
+
+ if 'setup' in lc and str(lc['setup']) not in setup_cache:
+ for item in lc['setup']:
+ if not run(item):
+ return False
+ setup_cache.add(str(lc['setup']))
if 'version' in lc:
- env = combined_env(lc.get('env'), linter.get('env'))
- if not run(lc['exec'] + lc['version'], env=env):
+ if not run(lc['exec'] + lc['version'], env=lc['env']):
return False
- print('# C&O linters installed: {}'.format(' '.join(linter_config.keys())))
+ if name not in installed:
+ installed.append(name)
+
+ print('# C&O linters installed: {}'.format(' '.join(installed)))
print('# C&O task: checks')
for linter in linters:
- if linter['name'] not in linter_config:
+ name = linter['name']
+ if name not in linter_config:
continue
if config['scm'] == 'git':
@@ -267,15 +295,12 @@
if files is False:
return False
- lc = linter_config[linter['name']]
+ lc = process_config(linter_config[name], linter)
for f in files:
- cmd = lc['exec']
- flags = lc.get('flags', []) + linter.get('flags', [])
- pf = lc.get('post_flags', []) + linter.get('post_flags', [])
+ cmd = lc['exec'] + lc['flags'] + [f] + lc['post_flags']
codes = lc.get('codes', (1,))
- env = combined_env(lc.get('env'), linter.get('env'))
- if not run(cmd + flags + [f] + pf, ignore_codes=codes, env=env):
+ if not run(cmd, ignore_codes=codes, env=lc['env']):
return False
return True