openwrt-packages/lang/python
Rosen Penev 9f15edf744
Merge pull request #8584 from jefferyto/python-compileall-recursion-level
python,python3: Increase max recursion level when generating bytecode
2019-04-04 00:19:55 -07:00
..
Flask Flask: now depends on python3-setuptools 2019-03-08 02:03:16 +01:00
Jinja2 Jinja2: add missing dependency on markupsafe 2019-03-05 17:19:51 +01:00
MarkupSafe MarkupSafe: update to version 1.1.1 2019-03-02 22:46:54 +01:00
Werkzeug Werkzeug: Update to 0.14.1 2018-11-06 09:38:16 -08:00
bcrypt bcrypt: Update to 3.1.6 2019-02-12 01:45:42 -05:00
click treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
click-log click-log: fix circular dependency 2019-03-13 14:34:49 -03:00
django django: Update to 1.11.17 2018-12-16 11:33:26 -08:00
django-appconf treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
django-compressor treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
django-constance django-constance: Update to 2.3.1 2018-10-20 15:12:15 -07:00
django-formtools django-formtools: use PyPackage to build 2018-12-05 08:04:47 -02:00
django-jsonfield treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
django-picklefield django-picklefield: Update to 1.1.0 2018-09-17 14:45:56 -07:00
django-postoffice django-postoffice: Update to 3.1.0 2018-09-17 14:49:49 -07:00
django-ranged-response django-ranged-response: use PyPackage to build 2018-12-05 08:05:46 -02:00
django-restframework django-restframework: Update to 3.9.0 2018-10-22 14:44:03 -07:00
django-simple-captcha django-simple-captcha: use PyPackage to build 2018-12-05 08:13:55 -02:00
django-statici18n django-statici18n: Update to 1.8.2 2018-09-17 14:32:20 -07:00
django-webpack-loader django-webpack-loader: use PyPackage to build 2018-12-05 08:03:40 -02:00
et_xmlfile treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
flup flup: Update to 1.0.3 2018-09-08 17:43:29 -07:00
gunicorn gunicorn: Update to 19.9.0 2018-09-17 14:57:34 -07:00
itsdangerous itsdangerous: Update to 1.1.0 2018-11-14 11:43:21 -08:00
jdcal jdcal: Update to 1.4 2018-09-16 08:41:42 -07:00
micropython micropython: Update to 1.94 2018-10-06 11:52:51 -07:00
micropython-lib micropython-lib: Update to 1.9.3 2018-10-07 06:03:34 -07:00
openpyxl openpyxl: Update to 2.5.9 2018-10-20 14:46:48 -07:00
passlib passlib: Add python library 2019-01-08 03:58:28 -05:00
pillow pillow: Update to 5.3.0 2018-11-10 19:49:32 -08:00
pyjwt pyjwt: bump to version 1.7.1 2018-12-13 16:24:38 -02:00
pyodbc pyodbc: Added ability to compile with uclibc++ 2019-03-03 16:15:31 -08:00
python Merge pull request #8584 from jefferyto/python-compileall-recursion-level 2019-04-04 00:19:55 -07:00
python-aiohttp python-aiohttp: add a new package 2019-04-01 02:29:26 +02:00
python-appdirs python-appdirs: add package 2019-03-11 17:21:31 +01:00
python-asn1crypto python-asn1crypto: bump to version 0.24.0 2018-06-11 12:02:40 +03:00
python-astral python-astral: add new package 2019-03-28 14:41:23 +01:00
python-async-timeout async-timeout: add a new package 2019-04-01 02:22:05 +02:00
python-attrs python-attrs: Update to latest version 2019-03-22 21:48:27 +08:00
python-automat python-(automat|crypto|gmpy2|parsley): Use default compile 2019-02-19 22:54:43 +08:00
python-certifi python-certifi: Update to 2019.3.9 2019-03-11 08:30:51 -03:00
python-cffi python-cffi: Update to latest version 2019-03-22 21:50:36 +08:00
python-chardet python-chardet: fix Makefile typo 2019-03-13 14:34:49 -03:00
python-constantly multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-contextlib2 python-contextlib2: add package 2019-03-11 17:21:31 +01:00
python-crcmod treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
python-crypto python-(automat|crypto|gmpy2|parsley): Use default compile 2019-02-19 22:54:43 +08:00
python-cryptodome python-cryptodome: add new package 2019-03-01 14:12:24 +08:00
python-cryptodomex python-cryptodome: add new package 2019-03-01 14:12:24 +08:00
python-cryptography python-cryptography: Update to latest version 2019-03-02 01:46:48 +08:00
python-curl python-curl: Fix compilation error after upgrade to 7.43.0.2 2018-06-05 00:32:20 +02:00
python-dateutil python-dateutil: Update packaging and add Python3 version 2019-01-07 11:13:46 -05:00
python-decorator python-decorator: add package 2019-03-11 17:21:31 +01:00
python-dns python-dns: Add Python3 variant, update to 1.16.0 2019-03-03 21:43:02 +01:00
python-dpkt python-dpkt: Update to 1.9.2 2018-12-17 19:14:48 -08:00
python-egenix-mx-base python-egenix-mx-base: use source distribution 2018-12-07 14:17:37 -02:00
python-enum34 multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-evdev python-evdev: bump to version 1.1.2 2018-09-11 09:53:45 +03:00
python-gmpy2 python-(automat|crypto|gmpy2|parsley): Use default compile 2019-02-19 22:54:43 +08:00
python-gnupg python-gnupg: update to version 0.4.4 2019-03-02 23:20:10 +01:00
python-hyperlink multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-idna multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-incremental multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-influxdb python-influxdb: update to 5.2.2 2019-03-20 16:26:18 +01:00
python-ipaddress multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-jsonpath-ng python-jsonpath-ng: add package 2019-03-11 17:21:31 +01:00
python-ldap python-ldap: Update to 3.1.0 2018-11-06 19:05:13 -08:00
python-lxml python-lxml: bump to version 4.3.1 2019-02-12 12:39:55 +02:00
python-multidict python-multidict: add a new package 2019-04-01 02:08:16 +02:00
python-mysql python-mysql: Update to 1.3.14 2018-12-17 14:17:11 -08:00
python-oauthlib python-oauthlib: update to 3.0.1 2019-03-18 18:16:11 -03:00
python-packages treewide: use local python-package.mk & python3-package.mk files 2018-01-10 23:06:23 +02:00
python-paho-mqtt python-paho-mqtt: add package 2019-03-11 17:21:32 +01:00
python-parsley python-(automat|crypto|gmpy2|parsley): Use default compile 2019-02-19 22:54:43 +08:00
python-pcapy python-pcapy: Add uclibc++ support 2018-12-26 15:54:21 -08:00
python-pip-conf python-pip-conf: split package away from python package 2017-12-10 19:49:23 +02:00
python-ply python-ply: fix circular dependency 2019-03-13 14:34:49 -03:00
python-psycopg2 python-psycopg2: Update to 2.7.6.1 2018-12-08 18:12:55 -08:00
python-pyasn1 multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-pyasn1-modules multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-pycparser multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-pyopenssl python-pyopenssl,python-service-identity: Update package data 2019-03-11 19:30:06 +08:00
python-pyotp python-pyotp: add new package for Python3 2019-04-01 02:13:59 +02:00
python-pyptlib multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-pyserial python-pyserial: Update to version 3.4 2018-02-16 15:48:16 +02:00
python-pytz python-pytz: add Python3 version 2019-03-11 10:43:38 +01:00
python-qrcode python-qrcode: bump to 6.1, fix dependencies 2019-03-11 08:29:46 -03:00
python-requests python-requests: fix circular dependency 2019-03-13 14:34:49 -03:00
python-requests-oauthlib python-requests-oauthlib: update to 1.2.0 2019-03-18 18:16:11 -03:00
python-schema python-schema: add package 2019-03-11 17:21:31 +01:00
python-service-identity python-pyopenssl,python-service-identity: Update package data 2019-03-11 19:30:06 +08:00
python-simplejson python-simplejson: fix circular dependency 2019-03-13 14:34:49 -03:00
python-six multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-slugify python-slugify: add Python3 package 2019-04-01 01:28:53 +02:00
python-twisted multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-txsocksx multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python-urllib3 python-urllib3: add variant for Python3 2019-02-20 09:50:58 +01:00
python-voluptuous python-voluptuous: add a new package 2019-03-28 14:34:39 +01:00
python-voluptuous-serialize python-voluptuous-serialize: add package for Python3 2019-04-01 02:36:52 +02:00
python-yaml python-yaml: Update to 3.13 2018-08-18 14:21:49 -07:00
python-yarl python-yarl: add a new package 2019-04-01 02:26:29 +02:00
python-zope-interface multiple-python-packages: Update package data 2019-02-20 19:19:20 +08:00
python3 python,python3: Include python-config for target Python in InstallDev 2019-03-31 19:33:12 +08:00
python3-bottle python3-bottle: update to version 0.12.16 2019-03-13 21:45:10 +01:00
rcssmin rcssmin: Switch to pythonhosted for consistency 2018-10-22 14:55:53 -07:00
ruamel-yaml ruamel-yaml: add package 2019-03-28 14:33:15 +01:00
text-unidecode text-unidecode: add new package 2019-03-28 14:32:21 +01:00
vobject vobject: Add python library 2019-01-07 07:33:00 -05:00
README.md lang/python/README.md: add doc describing the lang/python subtree 2019-01-08 17:38:16 +02:00
python-host.mk python,python3: remove `--ignore-installed` flag for host packages 2018-05-14 12:11:00 +03:00
python-package-install.sh python,python3: Increase max recursion level when generating bytecode 2019-04-04 03:07:02 +08:00
python-package.mk python,python3: Fix overridden usr/bin symlinks 2019-04-03 21:05:14 +08:00
python-version.mk python: bump to version 2.7.16 2019-03-08 19:34:38 +08:00
python3-host.mk python,python3: remove `--ignore-installed` flag for host packages 2018-05-14 12:11:00 +03:00
python3-package.mk python,python3: Fix overridden usr/bin symlinks 2019-04-03 21:05:14 +08:00
python3-version.mk python3: Fix py3 pip and setuptools versions 2019-01-02 02:59:08 -05:00

README.md

Python packages folder

Table of contents

  1. Description
  2. Introduction
  3. Build considerations
  4. General folder structure
  5. Building a Python[3] package
    1. PKG_BUILD_DIR
    2. PKG_UNPACK
    3. Include python[3]-package.mk
    4. Add Package/<PKG_NAME> OpenWrt definitions
    5. Wrapping things up so that they build
    6. Customizing things
    7. Host-side Python packages for build

Description

This section describes specifics for the Python packages that are present in this repo, and how things are structured.

In terms of license, contributing guide, etc, all of that information is described in the top README.md file, and it applies here as well. This document attempts to cover only technical aspects of Python/Python3 packages, and maybe some explanations about how things are (and why they are as they are).

Introduction

This sub-tree came to exist after a number of contributions (Python packages) were made to this repo, and the lang subtree grew to a point where a decision was made to move all Python packages under lang/python.

It contains the 2 Python interpreters (Python & Python3) and Python packages. Most of the Python packages are downloaded from pypi.org. Python packages from pypi.org are typically preferred when adding new packages.

If more packages (than the ones packaged here) are needed, they can be downloaded via pip or pip3. Note that the versions of pip & setuptools [available in this repo] are the ones that are packaged inside the Python & Python3 packages (yes, Python & Python3 come packaged with pip & setuptools).

Build considerations

In order to build the Python[3] interpreters, a host Python/Python3 interpreter needs to be built, in order to process some of the build for the target Python/Python3 build. The host Python[3] interpreters are also needed so that Python bytecodes are generated, so the host interpreters need to be the exact versions as on the target. And finally, the host Python[3] interpreters also provide pip & pip3, so that they may be used to install some Python[3] packages that are required to build other Python[3] packages. That's why you'll also see a Python/Python3 build & staging directories.

As you're probably thinking, this sounds [and is] somewhat too much complication [just for packaging], but the status of things is-as-it-is, and it's probably much worse than what's currently visible on the surface [with respect to packaging Python[3] & packages].

As mentioned earlier, Python[3] packages are shipped with bytecodes, and the reason for this is simply performance & size. The thought/discussion matrix derives a bit like this:

  • shipping both Python source-code & bytecodes takes too much space on some devices ; Python source code & byte-code take about similar disk-size
  • shipping only Python source code has a big performance penalty [on some lower end systems] ; something like 500 msecs (Python source-only) -> 70 msecs (Python byte-codes) time reduction for a simple "Hello World" script
  • shipping only Python byte-codes seems like a good trade-off, and this means that python-src & python3-src can be provided for people that want the source code

By default, automatic Python[3] byte-code generation is disabled when running a Python script, in order to prevent a disk from accidentally filling up. Since some disks reside in RAM, this also means not filling up the RAM. If someone wants to convert Python source to byte-code then he/she is free to compile it [directly on the device] manually via the Python interpreter & library.

General folder structure

The basis of all these packages are:

These 2 are normal OpenWrt packages, which will build the Python interpreters. They also provide python[3]-pip & python[3]-setuptools. Each Python or Python3 package is actually split into multiple sub-packages [e.g. python-email, python-sqlite3, etc]. This can be viewed inside lang/python/python/files & lang/python/python3/files.

The reason for this splitting, is purely to offer a way for some people to package Python/Python3 in as-minimal-as-possible-and-still-runable way, and also to be somewhat maintainable when packaging. A standard Python[3] installation can take ~20-30 MBs of disk, which can be somewhat big for some people, so there are the python[3]-base packages which bring that down to ~5 MBs. This seems to be good enough (and interesting) for a number of people.

The Python[3] interpreters are structured like this:

  • python-base (and python3-base), which is just the minimal package to startup Python[3] and run basic commands
  • python (and python3) are meta-packages, which install almost everything (python[3]-base [plus] Python[3] library [minus] some unit-tests & some windows-y things)
  • python-light (and python3-light) are python (and python3) [minus] packages that are in lang/python/python/files or lang/python/python3/files ; the size of these 2 packages may be sensible (and interesting) to another group of people

All other Python & Python3 packages (aside from the 2 intepreters) typically use these files:

  • python[3]-host.mk - this file contains paths and build rules for running the Python[3] interpreters on the host-side; they also provide paths to host interprete, host Python lib-dir & so on
  • python[3]-package.mk
    • includes python[3]-host.mk
    • contains all the default build rules for Python[3] packages; these will be detailed below in the [Building a Python[3] package](#Building a Python[3] package) section

Note that Python/Python3 packages don't need to use these files (i.e. python[3]-package.mk & python[3]-host.mk), but they do provide some ease-of-use & reduction of duplicate code, especially when packaging for both Python & Python3. And they do contain some learned-lessons about packaging Python/Python3 packages, so it's a good idea to use them.

Building a Python[3] package

A Python package can be packaged for either Python or Python3 or both.

This section will describe both, and then it can be inferred which is for which.

Packaging for both Python & Python3 uses the VARIANT mechanism for packaging inside OpenWrt. (#### FIXME: find a link for this later if it exists)

PKG_BUILD_DIR

It's important when packaging for both Python & Python3 to override this variable, so that the build directory differs for each variant.

Typically it's just something like:

PKG_BUILD_DIR:=$(BUILD_DIR)/$(BUILD_VARIANT)-pyasn1-$(PKG_VERSION)

Where pyasn1 should be some other name, or maybe PKG_NAME

This should be added before this include:

include $(INCLUDE_DIR)/package.mk

PKG_UNPACK

In many cases, this needs to be overriden. This is usually because the way Python packages are archived, don't follow the convention of other tar.gz packages.

So, something like:

PKG_UNPACK=$(HOST_TAR) -C $(PKG_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(PKG_SOURCE)

should be added.

It's not important whether this is after or before include $(INCLUDE_DIR)/package.mk

Include python[3]-package.mk

If packaging for Python, add this after include $(INCLUDE_DIR)/package.mk

include ../python-package.mk

If packaging for Python3, add this after include $(INCLUDE_DIR)/package.mk

include ../python3-package.mk

Order doesn't matter between python-package.mk & python3-package.mk.

These will make sure that build rules for Python or Python3 can be specified and picked up for build.

Add Package/<PKG_NAME> OpenWrt definitions

This part is similar to default OpenWrt packages. It's usually recommended to have a Package/<PKG_NAME>/Default section that's common for both Python & Python3.

Example:

define Package/python-lxml/Default
  SECTION:=lang
  CATEGORY:=Languages
  SUBMENU:=Python
  URL:=https://lxml.de
  DEPENDS:=+libxml2 +libxslt +libexslt
endef

Then for each variant do something like:

define Package/python-lxml
$(call Package/python-lxml/Default)
  TITLE:=python-lxml
  DEPENDS+=+PACKAGE_python-lxml:python-light +PACKAGE_python-lxml:python-codecs
  VARIANT:=python
endef

define Package/python3-lxml
$(call Package/python-lxml/Default)
  TITLE:=python3-lxml
  DEPENDS+=+PACKAGE_python3-lxml:python3-light
  VARIANT:=python3
endef

Some considerations here (based on the example above):

  • be sure to make sure that DEPENDS are correct for both variants; as seen in the example above, python-codecs is needed only for python-lxml ; that's because python3-codecs doesn't exist and is included in python3-base ; most of the times they are similar, sometimes they are not
  • consider adding conditional DEPENDS for each variant ; so for each Python[3] package add +PACKAGE_python-lxml:<dep> as seen in the above example ; the reason for this is build-time reduction ; if you want to build Python3 only packages, this won't build Python & Python packages + dependencies ; this is a known functionality of OpenWrt build deps
    • there is an exception to the above consideration: if adding +PACKAGE_python-lxml conditional deps creates circular dependencies [for some weird reason], then this can be omitted
  • VARIANT=python or VARIANT=python3 must be added
  • typically each variant package is named Package/python3-<something> & Package/python3-<something> ; this convention makes things easier to follow, though it could work without naming things this this
  • TITLE can be something a bit more verbose/neat ; typically the name is short as seen above

Following these, 2 more definitions are required:

define Package/python-lxml/description
The lxml XML toolkit is a Pythonic binding
for the C libraries libxml2 and libxslt.
endef

define Package/python3-lxml/description
$(call Package/python-lxml/description)
.
(Variant for Python3)
endef

Typically, the description is the same for both, so just mentioning that one is a variant of the other is sufficient.

Wrapping things up so that they build

If all the above prerequisites have been met, all that's left is:

$(eval $(call PyPackage,python-lxml))
$(eval $(call BuildPackage,python-lxml))

$(eval $(call Py3Package,python3-lxml))
$(eval $(call BuildPackage,python3-lxml))

The $(eval $(call PyPackage,python-lxml)) part will instantiate all the default Python build rules so that the final Python package is packaged into an OpenWrt. And $(eval $(call BuildPackage,python-lxml)) will bind all the rules generated with $(eval $(call PyPackage,python-lxml)) into the OpenWrt build system.

These packages will contain byte-codes and binaries (shared libs & other stuff).

If a user wishes to ship source code, adding 2 more lines creates 2 more packages that ship Python source code:

$(eval $(call PyPackage,python-lxml))
$(eval $(call PyPackage,python-lxml-src))
$(eval $(call BuildPackage,python-lxml))

$(eval $(call Py3Package,python3-lxml))
$(eval $(call Py3Package,python3-lxml-src))
$(eval $(call BuildPackage,python3-lxml))

The name *-src must be the Python package name; so for python-lxml-src a equivalent python-lxml name must exist.

Customizing things

Some packages need custom build rules (because they do).

For building, if a user specifies a PyBuild/Compile & Py3Build/Compile rule, this will be used to build/compile the package, instead of the default one defined in python[3]-package.mk.

For installing files on the target, 2 build rules are used:

  • PyPackage/$(1)/filespec & Py3Package/$(1)/filespec which are Python library files relative to /usr/lib/pythonX.Y ; by default this is /usr/lib/python$(PYTHON[3]_VERSION)/site-packages ; most Python[3] packages generate files that get installed in this sub-folder
  • PyPackage/$(1)/install & Py3Package/$(1)/install is similar to Package/$(1)/install ; these allow binary (or other files) to be installed on the target

Both the 2 above rules generate a Package/$(1)/install build rule, which gets picked up by the build system. Both can be used together (they are not mutually exclusive), and provide a good enough flexibility for specifying Python[3] packages.

Host-side Python packages for build

These can be installed via pip and ideally they should only be installed like this, because it's a bit simpler than running them through the OpenWrt build system. Build variants on the host-side build are more complicated (and nearly impossible to do sanely) in the current OpenWrt build system.

Which is why [for example] if you need python cffi on the host build, it's easier to just add it via:

HOST_PYTHON_PACKAGE_BUILD_DEPENDS:="cffi==$(PKG_VERSION)"
HOST_PYTHON3_PACKAGE_BUILD_DEPENDS:="cffi==$(PKG_VERSION)"

[cffi is one of those packages that needs a host-side package installed for both Python & Python3].

This works reasonably well in the current OpenWrt build system, as binaries get built for this package and get installed in the staging-dir $(STAGING_DIR)/usr/lib/pythonX.Y/site-packages.