from __future__ import annotations from pathlib import Path try: import pyzipper except ImportError: # pragma: no cover pyzipper = None def create_encrypted_zip(output_path: Path, files: list[Path], password: str) -> Path: output_path.parent.mkdir(parents=True, exist_ok=True) if pyzipper is None: raise RuntimeError("pyzipper is required for writing encrypted ZIP files") with pyzipper.AESZipFile( output_path, "w", compression=pyzipper.ZIP_DEFLATED, encryption=pyzipper.WZ_AES, ) as zip_file: if password: zip_file.setpassword(password.encode("utf-8")) for file_path in files: zip_file.write(file_path, arcname=file_path.name) return output_path