APKBUILD examples:Python: Difference between revisions
mNo edit summary |
(Update examples and add example for py2/py3 package) |
||
| Line 1: | Line 1: | ||
A lot of Python packages use the distutils framework. This mean that the build() and the package() section looks a bit different compared to an application which uses ''make''. | A lot of Python packages use the ''setuptools'' or ''distutils'' framework. This mean that the build() and the package() section looks a bit different compared to an application which uses ''make''. | ||
<pre> | <pre> | ||
pkgname="py3-foo" | |||
... | ... | ||
depends="python3" | |||
makedepends="python3-dev" | |||
... | |||
build() { | build() { | ||
cd "$ | cd "$builddir" | ||
python3 setup.py build | |||
} | } | ||
package() { | package() { | ||
cd "$ | cd "$builddir" | ||
python3 setup.py install --prefix=/usr --root="$pkgdir" | |||
} | |||
</pre> | |||
If Python package support both Python 2 and Python 3, then the Alpine package should provide both variants as ''py2-'' and ''py3-'' subpackages. | |||
<pre> | |||
pkgname="py-foo" | |||
_pkgname="Foo" | |||
... | |||
depends="" | |||
makedepends="python2-dev python3-dev" | |||
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3" | |||
... | |||
build() { | |||
cd "$builddir" | |||
python2 setup.py build || return 1 | |||
python3 setup.py build || return 1 | |||
} | |||
package() { | |||
mkdir -p "$pkgdir" | |||
} | |||
_py2() { | |||
replaces="$pkgname" | |||
_py python2 | |||
} | |||
_py3() { | |||
_py python3 | |||
} | |||
_py() { | |||
local python="$1" | |||
pkgdesc="$pkgdesc (for $python)" | |||
arch="all" | |||
depends="$depends $python" | |||
install_if="$pkgname=$pkgver-r$pkgrel $python" | |||
cd "$builddir" | |||
$python setup.py install --prefix=/usr --root="$subpkgdir" | |||
} | } | ||
</pre> | </pre> | ||
Source located at [http://pypi.python. | Source located at [http://pypi.python.org PyPi] | ||
<pre> | <pre> | ||
_pkgname=ShortName | _pkgname=ShortName | ||
... | ... | ||
source=" | source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz" | ||
</pre> | </pre> | ||
[[Category:Development]] [[Category:Python]] | [[Category:Development]] [[Category:Python]] | ||
Revision as of 18:10, 31 August 2016
A lot of Python packages use the setuptools or distutils framework. This mean that the build() and the package() section looks a bit different compared to an application which uses make.
pkgname="py3-foo"
...
depends="python3"
makedepends="python3-dev"
...
build() {
cd "$builddir"
python3 setup.py build
}
package() {
cd "$builddir"
python3 setup.py install --prefix=/usr --root="$pkgdir"
}
If Python package support both Python 2 and Python 3, then the Alpine package should provide both variants as py2- and py3- subpackages.
pkgname="py-foo"
_pkgname="Foo"
...
depends=""
makedepends="python2-dev python3-dev"
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3"
...
build() {
cd "$builddir"
python2 setup.py build || return 1
python3 setup.py build || return 1
}
package() {
mkdir -p "$pkgdir"
}
_py2() {
replaces="$pkgname"
_py python2
}
_py3() {
_py python3
}
_py() {
local python="$1"
pkgdesc="$pkgdesc (for $python)"
arch="all"
depends="$depends $python"
install_if="$pkgname=$pkgver-r$pkgrel $python"
cd "$builddir"
$python setup.py install --prefix=/usr --root="$subpkgdir"
}
Source located at PyPi
_pkgname=ShortName
...
source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz"