Skip to contentSkip to conversation

configure: Don't write .pyc files by default (python -B)

PATCH In review Stefan Weil 3 participants 5 messages Aug 27, 2013 – Nov 15, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Don't write .pyc files by default (python -B)

When a Python script is run, Python normally writes bytecode into a .pyc file. QEMU's build process uses several Python scripts which are called from configure or make.

The generated .pyc files take disk space without being of much use, because those scripts are short, not time critical and only called a few times.

Python's option -B disables writing of .pyc files. QEMU now uses "python -B" as default, but it is still possible to choose a different call by passing --python=PYTHON to configure.

---

It was necessary to change from "$python" to simply $python in the Python test. This should not matter: we already have a simple $python in configure, and Python wants to be installed in a path without spaces.

Stefan

 configure |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
index 0a55c20..db69327 100755
@@ -568,7 +568,7 @@ fi
 
 : ${make=${MAKE-make}}
 : ${install=${INSTALL-install}}
-: ${python=${PYTHON-python}}
+: ${python=${PYTHON-python -B}}
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1348,7 +1348,7 @@ fi
 
 # Note that if the Python conditional here evaluates True we will exit
 # with status 1 which is a shell 'false' value.
-if ! "$python" -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then
+if ! $python -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then
   error_exit "Cannot use '$python', Python 2.4 or later is required." \
       "Note that Python 3 or later is not yet supported." \
       "Use --python=/path/to/python to specify a supported Python."
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 10 lines · Stefan Weil

When a Python script is run, Python normally writes bytecode into a .pyc file. QEMU's build process uses several Python scripts which are called from configure or make.

The generated .pyc files take disk space without being of much use, because those scripts are short, not time critical and only called a few times.

Python's option -B disables writing of .pyc files. QEMU now uses "python -B" as default, but it is still possible to choose a different call by passing --python=PYTHON to configure.

Yay, thank you for this!
Applied to the trivial-patches queue.

/mjt

#2 lore raw
In reply to Stefan Weil
Quoted 47 lines · Stefan Weil

When a Python script is run, Python normally writes bytecode into a .pyc file. QEMU's build process uses several Python scripts which are called from configure or make.

The generated .pyc files take disk space without being of much use, because those scripts are short, not time critical and only called a few times.

Python's option -B disables writing of .pyc files. QEMU now uses "python -B" as default, but it is still possible to choose a different call by passing --python=PYTHON to configure.

---

It was necessary to change from "$python" to simply $python in the Python test. This should not matter: we already have a simple $python in configure, and Python wants to be installed in a path without spaces.

Stefan

 configure |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure +2 -3
index 0a55c20..db69327 100755
@@ -568,7 +568,7 @@ fi
 
 : ${make=${MAKE-make}}
 : ${install=${INSTALL-install}}
-: ${python=${PYTHON-python}}
+: ${python=${PYTHON-python -B}}
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1348,7 +1348,7 @@ fi
 
 # Note that if the Python conditional here evaluates True we will exit
 # with status 1 which is a shell 'false' value.
-if ! "$python" -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then
+if ! $python -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then
   error_exit "Cannot use '$python', Python 2.4 or later is required." \
       "Note that Python 3 or later is not yet supported." \
       "Use --python=/path/to/python to specify a supported Python."
--
Quoted 1 line

1.7.10.4

This patch breaks ./configure on RHEL 5 and other older distros that use Python 2.4.

The version test in ./configure fails because the python interpreter does not accept the -B option:
http://buildbot.b1-systems.de/qemu/builders/default_x86_64_rhel5/builds/762/steps/configure/logs/stdio

Can you add -B after version detection, if available? (No .pyc is generated for statements evaluated on the command-line during version detection.)

Stefan

#3 lore raw

Am 14.11.2013 15:45, schrieb Stefan Hajnoczi:

Quoted 21 lines · Stefan Weil
Quoted 20 lines

When a Python script is run, Python normally writes bytecode into a .pyc file. QEMU's build process uses several Python scripts which are called from configure or make.

The generated .pyc files take disk space without being of much use, because those scripts are short, not time critical and only called a few times.

Python's option -B disables writing of .pyc files. QEMU now uses "python -B" as default, but it is still possible to choose a different call by passing --python=PYTHON to configure.

---

It was necessary to change from "$python" to simply $python in the Python test. This should not matter: we already have a simple $python in configure, and Python wants to be installed in a path without spaces.

Stefan

[...]

Quoted 7 lines
Quoted 7 lines

This patch breaks ./configure on RHEL 5 and other older distros that use Python 2.4.

The version test in ./configure fails because the python interpreter does not accept the -B option:
http://buildbot.b1-systems.de/qemu/builders/default_x86_64_rhel5/builds/762/steps/configure/logs/stdio

Quoted 5 lines
Quoted 5 lines

Can you add -B after version detection, if available? (No .pyc is generated for statements evaluated on the command-line during version detection.)

Stefan

I'm sorry that I did not notice this regression in the buildbot report.

We have several possibilities how we can handle this incompatibility for old versions of Python.

According to http://docs.python.org/2/whatsnew/2.6.html, the -B option was introduced with
Python 2.6 which was released on October 1 2008.

Solution 1: We don't modify the current configure script because it works with Python versions
since 5 years. For older versions there is a very simple workaround:
call configure with
--python=python. This additional parameter would also be needed for the buildbots running
with Python 2.4.

Solution 2: I modify the configure script to set -B only if it is supported. This makes it marginally
longer (more lines of code, one more Python execution).

Would 1 be sufficient, or do you prefer getting a patch with solution 2? In any case, I don't think
this is a must for QEMU 1.7.

Stefan

#4 lore raw
Quoted 53 lines · Stefan Weil

Am 14.11.2013 15:45, schrieb Stefan Hajnoczi:

Quoted 21 lines · Stefan Weil
Quoted 20 lines

When a Python script is run, Python normally writes bytecode into a .pyc file. QEMU's build process uses several Python scripts which are called from configure or make.

The generated .pyc files take disk space without being of much use, because those scripts are short, not time critical and only called a few times.

Python's option -B disables writing of .pyc files. QEMU now uses "python -B" as default, but it is still possible to choose a different call by passing --python=PYTHON to configure.

---

It was necessary to change from "$python" to simply $python in the Python test. This should not matter: we already have a simple $python in configure, and Python wants to be installed in a path without spaces.

Stefan

[...]

Quoted 7 lines
Quoted 7 lines

This patch breaks ./configure on RHEL 5 and other older distros that use Python 2.4.

The version test in ./configure fails because the python interpreter does not accept the -B option:
http://buildbot.b1-systems.de/qemu/builders/default_x86_64_rhel5/builds/762/steps/configure/logs/stdio

Quoted 5 lines
Quoted 5 lines

Can you add -B after version detection, if available? (No .pyc is generated for statements evaluated on the command-line during version detection.)

Stefan

I'm sorry that I did not notice this regression in the buildbot report.

We have several possibilities how we can handle this incompatibility for old versions of Python.

According to http://docs.python.org/2/whatsnew/2.6.html, the -B option was introduced with
Python 2.6 which was released on October 1 2008.

Solution 1: We don't modify the current configure script because it works with Python versions
since 5 years. For older versions there is a very simple workaround:
call configure with
--python=python. This additional parameter would also be needed for the buildbots running
with Python 2.4.

Quoted 7 lines

Solution 2: I modify the configure script to set -B only if it is supported. This makes it marginally
longer (more lines of code, one more Python execution).

Would 1 be sufficient, or do you prefer getting a patch with solution 2? In any case, I don't think
this is a must for QEMU 1.7.

Thanks, the patch you sent looks good.

Stefan