pkgcraft package

Subpackages

Submodules

pkgcraft.config module

class pkgcraft.config.Config

Bases: object

Config for the system.

On instance creation, no system config is automatically loaded.

add_repo(self, repo, id=None, priority=0, external=True)

Add a repo via its file path or from a Repo object and return the Repo object.

Parameters:
  • repo (str | Repo) – path to a repo or a repo object

  • id (str | None) – repo identifier, if None the path is used

  • priority (int) – repo priority

  • external (bool) – repo is external from the system config

Returns:

the repo object (subclassed to its format) added to the config

Return type:

Repo

Raises:
load(self)

Load pkgcraft config files, if none are found revert to loading portage files.

Raises:

PkgcraftError – on config loading failures

load_portage_conf(self, path=None)

Load portage config files from a given directory, falling back to default locations.

Parameters:

path (str) – path to the portage config directory to load, by default the standard locations are used

Raises:

PkgcraftError – on config loading failures

repos

Return the config’s repo mapping.

Return type:

Repos

class pkgcraft.config.Repos

Bases: Indirect

Wrapper for all known repos.

all

Return the set of all repos.

Return type:

RepoSet

configured

Return the set of all configured repos.

Return type:

RepoSet

ebuild

Return the set of all ebuild repos.

Return type:

RepoSet

get(self, key, default=None)

Get the repo associated with a given key.

Parameters:

default – fallback value when no matching key exists

Returns:

the repo object if it exists, otherwise the fallback value

Return type:

Repo | None

pkgcraft.eapi module

class pkgcraft.eapi.Eapi

Bases: Indirect

dep_keys

Get an EAPI’s dependency keys.

static from_obj(obj)

Try to convert an object to an Eapi object.

has(s)

Check if an EAPI has a given feature.

See https://docs.rs/pkgcraft/latest/pkgcraft/eapi/enum.Feature.html for the full list of supported EAPI features.

existing feature:

>>> from pkgcraft.eapi import EAPI_LATEST_OFFICIAL
>>> EAPI_LATEST_OFFICIAL.has('UsevTwoArgs')
True

feature not existing in official EAPIs:

>>> EAPI_LATEST_OFFICIAL.has('RepoIds')
False

nonexistent feature:

>>> EAPI_LATEST_OFFICIAL.has('nonexistent')
False
metadata_keys

Get an EAPI’s metadata keys.

static parse(s, raised=False)

Determine if a string is a valid EAPI.

This avoids any string allocations, only returning the validity status.

Parameters:
  • s (str) – the string to parse

  • raised – if True, raise an exception when invalid

Returns:

True if the given string represents a valid EAPI, otherwise False.

Return type:

bool

Raises:

PkgcraftError – on failure if the raised parameter is set to True

>>> from pkgcraft.eapi import Eapi
>>> Eapi.parse('01')
True
>>> Eapi.parse('@1')
False
pkgcraft.eapi.eapi_range(s)

Convert EAPI range into an ordered set of Eapi objects.

>>> from pkgcraft.eapi import *
>>> eapi_range('..') == set(EAPIS.values())
True
>>> eapi_range('..6') == {EAPI5}
True
>>> eapi_range('..=6') == {EAPI5, EAPI6}
True
>>> eapi_range('7..8') == {EAPI7}
True
>>> eapi_range('8..8') == set()
True
>>> eapi_range('7..=8') == {EAPI7, EAPI8}
True
>>> eapi_range('..9999')
Traceback (most recent call last):
    ...
pkgcraft.error.PkgcraftError: invalid EAPI range: ..9999

pkgcraft.error module

exception pkgcraft.error.ConfigError(msg=None, **kwargs)

Bases: PkgcraftError

Generic configuration exception.

class pkgcraft.error.Indirect(*args, **kwargs)

Bases: object

Instances cannot be directly created.

__init__(*args, **kwargs)
exception pkgcraft.error.IndirectType

Bases: TypeError

Object type instances cannot be directly created.

exception pkgcraft.error.InvalidCpn(msg=None, **kwargs)

Bases: PkgcraftError, ValueError

Cpn doesn’t meet required specifications.

exception pkgcraft.error.InvalidCpv(msg=None, **kwargs)

Bases: PkgcraftError, ValueError

Cpv doesn’t meet required specifications.

exception pkgcraft.error.InvalidDep(msg=None, **kwargs)

Bases: PkgcraftError, ValueError

Package dependency doesn’t meet required specifications.

exception pkgcraft.error.InvalidPkg(msg=None, **kwargs)

Bases: PkgcraftError

Package doesn’t meet required specifications.

exception pkgcraft.error.InvalidRepo(msg=None, **kwargs)

Bases: PkgcraftError

Repo doesn’t meet required specifications.

exception pkgcraft.error.InvalidRestrict(msg=None, **kwargs)

Bases: PkgcraftError, ValueError

Object cannot be converted to a restriction.

exception pkgcraft.error.InvalidVersion(msg=None, **kwargs)

Bases: PkgcraftError, ValueError

Package version doesn’t meet required specifications.

exception pkgcraft.error.PkgcraftError(msg=None, **kwargs)

Bases: _PkgcraftError, Exception

Generic pkgcraft exception.

__init__(self, *args)

pkgcraft.logging module

class pkgcraft.logging.PkgcraftLogger(name, level=0)

Bases: Logger

Custom logger that supports switching pkgcraft log levels.

setLevel(self, level)

pkgcraft.parse module

pkgcraft.parse.category(s, raised=False)

Determine if a string is a valid category name.

pkgcraft.parse.package(s, raised=False)

Determine if a string is a valid package name.

pkgcraft.parse.repo(s, raised=False)

Determine if a string is a valid repo name.

pkgcraft.parse.use_flag(s, raised=False)

Determine if a string is a valid USE flag name.

pkgcraft.restrict module

class pkgcraft.restrict.Restrict(obj)

Bases: object

Generic restriction.

__init__(*args, **kwargs)
static dep(s)

Convert a string into a dependency-based restriction.

matches(self, obj)

Determine if a restriction matches a given object.

Returns True if the restriction matches a given object, otherwise False.

Raises TypeError for object types not supporting matches.

static pkg(s)

Convert a string into a package-based restriction.

Module contents