craft_parts.packages.base module

Definition and helpers for the repository base class.

class craft_parts.packages.base.BaseRepository[source]

Bases: ABC

Base implementation for a platform specific repository handler.

abstract classmethod configure(application_package_name)[source]

Set up the repository.

Parameters:

application_package_name (str) –

Return type:

None

abstract classmethod download_packages(package_names)[source]

Download the specified packages to the local package cache.

Parameters:

package_names (List[str]) – A list with the names of the packages to download.

Return type:

None

abstract classmethod fetch_stage_packages(*, cache_dir, package_names, stage_packages_path, base, arch, list_only=False)[source]

Fetch stage packages to stage_packages_path.

Parameters:
  • application_name – A unique identifier for the application using Craft Parts.

  • package_names (List[str]) – A list with the names of the packages to fetch.

  • base (str) – The base this project will run on.

  • arch (str) – The architecture of the packages to fetch.

  • list_only (bool) – Whether to obtain a list of packages to be fetched instead of actually fetching the packages.

  • cache_dir (Path) –

  • stage_packages_path (Path) –

Stage_packages_path:

The path stage packages will be fetched to.

Return type:

List[str]

Returns:

The list of all packages to be fetched, including dependencies.

abstract classmethod get_installed_packages()[source]

Obtain a list of the installed packages and their versions.

Return type:

List[str]

Returns:

A list of installed packages in the form package=version.

abstract classmethod get_package_libraries(package_name)[source]

Return a list of libraries in package_name.

Given the contents of package_name, return the subset of what are considered libraries from those contents, be it static or shared.

Parameters:

package_name (str) – The package name to get library contents from.

Return type:

Set[str]

Returns:

A list of libraries that package_name provides, with paths.

abstract classmethod get_packages_for_source_type(source_type)[source]

Return a list of packages required to to work with source_type.

Parameters:

source_type (str) – A source type to handle.

Return type:

Set[str]

Returns:

A set of packages that need to be installed on the host.

abstract classmethod install_packages(package_names, *, list_only=False, refresh_package_cache=True)[source]

Install packages on the host system.

This method needs to be implemented by using the appropriate mechanism to install packages on the system. If possible they should be marked as automatically installed to allow for easy removal. The method should return a list of the actually installed packages in the form “package=version”.

If one of the packages cannot be found BuildPackageNotFound should be raised. If dependencies for a package cannot be resolved PackageBroken should be raised. If installing a package on the host failed BuildPackagesNotInstalled should be raised.

Parameters:
  • package_names (List[str]) – A list of package names to install.

  • list_only (bool) – Only list the packages that would be installed.

  • refresh_package_cache (bool) – Refresh the cache before installing.

Return type:

List[str]

Returns:

A list with the packages installed and their versions.

abstract classmethod is_package_installed(package_name)[source]

Inform if a package is installed on the host system.

Parameters:

package_name (str) – The package name to query.

Return type:

bool

Returns:

Whether the package is installed.

abstract classmethod refresh_packages_list()[source]

Refresh the list of packages available in the repository.

If refreshing is not possible PackageListRefreshError should be raised.

Return type:

None

stage_packages_filters: Optional[Set[str]] = None
abstract classmethod unpack_stage_packages(*, stage_packages_path, install_path, stage_packages=None, track_stage_packages=False)[source]

Unpack stage packages.

Parameters:
  • stage_packages_path (Path) – The path to the directory containing the stage packages to unpack.

  • install_path (Path) – The path stage packages will be unpacked to.

  • stage_packages (Optional[List[str]]) – An optional list of the packages that were previously pulled.

  • track_stage_packages (bool) –

Return type:

None

class craft_parts.packages.base.DummyRepository[source]

Bases: BaseRepository

A dummy repository.

classmethod configure(application_package_name)[source]

Set up the repository.

Parameters:

application_package_name (str) –

Return type:

None

classmethod download_packages(package_names)[source]

Download the specified packages to the local package cache.

Parameters:

package_names (List[str]) –

Return type:

None

classmethod fetch_stage_packages(**kwargs)[source]

Fetch stage packages to stage_packages_path.

Parameters:

kwargs (Any) –

Return type:

List[str]

classmethod get_installed_packages()[source]

Obtain a list of the installed packages and their versions.

Return type:

List[str]

classmethod get_package_libraries(package_name)[source]

Return a list of libraries in package_name.

Parameters:

package_name (str) –

Return type:

Set[str]

classmethod get_packages_for_source_type(source_type)[source]

Return a list of packages required to to work with source_type.

Parameters:

source_type (str) –

Return type:

Set[str]

classmethod install_packages(package_names, *, list_only=False, refresh_package_cache=True)[source]

Install packages on the host system.

Parameters:
  • package_names (List[str]) –

  • list_only (bool) –

  • refresh_package_cache (bool) –

Return type:

List[str]

classmethod is_package_installed(package_name)[source]

Inform if a packahe is installed on the host system.

Parameters:

package_name (str) –

Return type:

bool

classmethod refresh_packages_list()[source]

Refresh the build packages cache.

Return type:

None

classmethod unpack_stage_packages(*, stage_packages_path, install_path, stage_packages=None, track_stage_packages=False)[source]

Unpack stage packages to install_path.

Parameters:
  • stage_packages_path (Path) –

  • install_path (Path) –

  • stage_packages (Optional[List[str]]) –

  • track_stage_packages (bool) –

Return type:

None

craft_parts.packages.base.get_pkg_name_parts(pkg_name)[source]

Break package name into base parts.

Parameters:

pkg_name (str) –

Return type:

Tuple[str, Optional[str]]

craft_parts.packages.base.mark_origin_stage_package(sources_dir, stage_package)[source]

Mark all files in sources_dir as coming from stage_package.

Parameters:
  • sources_dir (str) –

  • stage_package (str) –

Return type:

None

craft_parts.packages.base.read_origin_stage_package(path)[source]

Read origin stage package.

Parameters:

path (str) –

Return type:

Optional[str]

craft_parts.packages.base.write_origin_stage_package(path, value)[source]

Write origin stage package.

Parameters:
  • path (str) –

  • value (str) –

Return type:

None