pkgbuilder API

aur module

class pkgbuilder.aur.Aur(url='https://aur.archlinux.org')

Wrapper around the AUR RPC interface with caching for package info. See https://aur.archlinux.org/rpc.php.

Parameters

url – URL providing the RPC interface, defaults to https://aur.archlinux.org

get_package(name)

Get an AurPackage that can be downloaded.

Parameters

name – Name of the AUR package

Returns

an AurPackage or None if name is not found

info(name)

Get info about an AUR package.

Parameters

name – Name of the AUR package

Returns

Package info or None if name is not found

infos(*names)

Get info about AUR packages.

Parameters

names – Positional arguments specifying package names

Returns

A dictionary mapping names to info

class pkgbuilder.aur.AurPackage(info, url)

A package found on the AUR that can be downloaded or cloned via git.

Parameters
  • info – Package info

  • url – URL to the AUR interface

download(dest)

Download and extract package snapshot to given destination.

Parameters

dest – Extraction destination

git_clone(dest)

Clone the AUR package’s git repository to given destination.

Parameters

dest – Local repository destination

Raises
  • FileExistsError – Raised if the destination already exists

  • CalledProcessError – Raised if the git command fails

class pkgbuilder.aur.GitRepo(path)

A local git repository.

Parameters

path – Path to local repository

clone(url)

Clone a git repository to self.path.

Parameters

url – Git repository URL

Raises
  • FileExistsError – Raised if self.path already exists

  • CalledProcessError – Raised if the git command fails

pull()

Run git pull in this repository.

Raises

CalledProcessError – Raised if the git command fails

builder module

class pkgbuilder.builder.Builder(name, pacman_conf='/etc/pacman.conf', makepkg_conf='/etc/makepkg.conf', builddir='/var/cache/pkgbuilder', chrootdir='/var/lib/pkgbuilder', localdir=None, source=None)

A package builder.

Parameters
  • name – Name of the package to build

  • pacman_conf – Path to pacman configuration file

  • makepkg_conf – Path to makepkg configuration file

  • builddir – Path to package build directory

  • chrootdir – Path to chroot directory

  • localdir – Path to directory of local PKGBUILDs

  • source – PKGBUILD source - one of Pkgbuild.Source.Local or Pkgbuild.Source.Aur

build(rebuild=False)

Build the package.

Parameters

rebuild – Build packages even if they exist

Returns

A list of paths to all built packages

install(reinstall=False, sysroot=None, confirm=False)

Install built packages, building if necessary.

Parameters
  • reinstall – Reinstall installed packages if True, defaults to False

  • sysroot – An alternative system root

  • confirm – Prompt to install if True, defaults to False

Returns

A list of paths to all built packages

class pkgbuilder.builder.Manifest(pkgbuilddir)

The build manifest records built packages and dependencies.

Parameters

pkgbuilddir – Path to PKGBUILD directory

property all_packages

A set of paths to all built packages (including dependencies).

Returns

A set of paths to all built packages

exists()

Check if the manifest file exists.

Returns

True if exists, False otherwise

install(reinstall=False, pacman_conf=None, sysroot=None, confirm=False)

Install the packages in the manifest.

Parameters
  • reinstall – Reinstall installed packages if True, defaults to False

  • pacman_conf – Path to pacman configuration file

  • sysroot – An alternative system root (see pacman’s –sysroot flag)

  • confirm – Prompt to install if True, defaults to False

Raises

CalledProcessError – Raised if the pacman command fails

load()

Load the manifest file and populate the manifest’s packages and dependencies properties.

Returns

A dictionary with keys: timestamp, packages, dependencies

reset()

Remove all packages and dependencies from manifest.

save()

Save the manifest file.

verify()

Verify that the packages in the manifest exist.

Returns

True if all packages exist, otherwise false

chroot module

class pkgbuilder.chroot.Chroot(working_dir)

A mkarchroot-based chroot capable of building packages with makechrootpkg.

Parameters

working_dir – Path to chroot directory

exists()

Check if the chroot exists.

Returns

True if exists, False otherwise

make()

Make the chroot using mkarchroot.

makepkg(pkgbuild, deps=[])

Build a package in the chroot using makechrootpkg.

Parameters
  • pkgbuild – Pkgbuild to build

  • deps – List of dependency package paths to install into chroot

Returns

makechrootpkg return code, stdout, and stderr

pacman(flags)

Run pacman with the given flags in the chroot.

Parameters

flags – String containing flags for the pacman command

refresh()

Refresh pacman databases.

remove()

Remove the chroot.

update()

Update the chroot with pacman -Syu.

class pkgbuilder.chroot.Mirrorlist(chroot)

A chroot’s mirrorlist.

Parameters

chroot – The chroot

add(mirror, write=True)

Append the given mirror to the chroot’s mirrorlist and refresh pacman databases.

Parameters
  • mirror – The mirror URL

  • write – Whether to write the changed mirrorlist to the chroot, defaults to True

copy(path='/etc/pacman.d/mirrorlist')

Copy the provided mirrorlist into the chroot and refresh pacman databases.

Parameters

path – Path to the mirrorlist

read()

Read the mirrors from the mirrorlist file.

Returns

List of mirror URLs

set(mirror, write=True)

Set the given mirror as the chroot’s only mirror and refresh pacman databases.

Parameters
  • mirror – The mirror URL

  • write – Whether to write the changed mirrorlist to the chroot, defaults to True

set_date(date, write=True)

Set the mirror to the Arch Linux Archive repository of the given date.

Parameters
  • date – A date object

  • write – Whether to write the changed mirrorlist to the chroot, defaults to True

Returns

The mirror URL

write()

Write the list of mirrors to the mirrorlist file.

Returns

String of mirrorlist content

pkgbuild module

class pkgbuilder.pkgbuild.AurPkgbuild(name, buildpath, aurpkg)

An AUR-based PKGBUILD.

Parameters
  • name – Package name

  • buildpath – Path to build directory

  • aurpkg – AurPackage for the given package name

class pkgbuilder.pkgbuild.LocalPkgbuild(name, buildpath, localdir)

A locally sourced PKGBUILD.

Parameters
  • name – Package name

  • buildpath – Path to build directory

  • localdir – Path to the directory containing PKGBUILD

class pkgbuilder.pkgbuild.Pkgbuild(name, buildpath, sourcedir)

This class represents a local or AUR-based PKGBUILD. It creates the directory needed to build the package.

exception NoPkgbuildError

An exception raised when a local directory exists but does not contain a PKGBUILD file.

class Source

Flags for local or AUR sources.

exception SourceNotFoundError

An exception raised when no source is found for the package name.

classmethod new(name, builddir, localdir=None, source=None)

Create a new LocalPkgbuild or AurPkgbuild.

Parameters
  • name – Package name

  • builddir – Path to package build directory

  • localdir – Path to directory of local PKGBUILDs

  • source – PKGBUILD source - one of Pkgbuild.Source.Local or Pkgbuild.Source.Aur

Raises
Returns

LocalPkgbuild or AurPkgbuild

packagelist(makepkg_conf=None)

Get a list of paths to packages this PKGBUILD will produce when built.

Parameters

makepkg_conf – Path to makepkg configuration file

Returns

A list of paths to packages

Raises

CalledProcessError – Raised if the makepkg command fails

remove()

Remove build directory.

update(force=False)

Update the build directory. Local sources are synchronized and AUR sources are updated via git pull.

Parameters

force – Force checking for updates

utils module

class pkgbuilder.utils.CmdLogger(log)

A command runner capable of capturing and logging output.

Parameters

log – The logger

run(cmd)

Run a command, capturing and logging its output.

Parameters

cmd – The command to run

Returns

The command’s exit code, a list of stdout lines, and a list of stderr lines

pkgbuilder.utils.cwd(path)

A context manager for changing the working directory.

Parameters

path – The new working directory

pkgbuilder.utils.synctree(a, b)

Synchronize the contents of b with those found in a.

Parameters
  • a – The seed directory

  • b – The destination directory

pkgbuilder.utils.write_stdin(cmd, iter)

Write strings produced by an iterable to a subprocess’s standard input.

Parameters
  • cmd – The subprocess command

  • iter – The iterable

Raises

CalledProcessError – Raised if the subprocess fails