def _run_xsoar_linter(self, py_num: float, lint_files: List[Path]) -> Tuple[int, str]: """ Runs Xsaor linter in pack dir Args: lint_files(List[Path]): file to perform lint Returns: int: 0 on successful else 1, errors str: Xsoar linter errors """ status = SUCCESS FAIL_PYLINT = 0b10 with pylint_plugin(self._pack_abs_dir): log_prompt = f"{self._pack_name} - XSOAR Linter" logger.info(f"{log_prompt} - Start") myenv = os.environ.copy() if myenv.get('PYTHONPATH'): myenv['PYTHONPATH'] += ':' + str(self._pack_abs_dir) else: myenv['PYTHONPATH'] = str(self._pack_abs_dir) if self._facts['is_long_running']: myenv['LONGRUNNING'] = 'True' if py_num < 3: myenv['PY2'] = 'True' stdout, stderr, exit_code = run_command_os( command=build_xsoar_linter_command( lint_files, py_num, self._facts.get('support_level', 'base')), cwd=self._pack_abs_dir, env=myenv) if exit_code & FAIL_PYLINT: logger.info(f"{log_prompt}- Finished errors found") status = FAIL if exit_code & WARNING: logger.info(f"{log_prompt} - Finished warnings found") if not status: status = WARNING # if pylint did not run and failure exit code has been returned from run commnad elif exit_code & FAIL: status = FAIL # for contrib prs which are not merged from master and do not have pylint in dev-requirements-py2. if os.environ.get('CI'): stdout = "Xsoar linter could not run, Please merge from master" else: stdout = "Xsoar linter could not run, please make sure you have" \ " the necessary Pylint version for both py2 and py3" logger.info(f"{log_prompt}- Finished errors found") logger.debug(f"{log_prompt} - Finished exit-code: {exit_code}") logger.debug( f"{log_prompt} - Finished stdout: {RL if stdout else ''}{stdout}") logger.debug( f"{log_prompt} - Finished stderr: {RL if stderr else ''}{stderr}") if not exit_code: logger.info(f"{log_prompt} - Successfully finished") return status, stdout
def test_build_xsoar_linter_no_base_command(files): """Build xsoar linter command""" from demisto_sdk.commands.lint.commands_builder import build_xsoar_linter_command output = build_xsoar_linter_command(files, 2.7, "unsupported") files = [str(file) for file in files] expected = f"python2 -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ f"conftest.py,venv -E --disable=all --enable= {' '.join(files)}" assert output == expected
def test_build_xsoar_linter_py2_command(files): """Build xsoar linter command""" from demisto_sdk.commands.lint.commands_builder import build_xsoar_linter_command output = build_xsoar_linter_command(files, 2.7, "base") files = [str(file) for file in files] expected = f"python2 -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ "conftest.py,venv -E --disable=all --enable=E9002,E9003,E9004,E9005, --load-plugins " \ f"base_checker, {' '.join(files)}" assert output == expected
def test_build_xsoar_linter_no_base_command(files): """Build xsoar linter command""" from demisto_sdk.commands.lint.commands_builder import \ build_xsoar_linter_command output = build_xsoar_linter_command(files, '2.7', "unsupported") files = [str(file) for file in files] expected = "python2 -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ "conftest.py,venv -E --disable=all --msg-template='{abspath}:{line}:{column}: {msg_id} {obj}: {msg}' " \ f"--enable= {' '.join(files)}" assert output == expected
def test_build_xsoar_linter_py3_command(files): """Build xsoar linter command""" from demisto_sdk.commands.lint.commands_builder import build_xsoar_linter_command output = build_xsoar_linter_command(files, 3.8, "base") files = [str(file) for file in files] expected = f"python3 -m pylint --ignore=CommonServerPython.py,demistomock.py,CommonServerUserPython.py," \ "conftest.py,venv -E --disable=all --msg-template='{abspath}:{line}:{column}: {msg_id} {obj}: {msg}'" \ " --enable=E9002,E9003,E9004,E9005,E9006,E9007,E9010, --load-plugins " \ f"base_checker, {' '.join(files)}" assert output == expected