Skip to contentSkip to conversation

python: Allow pyo only and variants

PATCH New Maxime Hadjinlian 3 participants 3 messages Apr 26, 2015 – Apr 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python: Allow pyo only and variants

Enable the fact that you may want to use only pyo files on you target. The main differences between the file format are as follow:

- py: The source file
- pyc: It's a compiled bytecode, makes import faster.
- pyo: It's an optimized bytecode, mainly it removes the asserts

Also adding the various "mix" options a user may want between theses three options.

---
 package/python/Config.in | 16 ++++++++++++++--
 package/python/python.mk | 32 +++++++++++++++++++++++++++-----
 2 files changed, 41 insertions(+), 7 deletions(-)
package/python/Config.in +14 -2
index 8d71dc9..a03a11f 100644
@@ -18,9 +18,9 @@ if BR2_PACKAGE_PYTHON
 
 choice
 	prompt "python module format to install"
-	default BR2_PACKAGE_PYTHON_PYC_ONLY
+	default BR2_PACKAGE_PYTHON_PYO_ONLY
 	help
-	  Select Python module format to install on target (py, pyc or both)
+	  Select Python module format to install on target (py, pyc, pyo or a mix)
 
 config BR2_PACKAGE_PYTHON_PY_ONLY
 	bool ".py sources only"
@@ -28,9 +28,21 @@ config BR2_PACKAGE_PYTHON_PY_ONLY
 config BR2_PACKAGE_PYTHON_PYC_ONLY
 	bool ".pyc compiled sources only"
 
+config BR2_PACKAGE_PYTHON_PYO_ONLY
+	bool ".pyo compiled sources only"
+
 config BR2_PACKAGE_PYTHON_PY_PYC
 	bool ".py sources and .pyc compiled"
 
+config BR2_PACKAGE_PYTHON_PY_PYO
+	bool ".py sources and .pyo compiled"
+
+config BR2_PACKAGE_PYTHON_PYC_PYO
+	bool ".pyc and .pyo compiled sources"
+
+config BR2_PACKAGE_PYTHON_PY_PYC_PYO
+	bool ".py sources and both .pyc, .pyo compiled"
+
 endchoice
 
 menu "core python modules"
package/python/python.mk +27 -5
index 4a3e71c..a175f19 100644
@@ -33,8 +33,7 @@ HOST_PYTHON_CONF_OPTS += 	\
 	--disable-test-modules	\
 	--disable-bz2		\
 	--disable-ssl		\
-	--disable-ossaudiodev	\
-	--disable-pyo-build
+	--disable-ossaudiodev
 
 # Make sure that LD_LIBRARY_PATH overrides -rpath.
 # This is needed because libpython may be installed at the same time that
@@ -142,8 +141,7 @@ PYTHON_CONF_OPTS += \
 	--disable-gdbm		\
 	--disable-tk		\
 	--disable-nis		\
-	--disable-dbm		\
-	--disable-pyo-build
+	--disable-dbm
 
 # This is needed to make sure the Python build process doesn't try to
 # regenerate those files with the pgen program. Otherwise, it builds
@@ -217,16 +215,40 @@ PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
 
+ifeq ($(BR2_PACKAGE_PYTHON_PYO_ONLY),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.py' -or -name '*.pyc' \) -print0 | xargs -0 rm -f
+endef
+endif
+
 ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
 define PYTHON_FINALIZE_TARGET
-	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.py' -or -name '*.pyo' \) -print0 | xargs -0 rm -f
 endef
 endif
 
 ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
 define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.pyc' -or -name '*.pyo' \) -print0 | xargs -0 rm -f
+endef
+endif
+
+ifeq ($(BR2_PACKAGE_PYTHON_PY_PYC),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | xargs -0 rm -f
+endef
+endif
+
+ifeq ($(BR2_PACKAGE_PYTHON_PY_PYO),y)
+define PYTHON_FINALIZE_TARGET
 	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
 endef
 endif
 
+ifeq ($(BR2_PACKAGE_PYTHON_PYC_PYO),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
+endef
+endif
+
 TARGET_FINALIZE_HOOKS += PYTHON_FINALIZE_TARGET
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 python: Allow pyo only and variants

Dear Maxime Hadjinlian,

Quoted 11 lines · Maxime Hadjinlian

Enable the fact that you may want to use only pyo files on you target. The main differences between the file format are as follow:

- py: The source file
- pyc: It's a compiled bytecode, makes import faster.
- pyo: It's an optimized bytecode, mainly it removes the asserts

Also adding the various "mix" options a user may want between theses three options.

What about Python 3 ?

Quoted 18 lines

choice

package/python/Config.in +5 -2
 	prompt "python module format to install"
-	default BR2_PACKAGE_PYTHON_PYC_ONLY
+	default BR2_PACKAGE_PYTHON_PYO_ONLY
 	help
-	  Select Python module format to install on target (py, pyc or both)
+	  Select Python module format to install on target (py, pyc, pyo or a mix)
 
 config BR2_PACKAGE_PYTHON_PY_ONLY
 	bool ".py sources only"
@@ -28,9 +28,21 @@ config BR2_PACKAGE_PYTHON_PY_ONLY
 config BR2_PACKAGE_PYTHON_PYC_ONLY
 	bool ".pyc compiled sources only"
 
+config BR2_PACKAGE_PYTHON_PYO_ONLY
+	bool ".pyo compiled sources only"
+
 config BR2_PACKAGE_PYTHON_PY_PYC

package/python/Config.in config BR2_PACKAGE_PYTHON_PY_ONLY · line 44

Quoted 10 lines
package/python/Config.in +8 -0
 	bool ".py sources and .pyc compiled"
 
+config BR2_PACKAGE_PYTHON_PY_PYO
+	bool ".py sources and .pyo compiled"
+
+config BR2_PACKAGE_PYTHON_PYC_PYO
+	bool ".pyc and .pyo compiled sources"
+
+config BR2_PACKAGE_PYTHON_PY_PYC_PYO
+	bool ".py sources and both .pyc, .pyo compiled"

Hum do we really want/need a choice with all possible combinations?

Quoted 19 lines
package/python/Config.in +1 -0
+
 endchoice
 
 menu "core python modules"
package/python/python.mk +1 -2
index 4a3e71c..a175f19 100644
@@ -33,8 +33,7 @@ HOST_PYTHON_CONF_OPTS += 	\
 	--disable-test-modules	\
 	--disable-bz2		\
 	--disable-ssl		\
-	--disable-ossaudiodev	\
-	--disable-pyo-build
+	--disable-ossaudiodev
 
 # Make sure that LD_LIBRARY_PATH overrides -rpath.
 # This is needed because libpython may be installed at the same time that

package/python/python.mk PYTHON_CONF_OPTS += \ · line 144

Quoted 6 lines
package/python/python.mk +1 -2
@@ -142,8 +141,7 @@ PYTHON_CONF_OPTS += \
 	--disable-gdbm		\
 	--disable-tk		\
 	--disable-nis		\
-	--disable-dbm		\
-	--disable-pyo-build
+	--disable-dbm

I think we want to keep --disable-pyc-build or --disable-pyo-build when possible, since it saves quite a bit of time when building Python.

Quoted 32 lines
package/python/python.mk +18 -1
 # This is needed to make sure the Python build process doesn't try to
 # regenerate those files with the pgen program. Otherwise, it builds
@@ -217,16 +215,40 @@ PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
 
+ifeq ($(BR2_PACKAGE_PYTHON_PYO_ONLY),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.py' -or -name '*.pyc' \) -print0 | xargs -0 rm -f
+endef
+endif
+
 ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
 define PYTHON_FINALIZE_TARGET
-	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.py' -or -name '*.pyo' \) -print0 | xargs -0 rm -f
 endef
 endif
 
 ifeq ($(BR2_PACKAGE_PYTHON_PY_ONLY),y)
 define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) \( -name '*.pyc' -or -name '*.pyo' \) -print0 | xargs -0 rm -f
+endef
+endif
+
+ifeq ($(BR2_PACKAGE_PYTHON_PY_PYC),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | xargs -0 rm -f
+endef
+endif
+
+ifeq ($(BR2_PACKAGE_PYTHON_PY_PYO),y)

package/python/python.mk PYTHON_PATH = $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/sysconfigdata/ · line 252

Quoted 10 lines
package/python/python.mk +6 -0
+define PYTHON_FINALIZE_TARGET
 	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyc' -print0 | xargs -0 rm -f
 endef
 endif
 
+ifeq ($(BR2_PACKAGE_PYTHON_PYC_PYO),y)
+define PYTHON_FINALIZE_TARGET
+	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.py' -print0 | xargs -0 rm -f
+endef
+endif

I'm sure we can do something smarter here.

# arg1: extension of files to remove
define PYTHON_FINALIZE_REMOVE_HELPER

	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.$(1)' -print0 | xargs -0 rm -f

endef

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PY),y)

	$(call PYTHON_FINALIZE_REMOVE_HELPER,py)

endif

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PYC),y)

	$(call PYTHON_FINALIZE_REMOVE_HELPER,pyc)

endif

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PYO),y)

	$(call PYTHON_FINALIZE_REMOVE_HELPER,pyo)

endif

BR2_PACKAGE_PYTHON_REMOVE_* being hidden Config.in options.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 python: Allow pyo only and variants

Quoted 12 lines · Thomas Petazzoni

I'm sure we can do something smarter here.

# arg1: extension of files to remove
define PYTHON_FINALIZE_REMOVE_HELPER

	find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.$(1)' -print0 | xargs -0 rm -f

endef

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PY),y)

	$(call PYTHON_FINALIZE_REMOVE_HELPER,py)

endif

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PYC),y)

Quoted 8 lines
	$(call PYTHON_FINALIZE_REMOVE_HELPER,pyc)

endif

ifeq ($(BR2_PACKAGE_PYTHON_REMOVE_PYO),y)

	$(call PYTHON_FINALIZE_REMOVE_HELPER,pyo)

endif

BR2_PACKAGE_PYTHON_REMOVE_* being hidden Config.in options.

Or make these options the public ones instead of having the huge choice.

Requires legacy handling of course.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F