def run(self, files): # type: (typing.List[str]) -> None import isort self.conf["line_length"] = self.conf.as_int("line_length") self.conf["sections"] = self.conf.as_list("sections") self.conf["multi_line_output"] = self.conf.as_int("multi_line_output") res = [] for filename in files: with redirect_stdout(io.StringIO()): # mute stdout sort = isort.SortImports(filename, **self.conf) if sort.skipped: continue self.status_code = self.status_code or ( 1 if sort.incorrectly_sorted else 0) if self.conf.as_bool("inplace"): with io.open(filename, "w", encoding="utf-8") as file: file.write(sort.output) else: with io.open(filename, encoding="utf-8") as file: out = io.StringIO() with redirect_stdout(out): sort._show_diff(file.read()) # pylint: disable=protected-access out.seek(0) diff = out.read() if diff.strip(): res.append(diff.strip()) self.hook(res)
def run(self, files: list) -> None: import isort self.conf['line_length'] = self.conf.as_int('line_length') self.conf['sections'] = self.conf.as_list('sections') self.conf['multi_line_output'] = self.conf.as_int('multi_line_output') res = [] for filename in files: with redirect_stdout(io.StringIO()): # mute stdout sort = isort.SortImports(filename, **self.conf) if sort.skipped: continue self.status_code = self.status_code or ( 1 if sort.incorrectly_sorted else 0) if self.conf.as_bool('inplace'): with open(filename, "w") as file: file.write(sort.output) else: with open(filename) as file: out = io.StringIO() with redirect_stdout(out): sort._show_diff(file.read()) # pylint: disable=protected-access out.seek(0) diff = out.read() if diff.strip(): res.append(diff.strip()) self.hook(res)
def run(self, files): # type: (typing.List[str]) -> None args = ["-f", "json"] + files if sys.version_info >= (3, 0, 0): file = io.StringIO() else: file = io.BytesIO() with redirect_stdout(sys.stderr), redirect_stderr(file): import pylint.lint if sys.version_info < (3, 0, 0): from pylint.reporters.json import JSONReporter JSONReporter.__init__.__func__.__defaults__ = (file, ) else: from pylint.reporters.json_reporter import JSONReporter JSONReporter.__init__.__defaults__ = (file, ) if sys.version_info >= (3, 0, 0): pylint.lint.Run(args, do_exit=False) else: pylint.lint.Run(args, exit=False) file.seek(0) text = file.read() if text.startswith("Using config file"): text = "\n".join(text.split("\n")[1:]) data = json.loads(text) if text.strip() else [] self.status_code = bool(data) self.hook(data)
def run(self, _: list) -> None: import safety.cli if "requirements.txt" not in os.listdir(): self.hook([]) return outfile = io.StringIO() try: with redirect_stdout(outfile): safety.cli.check.callback(self.conf.get("pyup_key", ""), self.conf.get("db_path", ""), True, False, False, False, False, "requirements.txt", self.conf.as_list("ignore")) except SystemExit: # Raised by safety pass outfile.seek(0) json_data = json.load(outfile) self.status_code = 1 if json_data else 0 self.hook(json_data)
def run(self, _): # type: (typing.List[str]) -> None errors = [] if sys.version_info >= (3, 0, 0): fileo = io.StringIO() else: fileo = io.BytesIO() with redirect_stdout(fileo), redirect_stderr(fileo): from unittest import TestProgram, TextTestRunner paths = glob.glob(self.conf["testpaths"]) if len(paths) == 1 and os.path.isdir(paths[0]): paths = [ paths[0] + "/" + path for path in os.listdir(paths[0]) if not os.path.isdir(paths[0] + "/" + path) ] for path in paths: test_name = path.split(".")[0].replace("/", ".") try: prog = TestProgram(test_name, testRunner=TextTestRunner(stream=fileo), exit=False) except SystemExit: # py2 pass errors += prog.result.errors errors += prog.result.failures fileo.seek(0) self.status_code = bool(errors) self.hook(errors)
def run(self, files: list) -> None: import pylint.lint args = ["-f", "json"] + files file = io.StringIO() with redirect_stdout(file): pylint.lint.Run(args, exit=False) file.seek(0) text = file.read() self.status_code = 1 if text.strip() else 0 data = json.loads(text) if text.strip() else [] self.hook(data)
def run(self, files: list) -> None: import vulture.core vult = vulture.core.Vulture(self.conf.as_bool('verbose')) vult.scavenge(files, [x.strip() for x in self.conf.as_list("exclude")]) file = io.StringIO() with redirect_stdout(file): vult.report(self.conf.as_int("min-confidence"), self.conf.as_bool("sort-by-size")) file.seek(0) matches = list(self.patt.finditer(file.read())) self.status_code = 1 if matches else 0 self.hook( list( sorted([x.groupdict() for x in matches], key=lambda x: x["line"])))
def run(self, _): # type: (typing.List[str]) -> None import requests import twine.commands.upload import twine.settings try: with redirect_stdout(io.StringIO()), \ redirect_stderr(io.StringIO()): if sys.version_info >= (3, 0, 0): proc = subprocess.Popen( # noqa: B603 [ sys.executable, "setup.py", "sdist", "bdist_wheel", ], stdout=subprocess.DEVNULL, ) else: proc = subprocess.Popen( # noqa: B603 [ sys.executable, "setup.py", "-q", "sdist", "bdist_wheel" ]) proc.wait() twine.commands.upload.upload( twine.settings.Settings( sign=self.conf.as_bool("sign"), repository=self.conf["TWINE_REPOSITORY"], username=self.conf["TWINE_USERNAME"], identity=self.conf.get("identity"), password=self.conf["TWINE_PASSWORD"], comment=self.conf.get("comment"), sign_with=self.conf.get("sign-with"), config_file=self.confpath, skip_existing=self.conf.get("skip-existing", True), ), [ "dist/*{0}*".format( self.conf.get("version", __version__)) ], ) # noqa except requests.exceptions.HTTPError as err: print(err) self.hook([])
def run(self, _: list) -> None: import pytest with redirect_stdout(sys.stderr): exitcode = pytest.main( ["--json=.log.json", "-qqqq", "-c", self.confpath]) self.status_code = exitcode with open(".log.json") as file: data = json.load(file) os.remove(".log.json") self.hook([ test for test in data['report']['tests'] if test['outcome'] == 'failed' ])
def run(self, files: list) -> None: import flake8.main.cli file = io.StringIO() with redirect_stdout(file): try: sett = ["--config=" + self.confpath] sett.extend(files) flake8.main.cli.main(sett) except SystemExit: print("aaa") file.seek(0) matches = list(self.patt.finditer(file.read())) self.status_code = 1 if matches else 0 self.hook( list( sorted([x.groupdict() for x in matches], key=lambda x: x["line"])))
def run(self, _): # type: (typing.List[str]) -> None if sys.version_info >= (3, 0, 0): t = io.StringIO else: t = io.BytesIO file = t() with redirect_stdout(file), redirect_stderr(file): # Import pyroma here because it uses logging and sys.stdout import pyroma # noqa pylint: disable=all pyroma.run("directory", ".") file.seek(0) text = file.read() lines = text.split("\n") lines.pop(0) if sys.version_info >= (3, 0, 0): lines.pop(0) data = {"modules": {}} module = lines.pop(0)[6:].strip() data["modules"][module] = [] lines.pop(0) if len(lines) >= 6: line = lines.pop(0) while line != "-" * 30: data["modules"][module].append(line) line = lines.pop(0) rating = lines.pop(0) data["rating"] = int(rating[14:-3]) data["rating_word"] = lines.pop(0) self.status_code = 0 if data["rating"] == 10 else 1 if data["rating"] == 10: data = [] self.hook(data)
def run(self, files): # type: (typing.List[str]) -> None import vulture.core vult = vulture.core.Vulture(self.conf.as_bool("verbose")) vult.scavenge(files, [x.strip() for x in self.conf.as_list("exclude")]) if sys.version_info >= (3, 0, 0): file = io.StringIO() else: file = io.BytesIO() with redirect_stdout(file): vult.report( self.conf.as_int("min-confidence"), self.conf.as_bool("sort-by-size"), ) file.seek(0) matches = list(self.patt.finditer(file.read())) self.status_code = 1 if matches else 0 self.hook( list( sorted([x.groupdict() for x in matches], key=lambda x: x["line"])))
def run(self, _): # type: (typing.List[str]) -> None import safety.cli if "requirements.txt" not in os.listdir("."): self.hook([]) return if sys.version_info >= (3, 0, 0): outfile = io.StringIO() else: outfile = io.BytesIO() try: with redirect_stdout(outfile): safety.cli.check.callback( self.conf.get("pyup_key", ''), self.conf.get("db_path", ''), True, False, False, False, False, "requirements.txt", self.conf.as_list("ignore"), "", "http", None, 80, ) except SystemExit: # Raised by safety pass outfile.seek(0) json_data = json.load(outfile) self.status_code = 1 if json_data else 0 self.hook(json_data)
def run(self, _: list) -> None: import requests import twine.commands.upload try: with redirect_stdout(io.StringIO()), \ redirect_stderr(io.StringIO()): proc = subprocess.Popen( # noqa: B603 [sys.executable, "setup.py", "sdist", "bdist_wheel"], stdout=subprocess.DEVNULL) proc.wait() twine.commands.upload.upload( ["dist/*{0}*".format(__version__)], self.conf["TWINE_REPOSITORY"], self.conf.as_bool("sign"), self.conf.get("identity"), self.conf["TWINE_USERNAME"], self.conf["TWINE_PASSWORD"], self.conf.get("comment"), self.conf.get("sign-with"), self.confpath, self.conf.get("skip-existing", True), None, None, None) except requests.exceptions.HTTPError as err: print(err) self.hook([])
def run(self, _): # type: (typing.List[str]) -> None import pytest if sys.version_info >= (3, 0, 0): file = io.StringIO() else: file = io.BytesIO() with redirect_stdout(file): with redirect_stderr(file): exitcode = pytest.main( ["--json=.log.json", "-qqqq", "-c", self.confpath]) self.status_code = exitcode with io.open(".log.json", encoding="utf-8") as file: data = json.load(file) os.remove(".log.json") self.hook([ test for test in data["report"]["tests"] if test["outcome"] == "failed" ])
def run(self, _: list) -> None: file = io.StringIO() with redirect_stdout(file), redirect_stderr(io.StringIO()): # Import pyroma here because it uses logging and sys.stdout import pyroma # noqa pylint: disable=all pyroma.run('directory', '.') file.seek(0) text = file.read() lines = text.split("\n") lines.pop(0) lines.pop(0) data = {'modules': {}} module = lines.pop(0)[6:].strip() data['modules'][module] = [] lines.pop(0) if len(lines) >= 6: line = lines.pop(0) while line != "-" * 30: data['modules'][module].append(line) line = lines.pop(0) rating = lines.pop(0) data['rating'] = int(rating[14:-3]) data['rating_word'] = lines.pop(0) self.status_code = 0 if data['rating'] == 10 else 1 if data['rating'] == 10: data = [] self.hook(data)