# Copyright 2026 European Union
# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
# SPDX-License-Identifier: EUPL-1.2
"""
Dependency auditing utilities for MAFw.
This module provides functions for running pip-audit against compiled
requirement files.
"""
from __future__ import annotations
import subprocess
from pathlib import Path
from typing import Any
from mafw.tools.shell_tools import run as cmd
[docs]
def run_pip_audit(
req_file: Path,
output_file: Path,
output_format: str,
) -> subprocess.CompletedProcess[Any]:
"""
Run pip-audit on a requirements file and save the output.
:param req_file: Requirements file to audit.
:type req_file: Path
:param output_file: Path to the output report.
:type output_file: Path
:param output_format: Format of the report (e.g. 'markdown', 'json').
:type output_format: str
:return: Completed process produced by the command execution.
:rtype: subprocess.CompletedProcess[Any]
"""
cmd_parts = [
'pip-audit',
'-r',
str(req_file),
'--format',
output_format,
'-o',
str(output_file),
'--disable-pip',
]
return cmd(cmd_parts, check=False)