Check Python code with flake8 or similar.
(self)
| 140 | return False, "", str(e) |
| 141 | |
| 142 | def _check_python_linting(self) -> Tuple[bool, str, Optional[str]]: |
| 143 | """Check Python code with flake8 or similar.""" |
| 144 | try: |
| 145 | # Try flake8 first |
| 146 | python_path = shutil.which("python") |
| 147 | if not python_path: |
| 148 | raise FileNotFoundError("python executable not found in PATH") |
| 149 | result = subprocess.run([python_path, "-m", "flake8", "python/", "scripts/"], capture_output=True, text=True, cwd=self.root_path, timeout=120, shell=False) # nosec |
| 150 | |
| 151 | return result.returncode == 0, result.stdout, result.stderr if result.returncode != 0 else None |
| 152 | |
| 153 | except subprocess.TimeoutExpired: |
| 154 | return False, "", "Python linting check timed out" |
| 155 | except FileNotFoundError: |
| 156 | # If flake8 is not available, try pylint or skip |
| 157 | try: |
| 158 | python_path = shutil.which("python") |
| 159 | if not python_path: |
| 160 | raise FileNotFoundError("python executable not found in PATH") |
| 161 | result = subprocess.run([python_path, "-m", "pylint", "python/", "scripts/"], capture_output=True, text=True, cwd=self.root_path, timeout=180, shell=False) # nosec |
| 162 | |
| 163 | # Pylint returns non-zero for warnings, so we're more lenient |
| 164 | return result.returncode < 16, result.stdout, result.stderr if result.returncode >= 16 else None |
| 165 | |
| 166 | except FileNotFoundError: |
| 167 | return True, "No Python linter available, skipping Python linting check", None |
| 168 | except Exception as e: |
| 169 | return False, "", str(e) |
| 170 | |
| 171 | def _run_security_scan(self) -> Tuple[bool, str, Optional[str]]: |
| 172 | """Run security scans.""" |