pkgbuild_parser is a module written in Python (compatible with Python 3.x) designed to extract information from a PKGBUILD. The main purpose of this module is to provide simple and direct access to the most important fields of a PKGBUILD without relying on external tools or additional libraries.
This module allows you to quickly and directly obtain data such as package name, version, description, license, URL, source file, etc.
See the CONTRIBUTING file.
from pkgbuild_parser import Parser, InfoDict
parser = Parser(<FILENAME> (String; Default value: "PKGBUILD")
<ENABLE_CACHE> (Boolean; Default value: True)
<EXTRA_NAMES> (List of strings; Default value: None))
infodict = InfoDict(<PARSER> (Parser; Not default value)
<*INFO_TO_GET> (Strings; Not default value)
<MULTILINE> (Boolean; Default value: False)
<IGNORE_ERRORS> (Boolean; Default value: False))
| Function | That returns |
|---|---|
get_pkgname() |
Package name (pkgname) as a string. |
get_pkgver() |
Package version (pkgver) as a string. |
get_pkgrel() |
Release number (pkgrel) as a string. |
get_pkgdesc() |
Package description (pkgdesc) as a string. |
get_arch() |
Package architecture (arch) as a list of strings. |
get_url() |
Main project URL (url) as a string. |
get_license() |
Package license (license) as a list of strings. |
get_source() |
Package source(s) (source) as a list of strings. |
get_epoch() |
Package epoch. |
get_install() |
Install script name |
get_full_package_name() |
Full package name, including epoch, version, and pkgrel. |
get_depends() |
List of the package's dependencies. |
get_makedepends() |
List of the package's build dependencies. |
get_optdepends() |
Dictionary of the package's optional dependencies. |
get_options() |
List of the package's options. |
get_checkdepends() |
List of the package's check dependencies. |
get_sums(algorithm) |
List of the algorithm checksums. |
get_validpgpkeys() |
List of the valid PGP keys. |
get_conflicts() |
List of conflicting packages. |
get_provides() |
List of packages provided. |
get_replaces() |
List of packages it replaces. |
get_pkgbase() |
Base package (pkgbase) as a list. |
get_changelog() |
Changelog filename as a string. |
get_groups() |
List of the package groups. |
get_backup() |
List of the backup files. |
get_noextract() |
List of files to exclude from the extraction. |
Note: The internal functions (get_base, multiline, replacevar, processvar and remove_quotes) are intended for module use and do not need to be used by the user, except when you want to create functions that are not in the parser.
Also, you can use the InfoDict class to create dictionariess from selected information, InfoDict has this methods:
| Function | That returns |
|---|---|
get_dict() |
dictionary that contains the information requested by the user. |
to_json() |
Converts the dictionary to a JSON format. |
write_json(json_name) |
Writes a file with the provided name that contains the dictionary information in JSON format. |
The module is available on the AUR as python-pkgbuild-parser.
pip install pkgbuild-parser
GitHub example Codeberg example
If the PKGBUILD file does not exist, a ParserFileError is raised, which must be caught to prevent the program from failing.
A ParserKeyError can also be raised if getting a value from the PKGBUILD fails, for example, if the license is not declared correctly, and get_license() is called, this exception will be raised.
depends, makedepends, source, optdepends, license, options, and checkdepends.