Skip to content

Commit

Permalink
fixed handling new pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
godfryd committed Sep 11, 2021
1 parent 8f672bf commit 09c0c89
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
23 changes: 16 additions & 7 deletions agent/kraken/agent/kraken_pylint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The Kraken Authors
# Copyright 2020-2021 The Kraken Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,7 @@

import json
import logging
import tempfile

import giturlparse

Expand Down Expand Up @@ -61,13 +62,21 @@ def run_analysis(step, report_issue=None):
rcfile = step['rcfile']
modules_or_packages = step['modules_or_packages']
pylint_exe = step.get('pylint_exe', 'pylint')
cmd = '%s --exit-zero -f json --rcfile=%s %s' % (pylint_exe, rcfile, modules_or_packages)
ret, out = utils.execute(cmd, cwd=cwd, out_prefix='', timeout=180)
if ret != 0:
log.error('pylint exited with non-zero retcode: %s', ret)
return ret, 'pylint exited with non-zero retcode'

result = json.loads(out)
with tempfile.NamedTemporaryFile(suffix=".json", prefix="pylint-result-") as fh:
result_file = fh.name
cmd = 'sh -c "%s --exit-zero -f json --rcfile=%s %s > %s"' % (pylint_exe, rcfile, modules_or_packages, result_file)
ret, out = utils.execute(cmd, cwd=cwd, out_prefix='', timeout=180)

if ret != 0:
log.error('pylint exited with non-zero retcode: %s', ret)
return ret, 'pylint exited with non-zero retcode'

with open(result_file) as rf:
json_txt = rf.read()

result = json.loads(json_txt)

for issue in result:
log.info('%s:%s %s', issue['path'], issue['line'], issue['message'])
if git_url:
Expand Down
12 changes: 8 additions & 4 deletions agent/tests/test_kraken_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ def _rep_issue(issue):
patch('kraken.agent.kraken_pylint._get_git_url', return_value='https://github.com/Kraken-CI/kraken/blob/master'):
ret, msg = kraken_pylint.run_analysis(step, report_issue=_rep_issue)

ue.assert_called_once_with('pylint --exit-zero -f json --rcfile=pylint.rc .',
cwd='.',
out_prefix='',
timeout=180)
ue.assert_called_once()
print('ARGS', ue.call_args)
assert ue.call_args.kwargs['cwd'] == '.'
assert ue.call_args.kwargs['timeout'] == 180
assert 'pylint' in ue.call_args.args[0]
assert '--exit-zero' in ue.call_args.args[0]
assert '--rcfile=pylint.rc' in ue.call_args.args[0]
assert '-f json' in ue.call_args.args[0]

assert ret == 0
assert msg == ''
Expand Down

0 comments on commit 09c0c89

Please sign in to comment.