APKBUILD examples:Python: Difference between revisions
(Created page with "Coming soon...") |
WhyNotHugo (talk | contribs) No edit summary |
||
| (45 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
Typical Python packages use Python-specific build systems, making their <code>build()</code> and <code>package()</code> functions different compared to an application which uses ''make''. | |||
== Considerations == | |||
=== pkgname === | |||
Package name for a Python ''library'' must be prefixed with ''py3-''. | |||
For an 'executable' (for example, <code>black</code>, <code>binwalk</code>), you generally don't need to prefix it. | |||
=== arch === | |||
; noarch : Use for pure Python packages (i.e. without compiled code). | |||
; all (and others) : Use for packages with native extensions (i.e. with compiled code). | |||
=== depends === | |||
'''Do not''' add python3 to <tt>depends=</tt> (it's auto-detected via dynamic linking to python library). | |||
=== source === | |||
Most Python packages are published in [https://pypi.python.org/pypi PyPI](the Python Package Index). | |||
If the package has a source tarball available in PyPI (that’s true for most packages), and it contains tests (some explicitly remove them from PyPI), you should reference it in <tt>source=</tt> as: | |||
<pre> | |||
https://files.pythonhosted.org/packages/source/${_pyname%${_pyname#?}}/$_pyname/$_pyname-$pkgver.tar.gz | |||
</pre> | |||
where <tt>_pyname</tt> is the real name of the Python package. | |||
Otherwise, use the normal upstream git tarballs. | |||
== Examples == | |||
=== pep517 invocation === | |||
<pre> | |||
pkgname="py3-foo" | |||
_pyname=foo | |||
... | |||
depends="py3-bar py3-baz" | |||
makedepends="py3-gpep517 py3-setuptools py3-wheel python3-dev" | |||
checkdepends="py3-pytest" | |||
subpackages="$pkgname-pyc" | |||
source="$pkgname-$pkgver.tar.gz::https://github.com/xyz/foo/archive/refs/tags/v$pkgver.tar.gz" | |||
builddir="$srcdir/$_pyname-$pkgver" | |||
... | |||
build() { | |||
gpep517 build-wheel --wheel-dir .dist --output-fd 3 3>&1 | |||
} | |||
check() { | |||
python3 -m venv --clear --system-site-packages testenv | |||
testenv/bin/python3 -m installer .dist/*.whl | |||
testenv/bin/python3 -m pytest | |||
} | |||
package() { | |||
python3 -m installer -d "$pkgdir" \ | |||
dist/*.whl | |||
} | |||
</pre> | |||
Depending on the <code>build-backend</code> in the pyproject.toml, the package should depend on py3-setuptools, py3-flit-core, py3-poetry-core or py3-hatchling at build time. If a project specifies literally <code>flit</code> or <code>poetry</code>, patch it to use the <code>-core</code> variant. | |||
[[Category:Development]] [[Category:Python]] | |||
Latest revision as of 21:55, 7 April 2026
Typical Python packages use Python-specific build systems, making their build() and package() functions different compared to an application which uses make.
Considerations
pkgname
Package name for a Python library must be prefixed with py3-.
For an 'executable' (for example, black, binwalk), you generally don't need to prefix it.
arch
- noarch
- Use for pure Python packages (i.e. without compiled code).
- all (and others)
- Use for packages with native extensions (i.e. with compiled code).
depends
Do not add python3 to depends= (it's auto-detected via dynamic linking to python library).
source
Most Python packages are published in PyPI(the Python Package Index). If the package has a source tarball available in PyPI (that’s true for most packages), and it contains tests (some explicitly remove them from PyPI), you should reference it in source= as:
https://files.pythonhosted.org/packages/source/${_pyname%${_pyname#?}}/$_pyname/$_pyname-$pkgver.tar.gz
where _pyname is the real name of the Python package.
Otherwise, use the normal upstream git tarballs.
Examples
pep517 invocation
pkgname="py3-foo"
_pyname=foo
...
depends="py3-bar py3-baz"
makedepends="py3-gpep517 py3-setuptools py3-wheel python3-dev"
checkdepends="py3-pytest"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/xyz/foo/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/$_pyname-$pkgver"
...
build() {
gpep517 build-wheel --wheel-dir .dist --output-fd 3 3>&1
}
check() {
python3 -m venv --clear --system-site-packages testenv
testenv/bin/python3 -m installer .dist/*.whl
testenv/bin/python3 -m pytest
}
package() {
python3 -m installer -d "$pkgdir" \
dist/*.whl
}
Depending on the build-backend in the pyproject.toml, the package should depend on py3-setuptools, py3-flit-core, py3-poetry-core or py3-hatchling at build time. If a project specifies literally flit or poetry, patch it to use the -core variant.