Coverage for src / mafw / devtools / dependencies / audit.py: 100%
8 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-06-28 13:34 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-06-28 13:34 +0000
1# Copyright 2026 European Union
2# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
3# SPDX-License-Identifier: EUPL-1.2
4"""
5Dependency auditing utilities for MAFw.
7This module provides functions for running pip-audit against compiled
8requirement files.
9"""
11from __future__ import annotations
13import subprocess
14from pathlib import Path
15from typing import Any
17from mafw.tools.shell_tools import run as cmd
20def run_pip_audit(
21 req_file: Path,
22 output_file: Path,
23 output_format: str,
24) -> subprocess.CompletedProcess[Any]:
25 """
26 Run pip-audit on a requirements file and save the output.
28 :param req_file: Requirements file to audit.
29 :type req_file: Path
30 :param output_file: Path to the output report.
31 :type output_file: Path
32 :param output_format: Format of the report (e.g. 'markdown', 'json').
33 :type output_format: str
34 :return: Completed process produced by the command execution.
35 :rtype: subprocess.CompletedProcess[Any]
36 """
37 cmd_parts = [
38 'pip-audit',
39 '-r',
40 str(req_file),
41 '--format',
42 output_format,
43 '-o',
44 str(output_file),
45 '--disable-pip',
46 ]
47 return cmd(cmd_parts, check=False)