Skip to content

Commit 84ca6f9

Browse files
committed
refactored PipAuditException
1 parent 33d92ef commit 84ca6f9

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

exasol/toolbox/nox/_dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def audit(session: Session) -> None:
3535
try:
3636
vulnerabilities = Vulnerabilities.load_from_pip_audit(working_directory=Path())
3737
except PipAuditException as e:
38-
session.error(e.return_code, e.stdout, e.stderr)
38+
session.error(e.returncode, e.stdout, e.stderr)
3939

4040
security_issue_dict = vulnerabilities.security_issue_dict
4141
print(json.dumps(security_issue_dict, indent=2))

exasol/toolbox/util/dependencies/audit.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232

3333
@dataclass
3434
class PipAuditException(Exception):
35-
return_code: int
35+
returncode: int
3636
stdout: str
3737
stderr: str
3838

39-
def __init__(self, subprocess_output: subprocess.CompletedProcess) -> None:
40-
self.return_code = subprocess_output.returncode
41-
self.stdout = subprocess_output.stdout
42-
self.stderr = subprocess_output.stderr
39+
@classmethod
40+
def from_subprocess(cls, proc: subprocess.CompletedProcess) -> PipAuditException:
41+
return cls(proc.returncode, proc.stdout, proc.stderr)
4342

4443

4544
class VulnerabilitySource(str, Enum):
@@ -172,7 +171,7 @@ def audit_poetry_files(working_directory: Path) -> str:
172171
cwd=working_directory,
173172
) # nosec
174173
if output.returncode != 0:
175-
raise PipAuditException(subprocess_output=output)
174+
raise PipAuditException.from_subprocess(output)
176175

177176
with tempfile.TemporaryDirectory() as path:
178177
tmpdir = Path(path)
@@ -192,7 +191,7 @@ def audit_poetry_files(working_directory: Path) -> str:
192191
# they both map to returncode = 1, so we have our own logic to raise errors
193192
# for the case of 2) and not 1).
194193
if not search(PIP_AUDIT_VULNERABILITY_PATTERN, output.stderr.strip()):
195-
raise PipAuditException(subprocess_output=output)
194+
raise PipAuditException.from_subprocess(output)
196195
return output.stdout
197196

198197

0 commit comments

Comments
 (0)