[Zope-CVS] SVN: zpkgtools/trunk/zpkg Better Python 2.2.x support
for zpkg.
Fred L. Drake, Jr.
fred at zope.com
Tue Jun 22 13:34:41 EDT 2004
Log message for revision 25939:
Better Python 2.2.x support for zpkg.
- add a trivial Handler base class to zpkgsetup.loggingapi, for use
from zpkgtools.tests.test_locationmap
- cause zpkgtools.tests.test_locationmap to use loggingapi instead of
requiring the Python 2.3+ logging package
- zpkgtools.locationmap no longer uses the sets module
- zpkgsetup.publication no longer uses the headersonly option to
email.Parser.Parser; uses email.Parser.HeaderParser instead
- zpkgsetup.tests.support provides compatibility versions of
tempfile.gettempdir() and tempfile.mkdtemp(), but only suitable for
tests since security isn't handled
- use a subclass of distutils.extension.Extension for Python 2.2.x to
add the language and depends attributes
Running the zkpg script still requires Python 2.3 or newer, but
building and installing a generated package can be done with Python
2.2 or newer.
-=-
Modified: zpkgtools/trunk/zpkgsetup/dist.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/dist.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/dist.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,6 +16,7 @@
$Id$
"""
import distutils.dist
+import distutils.extension
import sys
@@ -23,7 +24,30 @@
distutils.dist.DistributionMetadata.classifiers = None
distutils.dist.DistributionMetadata.download_url = None
+ from distutils.extension import Extension
+ class ZPkgExtension(Extension):
+
+ def __init__(self, *args, **kw):
+ self.depends = []
+ self.language = None
+ if "depends" in kw:
+ self.depends = kw["depends"] or []
+ del kw["depends"]
+ if "language" in kw:
+ self.language = kw["language"]
+ del kw["language"]
+ Extension.__init__(self, *args, **kw)
+
+ distutils.extension.Extension = ZPkgExtension
+
+ import distutils.core
+ distutils.core.Extension = ZPkgExtension
+else:
+ ZPkgExtension = distutils.extension.Extension
+
+
+
class ZPkgDistribution(distutils.dist.Distribution):
def __init__ (self, attrs=None):
Modified: zpkgtools/trunk/zpkgsetup/loggingapi.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/loggingapi.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/loggingapi.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -26,7 +26,7 @@
from logging import getLogger
from logging import CRITICAL, FATAL, ERROR, WARNING, WARN
from logging import INFO, DEBUG, NOTSET
- from logging import StreamHandler
+ from logging import Handler, StreamHandler
except ImportError:
@@ -87,6 +87,12 @@
print >>self._handler, msg
+ class Handler:
+
+ def __init__(self):
+ pass
+
+
def StreamHandler():
import sys
return sys.stderr
Modified: zpkgtools/trunk/zpkgsetup/package.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/package.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/package.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -65,10 +65,10 @@
import re
import urllib
-from distutils.core import Extension
from StringIO import StringIO
from zpkgsetup import cfgparser
+from zpkgsetup import dist
PACKAGE_CONF = "SETUP.cfg"
@@ -244,7 +244,7 @@
kwargs["language"] = section.language[0]
if reldir and reldir != ".":
kwargs["include_dirs"] = [reldir]
- return Extension(**kwargs)
+ return dist.ZPkgExtension(**kwargs)
def expand_globs(directory, reldir, globlist):
Modified: zpkgtools/trunk/zpkgsetup/publication.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/publication.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/publication.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -22,7 +22,7 @@
"""
from distutils.dist import DistributionMetadata
from distutils.util import rfc822_escape
-from email.Parser import Parser
+from email.Parser import HeaderParser
from StringIO import StringIO
@@ -107,8 +107,8 @@
`DistributionMetadata` instance will be used.
"""
- parser = Parser()
- msg = parser.parse(f, headersonly=True)
+ parser = HeaderParser()
+ msg = parser.parse(f)
return _loadmsg(msg, versioninfo, metadata)
@@ -126,8 +126,8 @@
`DistributionMetadata` instance will be used.
"""
- parser = Parser()
- msg = parser.parsestr(text, headersonly=True)
+ parser = HeaderParser()
+ msg = parser.parsestr(text)
return _loadmsg(msg, versioninfo, metadata)
Added: zpkgtools/trunk/zpkgsetup/tests/tempfileapi.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/tempfileapi.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/tests/tempfileapi.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -0,0 +1,44 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Python 2.2 compatibility code.
+
+$Id$
+"""
+import os
+import tempfile
+
+
+try:
+ from tempfile import mkdtemp
+except ImportError:
+ def mkdtemp(prefix=None):
+ # This doesn't have the security promises of
+ # tempfile.mkdtemp(), but we don't really care about those for
+ # the tests.
+ old_template = tempfile.template
+ if prefix is not None:
+ tempfile.template = prefix
+ try:
+ tmpdir = tempfile.mktemp()
+ finally:
+ tempfile.template = old_template
+ os.mkdir(tmpdir)
+ return tmpdir
+
+
+try:
+ from template import gettempdir
+except ImportError:
+ def gettempdir():
+ return tempfile.tempdir
Property changes on: zpkgtools/trunk/zpkgsetup/tests/tempfileapi.py
___________________________________________________________________
Name: svn:mime-type
+ text/x-python
Name: svn:eol-style
+ native
Modified: zpkgtools/trunk/zpkgsetup/tests/test_package.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_package.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgsetup/tests/test_package.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,7 +16,6 @@
import doctest
import os.path
import shutil
-import tempfile
import unittest
from distutils.core import Extension
@@ -24,6 +23,7 @@
from zpkgsetup import cfgparser
from zpkgsetup import package
+from zpkgsetup.tests import tempfileapi as tempfile
class PackageInfoTestCase(unittest.TestCase):
@@ -205,7 +205,10 @@
def test_suite():
- suite = doctest.DocTestSuite("zpkgsetup.package")
+ suite = unittest.TestSuite()
+ if hasattr(doctest, "DocTestSuite"):
+ # Python 2.2.x has no DocTestSuite
+ suite.addTest(doctest.DocTestSuite("zpkgsetup.package"))
suite.addTest(unittest.makeSuite(PackageInfoTestCase))
return suite
Modified: zpkgtools/trunk/zpkgtools/locationmap.py
===================================================================
--- zpkgtools/trunk/zpkgtools/locationmap.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/locationmap.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,7 +16,6 @@
import os.path
import posixpath
import re
-import sets
import urllib
import urllib2
import urlparse
@@ -151,7 +150,7 @@
pass
if mapping is None:
mapping = LocationMap()
- local_entries = sets.Set()
+ local_entries = {}
lineno = 0
for line in f:
lineno += 1
@@ -203,7 +202,7 @@
# We only want to add it once, so that loading several
# mappings causes the first defining a resource to "win":
mapping[resource] = url
- local_entries.add(resource)
+ local_entries[resource] = resource
return mapping
Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,13 +16,13 @@
import os
import shutil
import sys
-import tempfile
import unittest
import urllib
from StringIO import StringIO
from zpkgsetup import publication
+from zpkgsetup.tests import tempfileapi as tempfile
import zpkgtools
Modified: zpkgtools/trunk/zpkgtools/tests/test_appsupport.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_appsupport.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_appsupport.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,9 +16,10 @@
import os
import shutil
import sys
-import tempfile
import unittest
+from zpkgsetup.tests import tempfileapi as tempfile
+
from zpkgtools import app
@@ -45,7 +46,7 @@
f = open(resource_map, "w")
f.write("TestThing file:///dev/null\n")
f.close()
- self.old_tempdir = tempfile.tempdir
+ self.old_tempdir = tempfile.gettempdir()
self.options = app.parse_args(["foo/bar.py", "-f", "-m", resource_map,
"-v", "0.1.0test1", "TestThing"])
self.app = app.BuilderApplication(self.options)
@@ -53,7 +54,8 @@
def tearDown(self):
self.app.cleanup()
shutil.rmtree(self.tmpdir)
- tempfile.tempdir = self.old_tempdir
+ # This assumes tempfile is really tempfileapi:
+ tempfile.tempfile.tempdir = self.old_tempdir
def make_component(self):
return Component("TestThing", self.publication_name)
Modified: zpkgtools/trunk/zpkgtools/tests/test_cvsloader.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_cvsloader.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_cvsloader.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,11 +16,12 @@
import doctest
import os.path
import shutil
-import tempfile
import unittest
from StringIO import StringIO
+from zpkgsetup.tests import tempfileapi as tempfile
+
from zpkgtools import cvsloader
from zpkgtools import loader
from zpkgtools.tests.test_loader import LoaderTestBase
Modified: zpkgtools/trunk/zpkgtools/tests/test_include.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_include.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_include.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,7 +16,6 @@
import filecmp
import os
import shutil
-import tempfile
import unittest
import urllib2
@@ -24,6 +23,7 @@
from StringIO import StringIO
from zpkgsetup import cfgparser
+from zpkgsetup.tests import tempfileapi as tempfile
from zpkgtools import include
from zpkgtools import loader
Modified: zpkgtools/trunk/zpkgtools/tests/test_loader.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_loader.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_loader.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -16,10 +16,11 @@
import filecmp
import os
import shutil
-import tempfile
import unittest
import urllib
+from zpkgsetup.tests import tempfileapi as tempfile
+
from zpkgtools import loader
from zpkgtools.tests import test_svnloader
Modified: zpkgtools/trunk/zpkgtools/tests/test_locationmap.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_locationmap.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_locationmap.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -14,13 +14,14 @@
"""Tests for zpkgtools.cvsmap."""
import doctest
-import logging
import os.path
import unittest
import urllib
from StringIO import StringIO
+from zpkgsetup import loggingapi as logging
+
from zpkgtools import locationmap
from zpkgtools.tests.test_cvsloader import CvsWorkingDirectoryBase
@@ -195,12 +196,12 @@
eq(map["foo.bar"], "svn://svn.example.org/proj/tags/*/path/bar")
-class CollectingHandler(logging.StreamHandler):
+class CollectingHandler(logging.Handler):
"""Log handler that simply collects emitted warning records."""
def __init__(self, list):
self.list = list
- logging.StreamHandler.__init__(self)
+ logging.Handler.__init__(self)
def emit(self, record):
self.list.append(record)
Modified: zpkgtools/trunk/zpkgtools/tests/test_svnloader.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_svnloader.py 2004-06-22 17:05:01 UTC (rev 25938)
+++ zpkgtools/trunk/zpkgtools/tests/test_svnloader.py 2004-06-22 17:32:32 UTC (rev 25939)
@@ -15,9 +15,10 @@
import os
import shutil
-import tempfile
import unittest
+from zpkgsetup.tests import tempfileapi as tempfile
+
from zpkgtools import cvsloader
from zpkgtools import svnloader
More information about the Zope-CVS
mailing list