Difference between revisions of "Python package guidelines"

From ArchWiki
Jump to: navigation, search
(Example: proto from ABS git)
(Instruct to pass correct flags to pip)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
[[Category:Package development]]
 
[[Category:Package development]]
[[it:Python Package Guidelines]]
+
[[it:Python package guidelines]]
{{Package Guidelines}}
+
[[ja:Python パッケージガイドライン]]
 
+
{{Package guidelines}}
Writing [[PKGBUILD]]s for software written in [[Python]].
+
This document covers standards and guidelines on writing [[PKGBUILD]]s for [[Python]] software.
  
 
== Package naming ==
 
== Package naming ==
For libraries, use {{Ic|python-''modulename''}}. For applications, use the program name. In either case, the package name should be entirely lowercase.
+
 
 +
For Python 3 libraries, use {{Ic|python-''modulename''}}. For applications, use the program name. In either case, the package name should be entirely lowercase.
  
 
Python 2 libraries should instead be named {{Ic|python2-''modulename''}}.
 
Python 2 libraries should instead be named {{Ic|python2-''modulename''}}.
 +
 +
===Versioned packages===
 +
 +
If you need to add a versioned package then use {{Ic|python-''modulename''-''version''}}, e.g. {{Ic|python-colorama-0.2.5}}. So python dependency {{Ic|colorama==0.2.5}} will turn into {{Ic|python-colorama-0.2.5}} Arch package.
  
 
== File placement ==
 
== File placement ==
 +
 
Most Python packages are installed with the [http://docs.python.org/library/distutils.html distutils] system using '''setup.py''', which installs files under {{Ic|/usr/lib/python''<python version>''/site-packages/''pkgname''}} directory.
 
Most Python packages are installed with the [http://docs.python.org/library/distutils.html distutils] system using '''setup.py''', which installs files under {{Ic|/usr/lib/python''<python version>''/site-packages/''pkgname''}} directory.
 +
 +
* The {{Ic|1=--optimize=1}} parameter compiles {{Ic|.pyo}} files so they can be tracked by [[pacman]].
 +
 +
If using [https://pip.pypa.io/en/stable/ pip] (which is necessary for installing e.g. wheels, and generally preferred by the Python community nowadays), remember to pass the following flags:
 +
 +
PIP_CONFIG_FILE=/dev/null pip install --isolated --root="$pkgdir" --ignore-installed --no-deps *.whl
 +
 +
* {{ic|PIP_CONFIG_FILE&#61;/dev/null}} ignores {{ic|{/etc,~/.config}/pip.conf}} that may be appending arbitrary flags to '''pip'''.
 +
* {{ic|--isolated}} ignores environment variables (and again {{ic|{/etc,~/.config}/pip/pip.conf}}) that may otherwise also be appending arbitrary flags to '''pip'''.
 +
* {{ic|--ignore-installed}} is necessary until https://github.com/pypa/pip/issues/3063 is resolved (otherwise '''pip''' skips the install in the presence of an earlier {{ic|--user}} install).
 +
* {{ic|--no-deps}} ensures, well, that dependencies do not get packaged together with the main package.
  
 
== Notes ==
 
== Notes ==
The {{Ic|1=--optimize=1}} parameter compiles {{Ic|.pyo}} files so they can be tracked by [[pacman]].
 
  
 
In most cases, you should put {{Ic|any}} in the {{Ic|arch}} array since most Python packages are architecture independent.
 
In most cases, you should put {{Ic|any}} in the {{Ic|arch}} array since most Python packages are architecture independent.
Line 21: Line 37:
  
 
== Example ==
 
== Example ==
An example PKGBUILD can be found [https://projects.archlinux.org/abs.git/tree/prototypes/PKGBUILD-python.proto here] or at {{Ic|/usr/share/pacman/PKGBUILD-python.proto}}, which is in the {{Pkg|abs}} package.
+
 
 +
A distutils-style example PKGBUILD can be found [https://projects.archlinux.org/abs.git/tree/prototypes/PKGBUILD-python.proto here] or at {{Ic|/usr/share/pacman/PKGBUILD-python.proto}}, which is in the {{Pkg|abs}} package.

Latest revision as of 02:20, 8 September 2016

Package creation guidelines

CLRCrossEclipseFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRubyVCSWebWine

This document covers standards and guidelines on writing PKGBUILDs for Python software.

Package naming

For Python 3 libraries, use python-modulename. For applications, use the program name. In either case, the package name should be entirely lowercase.

Python 2 libraries should instead be named python2-modulename.

Versioned packages

If you need to add a versioned package then use python-modulename-version, e.g. python-colorama-0.2.5. So python dependency colorama==0.2.5 will turn into python-colorama-0.2.5 Arch package.

File placement

Most Python packages are installed with the distutils system using setup.py, which installs files under /usr/lib/python<python version>/site-packages/pkgname directory.

  • The --optimize=1 parameter compiles .pyo files so they can be tracked by pacman.

If using pip (which is necessary for installing e.g. wheels, and generally preferred by the Python community nowadays), remember to pass the following flags:

PIP_CONFIG_FILE=/dev/null pip install --isolated --root="$pkgdir" --ignore-installed --no-deps *.whl
  • PIP_CONFIG_FILE=/dev/null ignores {/etc,~/.config}/pip.conf that may be appending arbitrary flags to pip.
  • --isolated ignores environment variables (and again {/etc,~/.config}/pip/pip.conf) that may otherwise also be appending arbitrary flags to pip.
  • --ignore-installed is necessary until https://github.com/pypa/pip/issues/3063 is resolved (otherwise pip skips the install in the presence of an earlier --user install).
  • --no-deps ensures, well, that dependencies do not get packaged together with the main package.

Notes

In most cases, you should put any in the arch array since most Python packages are architecture independent.

Please do not install a directory named just tests, as it easily conflicts with other Python packages (for example, /usr/lib/python2.7/site-packages/tests/).

Example

A distutils-style example PKGBUILD can be found here or at /usr/share/pacman/PKGBUILD-python.proto, which is in the abs package.