42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
"""Python dependencies used by the helper; optional cover tagging is excluded."""
|
|
from __future__ import annotations
|
|
|
|
import importlib.metadata
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
def requirements(yt_dlp="yt-dlp>=2026.8.19", ejs="yt-dlp-ejs"):
|
|
return [yt_dlp, ejs, "brotli", "certifi", "pycryptodomex",
|
|
"requests>=2.32.2,<3", "urllib3>=2,<3", "websockets>=13"]
|
|
|
|
|
|
def validate_metadata(records):
|
|
"""Reject strong copyleft Python libraries before activating a bundle.
|
|
|
|
FFmpeg is a separately executed program, so this policy concerns Python
|
|
libraries loaded into the helper process, not the FFmpeg distribution.
|
|
"""
|
|
for metadata in records:
|
|
name = re.sub(r"[-_.]+", "-", metadata.get("name", "").lower())
|
|
licenses = [metadata.get("license_expression") or "", metadata.get("license") or "",
|
|
*metadata.get("classifier", [])]
|
|
incompatible = name == "mutagen" or any(
|
|
re.search(r"(?<![A-Z])(?:A?GPL)(?:[-\s\dv]|$)|GNU (?:Affero )?General Public License",
|
|
license, re.IGNORECASE) for license in licenses)
|
|
if incompatible:
|
|
raise ValueError(f"Python-пакет {name} требует отдельной проверки совместимости лицензии; комплект не изменён.")
|
|
|
|
|
|
def validate_installed(directory: Path):
|
|
records = []
|
|
for distribution in importlib.metadata.distributions(path=[str(directory)]):
|
|
metadata = distribution.metadata
|
|
records.append({"name": metadata.get("Name", ""),
|
|
"license_expression": metadata.get("License-Expression", ""),
|
|
"license": metadata.get("License", ""),
|
|
"classifier": metadata.get_all("Classifier") or []})
|
|
validate_metadata(records)
|
|
return {distribution.metadata["Name"]: distribution.version
|
|
for distribution in importlib.metadata.distributions(path=[str(directory)])}
|