2 # Copyright (C) 2016 Yousong Zhou <yszhou4tech@gmail.com>
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 include $(TOPDIR)/rules.mk
10 PKG_NAME:=python-packages
14 PKG_MAINTAINER:=Yousong Zhou <yszhou4tech@gmail.com>
17 # NOTE: move the host module installation to Host/Compile when
18 # HOST_CONFIG_DEPENDS is supported
20 # NOTE: PKG_CONFIG_DEPENDS cannot correctly track changes of string type config
21 # options, so you may want to do manual cleanup on config change.
23 PKG_CONFIG_DEPENDS:= \
24 CONFIG_PACKAGE_python-packages-list-host \
25 CONFIG_PACKAGE_python-packages-list \
26 CONFIG_PACKAGE_python-packages-list-cleanup \
27 CONFIG_PACKAGE_python-packages-envs \
28 CONFIG_PACKAGE_python-packages-extra-deps \
29 CONFIG_PACKAGE_python-packages-index-url \
30 CONFIG_PACKAGE_python-packages-pip-opts \
32 PKG_BUILD_DEPENDS:=python python-pip/host
34 include $(INCLUDE_DIR)/package.mk
35 $(call include_mk, python-host.mk)
36 $(call include_mk, python-package.mk)
38 define Package/python-packages
42 TITLE:=A dummy package for packaging python modules with pip
43 DEPENDS:=@DEVEL +python
46 define Package/python-packages/config
47 if PACKAGE_python-packages
48 config PACKAGE_python-packages-list-host
49 string "List of python packages to install on host"
50 config PACKAGE_python-packages-list
51 string "List of python packages to install on target"
52 config PACKAGE_python-packages-list-cleanup
53 string "List of python packages to cleanup to avoid clash with existing packages"
54 config PACKAGE_python-packages-envs
55 string "Extra environment variables to pass on to pip and its children on target build"
56 config PACKAGE_python-packages-extra-deps
57 string "List of deps fulfilled but not tracked by the build system"
58 config PACKAGE_python-packages-index-url
59 string "Index URL passed to pip with --index-url"
60 config PACKAGE_python-packages-pip-opts
61 string "Additional arguments to pip command line"
65 CONFIG_PACKAGE_python-packages-list-host:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-host))
66 CONFIG_PACKAGE_python-packages-list:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list))
67 CONFIG_PACKAGE_python-packages-list-cleanup:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-list-cleanup))
68 CONFIG_PACKAGE_python-packages-envs:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-envs))
69 CONFIG_PACKAGE_python-packages-extra-deps:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-extra-deps))
70 CONFIG_PACKAGE_python-packages-pip-opts:=$(call qstrip,$(CONFIG_PACKAGE_python-packages-pip-opts))
72 HOST_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
74 decr=$(word $(1),0 1 2 3 4 5 6 7 8 9 10)
75 recur=$(if $(subst 0,,$(2)),$(call recur,$(1),$(call decr,$(2)),$(call $(1)$(2),$(3))),$(3))
76 _req2dir1=$(subst >,gt,$(1))
77 _req2dir2=$(subst <,lt,$(1))
78 _req2dir3=$(subst >=,geq,$(1))
79 _req2dir4=$(subst <=,leq,$(1))
80 _req2dir5=$(subst ://,:::,$(1))
81 _req2dir6=$(subst *,_,$(1))
82 _req2dir7=$(subst ?,_,$(1))
83 req2dir=$(call recur,_req2dir,7,$(1))
85 # --ignore-installed, it may happen that host pip will ignore target install if
86 # it was already installed as host module, e.g. cffi deps of cryptograph
87 HOST_PYTHON_PIP_INSTALL=$(HOST_PYTHON_PIP) install \
92 $(if $(CONFIG_PACKAGE_python-packages-index-url), --index-url $(CONFIG_PACKAGE_python-packages-index-url)) \
93 $(if $(CONFIG_PACKAGE_python-packages-pip-opts), $(CONFIG_PACKAGE_python-packages-pip-opts)) \
95 HOST_PYTHON_PIP_INSTALL_HOST:=$(call HOST_PYTHON_PIP_INSTALL,$(STAGING_DIR_HOSTPKG),"")
96 HOST_PYTHON_PIP_INSTALL_TARGET=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg)),/usr)
97 HOST_PYTHON_PIP_INSTALL_CLEANUP:=$(call HOST_PYTHON_PIP_INSTALL,$(PKG_INSTALL_DIR)/_cleanup,/usr)
100 $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-host),
101 $(call Build/Compile/HostPyRunHost,,$(HOST_PYTHON_PIP_INSTALL_HOST) $(pkg))
103 $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
104 $(call Build/Compile/HostPyRunTarget,,$(call HOST_PYTHON_PIP_INSTALL_TARGET,$(pkg)) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
106 $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list-cleanup),
107 $(call Build/Compile/HostPyRunTarget,,$(HOST_PYTHON_PIP_INSTALL_CLEANUP) $(pkg),$(CONFIG_PACKAGE_python-packages-envs))
111 define Package/python-packages/install
112 $(foreach pkg,$(CONFIG_PACKAGE_python-packages-list),
113 $(CP) "$(PKG_INSTALL_DIR)/$(call req2dir,$(pkg))"/* $(1)
116 find "$(PKG_INSTALL_DIR)/_cleanup" -mindepth 1 -depth | while read sf; do \
117 tf="$$$${sf#$(PKG_INSTALL_DIR)/_cleanup/}"; \
119 if [ -f "$$$$tf" -o -L "$$$$tf" ]; then \
121 elif [ -d "$$$$tf" ]; then \
122 rmdir -v -p "$$$$tf" || true; \
127 define Package/python-packages/extra_provides
128 echo $(CONFIG_PACKAGE_python-packages-extra-deps) | tr ' ' '\n'
131 $(eval $(call BuildPackage,python-packages))