Skip to contentSkip to conversation

configure: check for supported Python 2.x versions

PATCH Lluís Vilanova 2 participants 3 messages May 1, 2012 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 16 lines · Stefan Hajnoczi

The tracetool code requires Python 2.4, which was released in 2004. Check for a supported Python version so we can give a clear error message.

---
 configure |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
configure +0 -0
index 25697bb..0e6fbbc 100755
@@ -1247,9 +1247,10 @@ fi
 
 # Note that if the Python conditional here evaluates True we will exit

configure fi · line 1255

Quoted 10 lines
configure +4 -3
 # with status 1 which is a shell 'false' value.
-if ! "$python" -c 'import sys; sys.exit(sys.version_info[0] >= 3)'; then
-  echo "Python 2 required but '$python' is version 3 or better."
-  echo "Use --python=/path/to/python to specify a Python 2."
+if ! "$python" -c 'import sys; sys.version_info < (2,4) or sys.version_info >= (3,)'; then
+  echo "Cannot use '$python', Python 2.4 or later is required."
+  echo "Note that Python 3 or later is not yet supported."
+  echo "Use --python=/path/to/python to specify a supported Python."
   exit 1
 fi

Shouldn't this be using "sys.exit(...version checks...)" ?

Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#3 lore raw
Quoted 17 lines · Lluís Vilanova
Quoted 14 lines · Stefan Hajnoczi

The tracetool code requires Python 2.4, which was released in 2004. Check for a supported Python version so we can give a clear error message.

---
 configure |    7 ++++---

 1 file changed, 4 insertions(+), 3 deletions(-)
configure +0 -0
index 25697bb..0e6fbbc 100755
@@ -1247,9 +1247,10 @@ fi
Quoted 13 lines
Quoted 11 lines
configure +4 -3
  # 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[0] >= 3)'; then
-  echo "Python 2 required but '$python' is version 3 or better."
-  echo "Use --python=/path/to/python to specify a Python 2."
+if ! "$python" -c 'import sys; sys.version_info < (2,4) or sys.version_info >= (3,)'; then
+  echo "Cannot use '$python', Python 2.4 or later is required."
+  echo "Note that Python 3 or later is not yet supported."
+  echo "Use --python=/path/to/python to specify a supported Python."

   exit 1
 fi

Shouldn't this be using "sys.exit(...version checks...)" ?

Yes, thanks for pointing it out.

Stefan

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#5 lore raw

Re: [Qemu-devel] [PATCH v2 5/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function

Quoted 5 lines · Stefan Hajnoczi

The pkgutil.iter_modules() function provides a way to enumerate child modules. Unfortunately it's missing in Python <2.7 so we must implement similar behavior ourselves.

Quoted 59 lines
---
 scripts/tracetool/backend/__init__.py |    8 ++++++--
 scripts/tracetool/format/__init__.py  |    8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)
scripts/tracetool/backend/__init__.py +6 -2
index 34b7ed8..be43472 100644
@@ -37,7 +37,7 @@ __maintainer__ = "Stefan Hajnoczi"
 __email__      = "[email protected]"
 
 
-import pkgutil
+import os
 
 import tracetool
 
@@ -45,7 +45,11 @@ import tracetool
 def get_list():
     """Get a list of (name, description) pairs."""
     res = [("nop", "Tracing disabled.")]
-    for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__):
+    modnames = []
+    for filename in os.listdir(tracetool.backend.__path__[0]):
+        if filename.endswith('.py') and filename != '__init__.py':
+            modnames.append(filename.rsplit('.', 1)[0])
+    for modname in modnames:
         module = tracetool.try_import("tracetool.backend." + modname)
 
         # just in case; should never fail unless non-module files are put there
scripts/tracetool/format/__init__.py +6 -2
index 0e4baf0..3c2a0d8 100644
@@ -41,7 +41,7 @@ __maintainer__ = "Stefan Hajnoczi"
 __email__      = "[email protected]"
 
 
-import pkgutil
+import os
 
 import tracetool
 
@@ -49,7 +49,11 @@ import tracetool
 def get_list():
     """Get a list of (name, description) pairs."""
     res = []
-    for _, modname, _ in pkgutil.iter_modules(tracetool.format.__path__):
+    modnames = []
+    for filename in os.listdir(tracetool.format.__path__[0]):
+        if filename.endswith('.py') and filename != '__init__.py':
+            modnames.append(filename.rsplit('.', 1)[0])
+    for modname in modnames:
         module = tracetool.try_import("tracetool.format." + modname)
 
         # just in case; should never fail unless non-module files are put there
Signature · 1 line
1.7.10
Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth