* Option to change default optimization level of Python
@ 2025-04-10 6:23 Lukas Woodtli
2025-04-10 7:57 ` [OE-core] " Alexander Kanavin
2025-04-10 8:03 ` Mathieu Dubois-Briand
0 siblings, 2 replies; 4+ messages in thread
From: Lukas Woodtli @ 2025-04-10 6:23 UTC (permalink / raw)
To: openembedded-core
From 1614b1bb21b164d11aa88ff428c6bae9439b82d6 Mon Sep 17 00:00:00 2001
From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
Date: Mon, 7 Apr 2025 13:18:41 +0200
Subject: [PATCH] python3: Allow to set the default optimization level
It's possible to compile the Python interpreter for the target, that it
uses a given optimization level by default. This is as providing the
`-O` option to the interpreter (possibly one or two times) or setting
the environment variable `PYTHONOPTIMIZE`.
Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
---
...zation-level-1-as-default-for-Python.patch | 25 ++++++++++++++++++
...zation-level-2-as-default-for-Python.patch | 26 +++++++++++++++++++
.../recipes-devtools/python/python3_3.13.2.bb | 9 +++++++
3 files changed, 60 insertions(+)
create mode 100644
meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
create mode 100644
meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
diff --git
a/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
new file mode 100644
index 0000000000..98e4355b1d
--- /dev/null
+++
b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
@@ -0,0 +1,25 @@
+From ef51db9528916493d23a7e7a63cfc3b12b4ce3d9 Mon Sep 17 00:00:00 2001
+From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
+Date: Tue, 8 Apr 2025 08:26:35 +0200
+Subject: [PATCH] Use optimization level 1 as default for Python
+
+This is as if the command line option `-O` is set implicitly.
+
+Upstream-Status: Inappropriate [this is an optional enhancement just
useful for a custom build for an embedded system]
+---
+ Python/initconfig.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Python/initconfig.c b/Python/initconfig.c
+index 192089b..c451b15 100644
+--- a/Python/initconfig.c
++++ b/Python/initconfig.c
+@@ -788,7 +788,7 @@ config_init_defaults(PyConfig *config)
+ config->bytes_warning = 0;
+ config->inspect = 0;
+ config->interactive = 0;
+- config->optimization_level = 0;
++ config->optimization_level = 1;
+ config->parser_debug= 0;
+ config->write_bytecode = 1;
+ config->verbose = 0;
diff --git
a/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
new file mode 100644
index 0000000000..ca196970a6
--- /dev/null
+++
b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
@@ -0,0 +1,26 @@
+From 31d904e770437cf47b7b56161687a0d90b1bc982 Mon Sep 17 00:00:00 2001
+From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
+Date: Mon, 7 Apr 2025 13:11:02 +0200
+Subject: [PATCH] Use optimization level 2 as default for Python
+
+This is as if the command line option `-OO` is set implicitly.
+
+Upstream-Status: Inappropriate [this is an optional enhancement just
useful for a custom build for an embedded system]
+
+---
+ Python/initconfig.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Python/initconfig.c b/Python/initconfig.c
+index 192089b..3f91fac 100644
+--- a/Python/initconfig.c
++++ b/Python/initconfig.c
+@@ -788,7 +788,7 @@ config_init_defaults(PyConfig *config)
+ config->bytes_warning = 0;
+ config->inspect = 0;
+ config->interactive = 0;
+- config->optimization_level = 0;
++ config->optimization_level = 2;
+ config->parser_debug= 0;
+ config->write_bytecode = 1;
+ config->verbose = 0;
diff --git a/meta/recipes-devtools/python/python3_3.13.2.bb
b/meta/recipes-devtools/python/python3_3.13.2.bb
index 7c36fd92ed..f86c150534 100644
--- a/meta/recipes-devtools/python/python3_3.13.2.bb
+++ b/meta/recipes-devtools/python/python3_3.13.2.bb
@@ -36,6 +36,15 @@ SRC_URI:append:class-native = " \
file://0001-Lib-sysconfig.py-use-prefix-value-from-build-configu.patch \
"
+
+# Default optimization level when running the Python interpreter (`-O`
flag)
+PYTHON_DEFAULT_OPT_LEVEL ?= "0"
+
+SRC_URI:append:class-target = " \
+ ${@'file://0001-Use-optimization-level-1-as-default-for-Python.patch'
if d.getVar('PYTHON_DEFAULT_OPT_LEVEL') == '1' else ''} \
+ ${@'file://0001-Use-optimization-level-2-as-default-for-Python.patch'
if d.getVar('PYTHON_DEFAULT_OPT_LEVEL') == '2' else ''} \
+"
+
SRC_URI[sha256sum] =
"d984bcc57cd67caab26f7def42e523b1c015bbc5dc07836cf4f0b63fa159eb56"
# exclude pre-releases for both python 2.x and 3.x
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [OE-core] Option to change default optimization level of Python
2025-04-10 6:23 Option to change default optimization level of Python Lukas Woodtli
@ 2025-04-10 7:57 ` Alexander Kanavin
[not found] ` <31851.1744285641335320841@lists.openembedded.org>
2025-04-10 8:03 ` Mathieu Dubois-Briand
1 sibling, 1 reply; 4+ messages in thread
From: Alexander Kanavin @ 2025-04-10 7:57 UTC (permalink / raw)
To: lw; +Cc: openembedded-core
This needs to be proposed to python upstream first. And definitely
first reworked as an option to configure script, rather than
conditional patches that hardcode the level.
You can also install a runtime wrapper for python executable that adds
the command line option, or sets the environment variable.
As it is, it's unsuitable.
Alex
On Thu, 10 Apr 2025 at 08:23, Lukas Woodtli via lists.openembedded.org
<lw=hqv.ch@lists.openembedded.org> wrote:
>
> From 1614b1bb21b164d11aa88ff428c6bae9439b82d6 Mon Sep 17 00:00:00 2001
> From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> Date: Mon, 7 Apr 2025 13:18:41 +0200
> Subject: [PATCH] python3: Allow to set the default optimization level
>
> It's possible to compile the Python interpreter for the target, that it
> uses a given optimization level by default. This is as providing the
> `-O` option to the interpreter (possibly one or two times) or setting
> the environment variable `PYTHONOPTIMIZE`.
>
> Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> ---
> ...zation-level-1-as-default-for-Python.patch | 25 ++++++++++++++++++
> ...zation-level-2-as-default-for-Python.patch | 26 +++++++++++++++++++
> .../recipes-devtools/python/python3_3.13.2.bb | 9 +++++++
> 3 files changed, 60 insertions(+)
> create mode 100644
> meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
> create mode 100644
> meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
>
> diff --git
> a/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
> b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
> new file mode 100644
> index 0000000000..98e4355b1d
> --- /dev/null
> +++
> b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-1-as-default-for-Python.patch
> @@ -0,0 +1,25 @@
> +From ef51db9528916493d23a7e7a63cfc3b12b4ce3d9 Mon Sep 17 00:00:00 2001
> +From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> +Date: Tue, 8 Apr 2025 08:26:35 +0200
> +Subject: [PATCH] Use optimization level 1 as default for Python
> +
> +This is as if the command line option `-O` is set implicitly.
> +
> +Upstream-Status: Inappropriate [this is an optional enhancement just
> useful for a custom build for an embedded system]
> +---
> + Python/initconfig.c | 2 +-
> + 1 file changed, 1 insertion(+), 1 deletion(-)
> +
> +diff --git a/Python/initconfig.c b/Python/initconfig.c
> +index 192089b..c451b15 100644
> +--- a/Python/initconfig.c
> ++++ b/Python/initconfig.c
> +@@ -788,7 +788,7 @@ config_init_defaults(PyConfig *config)
> + config->bytes_warning = 0;
> + config->inspect = 0;
> + config->interactive = 0;
> +- config->optimization_level = 0;
> ++ config->optimization_level = 1;
> + config->parser_debug= 0;
> + config->write_bytecode = 1;
> + config->verbose = 0;
> diff --git
> a/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
> b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
> new file mode 100644
> index 0000000000..ca196970a6
> --- /dev/null
> +++
> b/meta/recipes-devtools/python/python3/0001-Use-optimization-level-2-as-default-for-Python.patch
> @@ -0,0 +1,26 @@
> +From 31d904e770437cf47b7b56161687a0d90b1bc982 Mon Sep 17 00:00:00 2001
> +From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> +Date: Mon, 7 Apr 2025 13:11:02 +0200
> +Subject: [PATCH] Use optimization level 2 as default for Python
> +
> +This is as if the command line option `-OO` is set implicitly.
> +
> +Upstream-Status: Inappropriate [this is an optional enhancement just
> useful for a custom build for an embedded system]
> +
> +---
> + Python/initconfig.c | 2 +-
> + 1 file changed, 1 insertion(+), 1 deletion(-)
> +
> +diff --git a/Python/initconfig.c b/Python/initconfig.c
> +index 192089b..3f91fac 100644
> +--- a/Python/initconfig.c
> ++++ b/Python/initconfig.c
> +@@ -788,7 +788,7 @@ config_init_defaults(PyConfig *config)
> + config->bytes_warning = 0;
> + config->inspect = 0;
> + config->interactive = 0;
> +- config->optimization_level = 0;
> ++ config->optimization_level = 2;
> + config->parser_debug= 0;
> + config->write_bytecode = 1;
> + config->verbose = 0;
> diff --git a/meta/recipes-devtools/python/python3_3.13.2.bb
> b/meta/recipes-devtools/python/python3_3.13.2.bb
> index 7c36fd92ed..f86c150534 100644
> --- a/meta/recipes-devtools/python/python3_3.13.2.bb
> +++ b/meta/recipes-devtools/python/python3_3.13.2.bb
> @@ -36,6 +36,15 @@ SRC_URI:append:class-native = " \
> file://0001-Lib-sysconfig.py-use-prefix-value-from-build-configu.patch \
> "
>
> +
> +# Default optimization level when running the Python interpreter (`-O`
> flag)
> +PYTHON_DEFAULT_OPT_LEVEL ?= "0"
> +
> +SRC_URI:append:class-target = " \
> + ${@'file://0001-Use-optimization-level-1-as-default-for-Python.patch'
> if d.getVar('PYTHON_DEFAULT_OPT_LEVEL') == '1' else ''} \
> + ${@'file://0001-Use-optimization-level-2-as-default-for-Python.patch'
> if d.getVar('PYTHON_DEFAULT_OPT_LEVEL') == '2' else ''} \
> +"
> +
> SRC_URI[sha256sum] =
> "d984bcc57cd67caab26f7def42e523b1c015bbc5dc07836cf4f0b63fa159eb56"
>
> # exclude pre-releases for both python 2.x and 3.x
> --
> 2.43.0
>
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#214619): https://lists.openembedded.org/g/openembedded-core/message/214619
> Mute This Topic: https://lists.openembedded.org/mt/112186757/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [OE-core] Option to change default optimization level of Python
2025-04-10 6:23 Option to change default optimization level of Python Lukas Woodtli
2025-04-10 7:57 ` [OE-core] " Alexander Kanavin
@ 2025-04-10 8:03 ` Mathieu Dubois-Briand
1 sibling, 0 replies; 4+ messages in thread
From: Mathieu Dubois-Briand @ 2025-04-10 8:03 UTC (permalink / raw)
To: Lukas Woodtli, openembedded-core
On Thu Apr 10, 2025 at 8:23 AM CEST, Lukas Woodtli wrote:
> From 1614b1bb21b164d11aa88ff428c6bae9439b82d6 Mon Sep 17 00:00:00 2001
> From: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> Date: Mon, 7 Apr 2025 13:18:41 +0200
> Subject: [PATCH] python3: Allow to set the default optimization level
>
> It's possible to compile the Python interpreter for the target, that it
> uses a given optimization level by default. This is as providing the
> `-O` option to the interpreter (possibly one or two times) or setting
> the environment variable `PYTHONOPTIMIZE`.
>
> Signed-off-by: Lukas Woodtli <lukas.woodtli@husqvarnagroup.com>
> ---
Hi Lukas,
Thanks for your patch. However, it seems it was corrupted somehow in the
sending process. This comes either from your mailer or the behaviour of
your mail server. Are you using 'git send-email' or 'b4 prep' to send
it?
First, it looks like long lines are wrapped, so git cannot understand
them. I tried a bit to reconstruct a correct patch, but failed. So maybe
something else was also modified in the process.
Can you please try to fix this? It looks like there is the same issue
for your other patch.
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-10 12:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 6:23 Option to change default optimization level of Python Lukas Woodtli
2025-04-10 7:57 ` [OE-core] " Alexander Kanavin
[not found] ` <31851.1744285641335320841@lists.openembedded.org>
[not found] ` <CANNYZj_1OmBvTShfEkN2GX0dYOOiDKQHV8T3A300exv637Zk8w@mail.gmail.com>
2025-04-10 12:53 ` Private: " Lukas Woodtli
2025-04-10 8:03 ` Mathieu Dubois-Briand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox