swh.loader.package.crates.loader module#

class swh.loader.package.crates.loader.CratesPackageInfo(url: str, filename: str | None, name: str, version: str, sha256: str, last_update: datetime, *, directory_extrinsic_metadata: List[RawExtrinsicMetadataCore] = [], checksums: Dict[str, str] = {})[source]#

Bases: BasePackageInfo

Method generated by attrs for class CratesPackageInfo.

name#

Name of the package

version#

Current version

sha256#

Extid as sha256

last_update#

Last update as release date

MANIFEST_FORMAT: Template | None = <string.Template object>#

If not None, used by the default extid() implementation to format a manifest, before hashing it to produce an ExtID.

EXTID_TYPE: str = 'crates-manifest-sha256'#
EXTID_VERSION: int = 0#
swh.loader.package.crates.loader.extract_intrinsic_metadata(dir_path: Path) Dict[str, Any][source]#

Extract intrinsic metadata from Cargo.toml file at dir_path.

Each crate archive has a Cargo.toml at the root of the archive.

Parameters:

dir_path – A directory on disk where a Cargo.toml must be present

Returns:

A dict mapping from toml parser

class swh.loader.package.crates.loader.CratesLoader(storage: StorageInterface, url: str, artifacts: List[Dict[str, Any]], **kwargs)[source]#

Bases: PackageLoader[CratesPackageInfo]

Load Crates package origins into swh archive.

Constructor

Parameters:
  • url – Origin url, (e.g. https://crates.io/crates/<package_name>)

  • artifacts

    A list of dict listing all existing released versions for a package (Usually set with crates lister extra_loader_arguments). Each line is a dict that should have an url (where to download package specific version), a version, a filename and a checksums[‘sha256’] entry.

    Example:

    [
        {
            "version": <version>,
            "url": "https://static.crates.io/crates/<package_name>/<package_name>-<version>.crate",
            "filename": "<package_name>-<version>.crate",
            "checksums": {
                "sha256": "<sha256>",
            },
        }
    ]
    

visit_type: str = 'crates'#
CRATE_API_URL_PATTERN = 'https://crates.io/api/v1/crates/{crate}'#
crate_extrinsic_medata() Dict[str, Dict[str, Any]][source]#
get_versions() Sequence[str][source]#

Get all released versions of a crate

Returns:

A sequence of versions

Example:

["0.1.1", "0.10.2"]

get_metadata_authority()[source]#

For package loaders that get extrinsic metadata, returns the authority the metadata are coming from.

get_package_info(version: str) Iterator[Tuple[str, CratesPackageInfo]][source]#

Get release name and package information from version

Parameters:

version – crate version (e.g: “0.1.0”)

Returns:

Iterator of tuple (release_name, p_info)

build_release(p_info: CratesPackageInfo, uncompressed_path: str, directory: bytes) Release | None[source]#

Build the release from the archive metadata (extrinsic artifact metadata) and the intrinsic metadata.

Parameters:
  • p_info – Package information

  • uncompressed_path – Artifact uncompressed path on disk