| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import TYPE_CHECKING |
| 4 |
|
| 5 |
from auditwheel.condatools import InCondaPkgCtx |
| 6 |
from auditwheel.wheeltools import InWheelCtx |
| 7 |
|
| 8 |
if TYPE_CHECKING: |
| 9 |
from pathlib import Path |
| 10 |
|
| 11 |
|
| 12 |
def InGenericPkgCtx( # noqa: N802 |
| 13 |
in_path: Path, |
| 14 |
out_path: Path | None = None, |
| 15 |
) -> InWheelCtx | InCondaPkgCtx: |
| 16 |
"""Factory that returns a InWheelCtx or InCondaPkgCtx |
| 17 |
context manager depending on the file extension |
| 18 |
""" |
| 19 |
if in_path.name.endswith(".whl"): |
| 20 |
return InWheelCtx(in_path, out_path) |
| 21 |
if in_path.name.endswith(".tar.bz2"): |
| 22 |
if out_path is not None: |
| 23 |
raise NotImplementedError |
| 24 |
return InCondaPkgCtx(in_path) |
| 25 |
msg = f"Invalid package: {in_path}. File formats supported: .whl, .tar.bz2" |
| 26 |
raise ValueError(msg) |