swh.loader.package.opam.loader module#

class swh.loader.package.opam.loader.OpamPackageInfo(url: str, filename: Optional[str], version: str, author: Person, committer: Person, *, directory_extrinsic_metadata: List[RawExtrinsicMetadataCore] = [], checksums: Dict[str, str] = {})[source]#

Bases: BasePackageInfo

Method generated by attrs for class OpamPackageInfo.

swh.loader.package.opam.loader.opam_read(cmd: List[str], init_error_msg_if_any: Optional[str] = None) Optional[str][source]#

This executes an opam command and returns the first line of the output.

Parameters:
  • cmd – Opam command to execute as a list of string

  • init_error_msg_if_any – Error message to raise in case a problem occurs during initialization

Raises:
  • ValueError with the init_error_msg_if_any content in case stdout is not

  • consumable and the variable is provided with non empty value.

Returns:

the first line of the executed command output

class swh.loader.package.opam.loader.OpamLoader(storage: StorageInterface, url: str, opam_root: str, opam_instance: str, opam_url: str, opam_package: str, initialize_opam_root: bool = False, **kwargs: Any)[source]#

Bases: PackageLoader[OpamPackageInfo]

Load all versions of a given package in a given opam repository.

The state of the opam repository is stored in a directory called an opam root. This folder is a requisite for the opam binary to actually list information on package.

When initialize_opam_root is False (the default for production workers), the opam root must already have been configured outside of the loading process. If not an error is raised, thus failing the loading.

For standalone workers, initialize_opam_root must be set to True, so the ingestion can take care of installing the required opam root properly.

The remaining ingestion uses the opam binary to give the versions of the given package. Then, for each version, the loader uses the opam binary to list the tarball url to fetch and ingest.

Loader’s constructor. This raises exception if the minimal required

configuration is missing (cf. fn:check method).

Parameters:
  • storage – Storage instance

  • url – Origin url to load data from

visit_type: str = 'opam'#
get_package_dir() str[source]#
get_package_name(version: str) str[source]#
get_package_file(version: str) str[source]#
get_metadata_authority()[source]#

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

get_versions() List[str][source]#

First initialize the opam root directory if needed then start listing the package versions.

Raises:
  • ValueError in case the lister is not able to determine the list of

  • versions or if the opam root directory is invalid.

get_default_version() str[source]#

Return the most recent version of the package as default.

get_enclosed_single_line_field(field, version) Optional[str][source]#
get_package_info(version: str) Iterator[Tuple[str, OpamPackageInfo]][source]#
Given a release version of a package, retrieve the associated

package information for such version.

Parameters:

version – Package version

Returns:

(branch name, package metadata)

build_release(p_info: OpamPackageInfo, uncompressed_path: str, directory: bytes) Optional[Release][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

origin: Origin#
loaded_snapshot_id: Optional[bytes]#
parent_origins: Optional[List[Origin]]#

If the given origin is a “forge fork” (ie. created with the “Fork” button of GitHub-like forges), build_extrinsic_origin_metadata() sets this to a list of origins it was forked from; closest parent first.