* [Buildroot] [RFC] Python pyc compilation check
@ 2016-02-08 21:51 Yegor Yefremov
2016-02-09 22:47 ` Arnout Vandecappelle
0 siblings, 1 reply; 2+ messages in thread
From: Yegor Yefremov @ 2016-02-08 21:51 UTC (permalink / raw)
To: buildroot
As promised Samuel's patch:
diff --git a/package/python/python.mk b/package/python/python.mk
index 5ef3589..1d131c0 100644
--- a/package/python/python.mk
+++ b/package/python/python.mk
@@ -220,8 +220,9 @@ $(eval $(host-autotools-package))
define PYTHON_CREATE_PYC_FILES
PYTHONPATH="$(PYTHON_PATH)" \
- $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) -c "import compileall; \
- compileall.compile_dir('$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)')"
+ $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) \
+ $(TOPDIR)/support/scripts/pycompile.py \
+ "$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)"
endef
ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
diff --git a/package/python3/python3.mk b/package/python3/python3.mk
index 507c610..1eb356b 100644
--- a/package/python3/python3.mk
+++ b/package/python3/python3.mk
@@ -217,8 +217,9 @@ $(eval $(host-autotools-package))
define PYTHON3_CREATE_PYC_FILES
PYTHONPATH="$(PYTHON3_PATH)" \
- $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) -c "import compileall; \
- compileall.compile_dir('$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)')"
+ $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
+ $(TOPDIR)/support/scripts/pycompile.py \
+ "$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
endef
ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
diff --git a/support/scripts/pycompile.py b/support/scripts/pycompile.py
new file mode 100755
index 0000000..fde711a
--- /dev/null
+++ b/support/scripts/pycompile.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+# Wrapper for python2 and python3 around compileall to raise exception
+# when a python byte code generation failed.
+#
+# Inspired from:
+# http://stackoverflow.com/questions/615632/how-to-detect-errors-from-compileall-compile-dir
+
+from __future__ import print_function
+import sys
+import py_compile
+import compileall
+
+class ReportProblem:
+ def __nonzero__(self):
+ type, value, traceback = sys.exc_info()
+ if type is not None and issubclass(type, py_compile.PyCompileError):
+ print("Cannot compile %s" %value.file)
+ raise value
+ return 1
+
+report_problem = ReportProblem()
+
+compileall.compile_dir(sys.argv[1], quiet=report_problem)
Yegor
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [Buildroot] [RFC] Python pyc compilation check
2016-02-08 21:51 [Buildroot] [RFC] Python pyc compilation check Yegor Yefremov
@ 2016-02-09 22:47 ` Arnout Vandecappelle
0 siblings, 0 replies; 2+ messages in thread
From: Arnout Vandecappelle @ 2016-02-09 22:47 UTC (permalink / raw)
To: buildroot
This is just an RFC, but if it gets good review I guess you intend to squash it
with the other series?
I'm basically OK with the concept of this patch, with a few remarks still below.
On 08-02-16 22:51, Yegor Yefremov wrote:
> As promised Samuel's patch:
>
> diff --git a/package/python/python.mk b/package/python/python.mk
> index 5ef3589..1d131c0 100644
> --- a/package/python/python.mk
> +++ b/package/python/python.mk
> @@ -220,8 +220,9 @@ $(eval $(host-autotools-package))
>
> define PYTHON_CREATE_PYC_FILES
> PYTHONPATH="$(PYTHON_PATH)" \
> - $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) -c "import compileall; \
> - compileall.compile_dir('$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)')"
> + $(HOST_DIR)/usr/bin/python$(PYTHON_VERSION_MAJOR) \
You should add indentation here.
> + $(TOPDIR)/support/scripts/pycompile.py \
$(TOPDIR) isn't needed, it is always executed from the top directory.
> + "$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)"
> endef
>
> ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
> diff --git a/package/python3/python3.mk b/package/python3/python3.mk
> index 507c610..1eb356b 100644
> --- a/package/python3/python3.mk
> +++ b/package/python3/python3.mk
> @@ -217,8 +217,9 @@ $(eval $(host-autotools-package))
>
> define PYTHON3_CREATE_PYC_FILES
> PYTHONPATH="$(PYTHON3_PATH)" \
> - $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) -c "import compileall; \
> - compileall.compile_dir('$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)')"
> + $(HOST_DIR)/usr/bin/python$(PYTHON3_VERSION_MAJOR) \
> + $(TOPDIR)/support/scripts/pycompile.py \
> + "$(TARGET_DIR)/usr/lib/python$(PYTHON3_VERSION_MAJOR)"
Same same.
> endef
>
> ifeq ($(BR2_PACKAGE_PYTHON3_PYC_ONLY),y)
> diff --git a/support/scripts/pycompile.py b/support/scripts/pycompile.py
> new file mode 100755
> index 0000000..fde711a
> --- /dev/null
> +++ b/support/scripts/pycompile.py
> @@ -0,0 +1,24 @@
> +#!/usr/bin/env python
> +
> +# Wrapper for python2 and python3 around compileall to raise exception
> +# when a python byte code generation failed.
> +#
> +# Inspired from:
> +# http://stackoverflow.com/questions/615632/how-to-detect-errors-from-compileall-compile-dir
> +
> +from __future__ import print_function
> +import sys
> +import py_compile
> +import compileall
> +
> +class ReportProblem:
> + def __nonzero__(self):
This could really use some comment to explain why it needs to be a class with a
__nonzero__ member.
Regards,
Arnout
> + type, value, traceback = sys.exc_info()
> + if type is not None and issubclass(type, py_compile.PyCompileError):
> + print("Cannot compile %s" %value.file)
> + raise value
> + return 1
> +
> +report_problem = ReportProblem()
> +
> +compileall.compile_dir(sys.argv[1], quiet=report_problem)
>
> Yegor
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
>
--
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: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-09 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-08 21:51 [Buildroot] [RFC] Python pyc compilation check Yegor Yefremov
2016-02-09 22:47 ` Arnout Vandecappelle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox