mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Actually write the lint reports.
It's just too much trouble to stream both to stdout and to a file from a subprocess.
This commit is contained in:
parent
5f972704bd
commit
83dc97dfee
1 changed files with 17 additions and 55 deletions
72
noxfile.py
72
noxfile.py
|
@ -14,14 +14,7 @@ import glob
|
|||
import json
|
||||
import pprint
|
||||
import shutil
|
||||
try:
|
||||
# Python 2
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
# Python 3
|
||||
import io
|
||||
StringIO = io.StringIO
|
||||
|
||||
import tempfile
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.stderr.write('Do not execute this file directly. Use nox instead, it will know how to handle this file\n')
|
||||
|
@ -36,46 +29,6 @@ from nox.command import CommandFailed
|
|||
PIP_INSTALL_SILENT = (os.environ.get('JENKINS_URL') or os.environ.get('CI') or os.environ.get('DRONE')) is None
|
||||
|
||||
|
||||
# ----- Helper Classes ---------------------------------------------------------------------------------------------->
|
||||
class StdStream(StringIO):
|
||||
def __init__(self, std):
|
||||
StringIO.__init__(self)
|
||||
self._std = std
|
||||
|
||||
def write(self, data):
|
||||
StringIO.write(self, data)
|
||||
self._std.write(data)
|
||||
|
||||
|
||||
class CaptureSTDs(object):
|
||||
|
||||
def __init__(self):
|
||||
self._stdout = StdStream(sys.stdout)
|
||||
self._stderr = StdStream(sys.stderr)
|
||||
self._sys_stdout = sys.stdout
|
||||
self._sys_stderr = sys.stderr
|
||||
|
||||
def __enter__(self):
|
||||
sys.stdout = self._stdout
|
||||
sys.stderr = self._stderr
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
sys.stdout = self._sys_stdout
|
||||
sys.stderr = self._sys_stderr
|
||||
|
||||
@property
|
||||
def stdout(self):
|
||||
self._stdout.seek(0)
|
||||
return self._stdout.read()
|
||||
|
||||
@property
|
||||
def stderr(self):
|
||||
self._stdout.seek(0)
|
||||
return self._stdout.read()
|
||||
# <---- Helper Classes -----------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Global Path Definitions
|
||||
REPO_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||
SITECUSTOMIZE_DIR = os.path.join(REPO_ROOT, 'tests', 'support', 'coverage')
|
||||
|
@ -777,16 +730,25 @@ def _lint(session, rcfile, flags, paths):
|
|||
'--rcfile={}'.format(rcfile)
|
||||
] + list(flags) + list(paths)
|
||||
|
||||
stdout = tempfile.TemporaryFile(mode='w+b')
|
||||
lint_failed = False
|
||||
try:
|
||||
with CaptureSTDs() as capstds:
|
||||
session.run(*cmd_args)
|
||||
session.run(*cmd_args, stdout=stdout)
|
||||
except CommandFailed:
|
||||
if pylint_report_path:
|
||||
# Write report
|
||||
with open(pylint_report_path, 'w') as wfh:
|
||||
wfh.write(capstds.stdout)
|
||||
session.log('Report file written to %r', pylint_report_path)
|
||||
lint_failed = True
|
||||
raise
|
||||
finally:
|
||||
stdout.seek(0)
|
||||
contents = stdout.read().encode('utf-8')
|
||||
if contents:
|
||||
sys.stdout.write(contents)
|
||||
sys.stdout.flush()
|
||||
if pylint_report_path:
|
||||
# Write report
|
||||
with open(pylint_report_path, 'w') as wfh:
|
||||
wfh.write(contents)
|
||||
session.log('Report file written to %r', pylint_report_path)
|
||||
stdout.close()
|
||||
|
||||
|
||||
@nox.session(python='2.7')
|
||||
|
|
Loading…
Add table
Reference in a new issue