python: remove *.pyo files
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Sun, 1 May 2016 20:15:14 +0000 (22:15 +0200)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tue, 17 May 2016 20:47:33 +0000 (22:47 +0200)
Even though we disable the build of .pyo files in the interpreter,
nothing prevents other packages to install them. Since we only want to
keep either .py or .pyc or both, let's add a target finalize hooks
that removes all .pyo files.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
[Thomas: add --no-run-if-empty option to xargs, as suggested by Samuel.]
Reviewed-by: Samuel Martin <s.martin49@gmail.com>
package/python/python.mk

index 819d32b9d64c236770a7d5d1bf920a43748ba80d..c96d21897e813f255fbcbbb7196101f36db7f697 100644 (file)
@@ -230,3 +230,11 @@ define PYTHON_REMOVE_PYC_FILES
 endef
 TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYC_FILES
 endif
+
+# In all cases, we don't want to keep the optimized .pyo files
+ifeq ($(BR2_PACKAGE_PYTHON),y)
+define PYTHON_REMOVE_PYO_FILES
+       find $(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR) -name '*.pyo' -print0 | xargs -0 --no-run-if-empty rm -f
+endef
+TARGET_FINALIZE_HOOKS += PYTHON_REMOVE_PYO_FILES
+endif