| 1 |
"""Context managers like those in wheeltools.py for unpacking |
| 2 |
conda packages. |
| 3 |
""" |
| 4 |
|
| 5 |
from __future__ import annotations |
| 6 |
|
| 7 |
from typing import TYPE_CHECKING |
| 8 |
|
| 9 |
from auditwheel.tmpdirs import InTemporaryDirectory |
| 10 |
from auditwheel.tools import tarbz2todir |
| 11 |
|
| 12 |
if TYPE_CHECKING: |
| 13 |
from pathlib import Path |
| 14 |
|
| 15 |
|
| 16 |
class InCondaPkg(InTemporaryDirectory): |
| 17 |
def __init__(self, in_conda_pkg: Path) -> None: |
| 18 |
"""Initialize in-conda-package context manager""" |
| 19 |
self.in_conda_pkg = in_conda_pkg.absolute() |
| 20 |
super().__init__() |
| 21 |
|
| 22 |
def __enter__(self) -> Path: |
| 23 |
tarbz2todir(self.in_conda_pkg, self.name) |
| 24 |
return super().__enter__() |
| 25 |
|
| 26 |
|
| 27 |
class InCondaPkgCtx(InCondaPkg): |
| 28 |
def __init__(self, in_conda_pkg: Path) -> None: |
| 29 |
super().__init__(in_conda_pkg) |
| 30 |
self.path: Path | None = None |
| 31 |
|
| 32 |
def __enter__(self): # type: ignore[no-untyped-def] |
| 33 |
self.path = super().__enter__() |
| 34 |
return self |
| 35 |
|
| 36 |
def iter_files(self) -> list[str]: |
| 37 |
if self.path is None: |
| 38 |
msg = "This function should be called from context manager" |
| 39 |
raise ValueError(msg) |
| 40 |
files = self.path / "info" / "files" |
| 41 |
with files.open() as f: |
| 42 |
return [line.strip() for line in f.readlines()] |