[Checkins] SVN: z3c.checkversions/trunk/z3c/checkversions/ Some Python 3 compatibility.

Marius Gedminas cvs-admin at zope.org
Mon Jun 11 09:10:39 UTC 2012


Log message for revision 126709:
  Some Python 3 compatibility.
  
  I assumed it was desired because I saw some statements of the form
  
    print("single-line string")
  
  Unfortunately I hit a wall by what seems to be a bug in distribute on
  Python 3: when given a file:/// URL it tries to read it (as bytes) and
  pass the body into io.StringIO() (which wants str).

Changed:
  U   z3c.checkversions/trunk/z3c/checkversions/buildout.py
  U   z3c.checkversions/trunk/z3c/checkversions/buildout.txt
  U   z3c.checkversions/trunk/z3c/checkversions/installed.py
  U   z3c.checkversions/trunk/z3c/checkversions/test.py

-=-
Modified: z3c.checkversions/trunk/z3c/checkversions/buildout.py
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/buildout.py	2012-06-11 09:10:30 UTC (rev 126708)
+++ z3c.checkversions/trunk/z3c/checkversions/buildout.py	2012-06-11 09:10:36 UTC (rev 126709)
@@ -15,7 +15,7 @@
 try:
     from zc.buildout.buildout import Buildout
 except ImportError:
-    raise ImportError(u"zc.buildout is not installed! \n"
+    raise ImportError("zc.buildout is not installed! \n"
           "If you're in a buildout environment,\n"
           "enable the buildout extra requirement like this:\n"
           "eggs = z3c.checkversions [buildout]")
@@ -38,7 +38,7 @@
         if not self.__custom_url:
             self._set_index_url(buildout_index)
 
-        print(u"# Checking buildout file %s" % self.filename)
+        print("# Checking buildout file %s" % self.filename)
         return buildout['versions']
 
 

Modified: z3c.checkversions/trunk/z3c/checkversions/buildout.txt
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/buildout.txt	2012-06-11 09:10:30 UTC (rev 126708)
+++ z3c.checkversions/trunk/z3c/checkversions/buildout.txt	2012-06-11 09:10:36 UTC (rev 126709)
@@ -7,16 +7,14 @@
 >>> from os.path import dirname, sep
 >>> testindex = 'file://' + dirname(z3c.checkversions.__file__).replace(sep, '/') + '/testindex'
 >>> testindex2 = 'file://' + dirname(z3c.checkversions.__file__).replace(sep, '/') + '/testindex2'
->>> print testindex
+>>> print(testindex)
 file:///.../testindex
 
 We create a buildout with a [versions] section and a custom index:
 
 >>> import os
->>> from tempfile import mkstemp
->>> buildout_fd, buildout_path = mkstemp()
->>> buildout_file = os.fdopen(buildout_fd, 'w')
->>> buildout_file.write("""
+>>> from z3c.checkversions.test import write_temp_file
+>>> buildout_path = write_temp_file("""
 ... [buildout]
 ... index = %s
 ... versions = versions
@@ -24,7 +22,6 @@
 ... zope.interface = 3.4.0
 ... zope.component = 3.0.0
 ... """ % testindex)
->>> buildout_file.close()
 
 We can now check the new highest versions:
 
@@ -68,9 +65,7 @@
 The old comments are removed:
 
 >>> os.remove(buildout_path)
->>> buildout_fd, buildout_path = mkstemp()
->>> buildout_file = os.fdopen(buildout_fd, 'w')
->>> buildout_file.write("""
+>>> buildout_path = write_temp_file("""
 ... [buildout]
 ... index = %s
 ... versions = versions
@@ -79,7 +74,6 @@
 ... zope.interface = 3.4.1
 ... zope.component = 3.0.3
 ... """ % testindex)
->>> buildout_file.close()
 
 >>> checker = buildout.Checker(filename=buildout_path, verbose=True)
 >>> checker.check()
@@ -92,12 +86,9 @@
 We can provide a blacklist file, containing versions to not suggest.
 This file may come from a buildbot remembering failures.
 
->>> blacklist_fd, blacklist_path = mkstemp()
->>> blacklist_file = os.fdopen(blacklist_fd, 'w')
->>> blacklist_file.write("""
+>>> blacklist_path = write_temp_file("""
 ... zope.component =3.9.4  
 ... zope.component = 3.9.3""")
->>> blacklist_file.close()
 
 >>> checker = buildout.Checker(filename=buildout_path,
 ...                            verbose=True,
@@ -142,5 +133,3 @@
 >>> p.stdout.read().lower().startswith('usage: ')
 True
 
-
-

Modified: z3c.checkversions/trunk/z3c/checkversions/installed.py
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/installed.py	2012-06-11 09:10:30 UTC (rev 126708)
+++ z3c.checkversions/trunk/z3c/checkversions/installed.py	2012-06-11 09:10:36 UTC (rev 126709)
@@ -21,7 +21,7 @@
     def get_versions(self, level=0):
         working_set = pkg_resources.working_set
         versions = dict([(d.key, d.version) for d in working_set])
-        print "# Checking your installed distributions"
+        print("# Checking your installed distributions")
         return versions
 
 

Modified: z3c.checkversions/trunk/z3c/checkversions/test.py
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/test.py	2012-06-11 09:10:30 UTC (rev 126708)
+++ z3c.checkversions/trunk/z3c/checkversions/test.py	2012-06-11 09:10:36 UTC (rev 126709)
@@ -14,7 +14,16 @@
 
 from doctest import DocFileSuite, ELLIPSIS, NORMALIZE_WHITESPACE
 import distutils.log
+import os
+import tempfile
 
+def write_temp_file(content):
+    fd, path = tempfile.mkstemp(prefix='test-z3c.checkversions-')
+    f = os.fdopen(fd, 'w')
+    f.write(content)
+    f.close()
+    return path
+
 def setUp(test):
     test._old_log_level = distutils.log.set_threshold(distutils.log.ERROR)
 



More information about the checkins mailing list