Skip to content

package

Classes:

Name Description
PackageInfo

Package information relevant to decide for deletion

PackageInfoCollection

Collection of PackageInfo to store for instance a entire channel packages information

Functions:

Name Description
parse_repodata

Parses the reodata dictionary into a ChannelPackages

PackageInfo dataclass

Package information relevant to decide for deletion

The package information are typically retrieved from the repodata.json index file of a conda channel repository

Attributes:

Name Type Description
filename str

Filename of the package in the channel (key of the package map in repodata.json). Typically of the form "{project_name}-[branch_name}-{package_hash}_{package_build_number}.conda"

name str

The name of the package (the name used to install the package with eg pixi) "{project_name}"

upload_time datetime

Time of the package upload to the channel (unix time)

version str

Version associated to the package. For instance "v1.0.0" but can be any string

Source code in src/phoenixpackagecleanup/package.py
@dataclass
class PackageInfo:
    """Package information relevant to decide for deletion

    The package information are typically retrieved from the `repodata.json` index file of a conda channel repository

    Attributes
    ----------
    filename : str
        Filename of the package in the channel (key of the package map in `repodata.json`). Typically of the form
        "{project_name}-[branch_name}-{package_hash}_{package_build_number}.conda"
    name : str
        The name of the package (the name used to install the package with eg pixi) "{project_name}"
    upload_time : datetime
        Time of the package upload to the channel (unix time)
    version : str
        Version associated to the package. For instance "v1.0.0" but can be any string
    """

    filename: str
    name: str
    upload_time: datetime
    version: str

PackageInfoCollection dataclass

Collection of PackageInfo to store for instance a entire channel packages information

The class groups the packages per channel-name

Attributes:

Name Type Description
packages dict[str, list[PackageInfo]]

Dictionary with keys the package name (as used to download the package from channel) and values a list of PackageInfo for each package archive in the channel.

Source code in src/phoenixpackagecleanup/package.py
@dataclass
class PackageInfoCollection:
    """Collection of PackageInfo to store for instance a entire channel packages information

    The class groups the packages per channel-name

    Attributes
    ----------
    packages: dict[str, list[PackageInfo]]
        Dictionary with keys the package name (as used to download the package from channel) and values
        a list of PackageInfo for each package archive in the channel.
    """

    packages_info: dict[str, list[PackageInfo]]

parse_repodata

parse_repodata(repodata)

Parses the reodata dictionary into a ChannelPackages

Parameters:

Name Type Description Default
repodata dict

repodata.json content loaded as a dict

required

Returns:

Type Description
ChannelPackages

Packages available in the channel

Source code in src/phoenixpackagecleanup/package.py
def parse_repodata(repodata: dict) -> PackageInfoCollection:
    """Parses the reodata dictionary into a `ChannelPackages`

    Parameters
    ----------
    repodata : dict
        repodata.json content loaded as a dict

    Returns
    -------
    ChannelPackages
        Packages available in the channel
    """
    # defaultdict(list) allows to create an empty list using dict["missing_key"] so we can append to the list directly
    packages = defaultdict(list)
    # conda channels can have either ".tar.gz" archives in "packages" or ".conda" packages in "packages.conda"
    for packages_dict in [repodata["packages"], repodata["packages.conda"]]:
        for package_filename, package_info in packages_dict.items():
            packages[package_info["name"]].append(
                PackageInfo(
                    filename=package_filename,
                    name=package_info["name"],
                    upload_time=datetime.fromtimestamp(package_info["timestamp"] / 1000, timezone.utc),
                    version=package_info["version"],
                )
            )
    return PackageInfoCollection(dict(packages))