[Zope-CVS] SVN: zpkgtools/trunk/ - add an install_lib command that can deal with the fact that

Fred L. Drake, Jr. fdrake at gmail.com
Wed Jul 28 11:07:14 EDT 2004


Log message for revision 26807:
  - add an install_lib command that can deal with the fact that
    build_py.get_outputs() reports package data files as well as Python
    source files
  - add tests
  


Changed:
  U   zpkgtools/trunk/doc/Makefile
  U   zpkgtools/trunk/zpkgsetup/dist.py
  A   zpkgtools/trunk/zpkgsetup/install_lib.py
  A   zpkgtools/trunk/zpkgsetup/tests/support.py
  A   zpkgtools/trunk/zpkgsetup/tests/test_build_py.py


-=-
Modified: zpkgtools/trunk/doc/Makefile
===================================================================
--- zpkgtools/trunk/doc/Makefile	2004-07-28 13:45:04 UTC (rev 26806)
+++ zpkgtools/trunk/doc/Makefile	2004-07-28 15:07:13 UTC (rev 26807)
@@ -16,7 +16,7 @@
 
 # This should point to the Zope3/utilities/rst2html, but just about
 # implementation will do.
-RST2HTML=rst2html
+RST2HTML=../../../Zope3/utilities/rst2html
 
 LOCAL_HTML=\
 	collections.html \

Modified: zpkgtools/trunk/zpkgsetup/dist.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/dist.py	2004-07-28 13:45:04 UTC (rev 26806)
+++ zpkgtools/trunk/zpkgsetup/dist.py	2004-07-28 15:07:13 UTC (rev 26807)
@@ -67,4 +67,6 @@
         distutils.dist.Distribution.__init__(self, attrs)
         if self.package_data and sys.version_info < (2, 4):
             from zpkgsetup.build_py import build_py
+            from zpkgsetup.install_lib import install_lib
             self.cmdclass.setdefault('build_py', build_py)
+            self.cmdclass.setdefault('install_lib', install_lib)

Added: zpkgtools/trunk/zpkgsetup/install_lib.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/install_lib.py	2004-07-28 13:45:04 UTC (rev 26806)
+++ zpkgtools/trunk/zpkgsetup/install_lib.py	2004-07-28 15:07:13 UTC (rev 26807)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Hacked install_lib command to deal with package_data for Python before 2.4.
+
+$Id$
+"""
+import os
+
+from distutils.command.install_lib import install_lib as _install_lib
+
+
+# Extension for Python source files.
+PYTHON_SOURCE_EXTENSION = os.extsep + "py"
+
+
+class install_lib(_install_lib):
+    """install_lib variant with package_data support.
+
+    This overrides the _bytecode_filenames() helper method to
+    accomodate the fact that it can now be called with names other
+    than Python source files due to the package_data support.
+    
+    This is only needed when the zpkgsetup.build_py implementation is
+    used; this is ensured by the `zpkgsetup.dist.ZPkgDistribution`
+    class.
+
+    """
+
+    def _bytecode_filenames (self, py_filenames):
+        bytecode_files = []
+        for py_file in py_filenames:
+            # Since build_py handles package data installation, the
+            # list of outputs can contain more than just .py files.
+            # Make sure we only report bytecode for the .py files.
+            ext = os.path.splitext(os.path.normcase(py_file))[1]
+            if ext != PYTHON_SOURCE_EXTENSION:
+                continue
+            if self.compile:
+                bytecode_files.append(py_file + "c")
+            if self.optimize > 0:
+                bytecode_files.append(py_file + "o")
+
+        return bytecode_files


Property changes on: zpkgtools/trunk/zpkgsetup/install_lib.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Added: zpkgtools/trunk/zpkgsetup/tests/support.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/support.py	2004-07-28 13:45:04 UTC (rev 26806)
+++ zpkgtools/trunk/zpkgsetup/tests/support.py	2004-07-28 15:07:13 UTC (rev 26807)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Support code for zpkgsetup test cases."""
+
+import shutil
+
+from zpkgsetup.tests import tempfileapi as tempfile
+
+
+class TempdirManager(object):
+    """Mix-in class that handles temporary directories for test cases.
+
+    This is intended to be used with unittest.TestCase.
+    """
+
+    def setUp(self):
+        super(TempdirManager, self).setUp()
+        self.tempdirs = []
+
+    def tearDown(self):
+        super(TempdirManager, self).tearDown()
+        while self.tempdirs:
+            d = self.tempdirs.pop()
+            shutil.rmtree(d)
+
+    def mkdtemp(self):
+        """Create a temporary directory that will be cleaned up.
+
+        Returns the path of the directory.
+        """
+        d = tempfile.mkdtemp()
+        self.tempdirs.append(d)
+        return d
+
+
+class DummyCommand:
+    """Class to store options for retrieval via set_undefined_options()."""
+
+    def __init__(self, **kwargs):
+        for kw, val in kwargs.items():
+            setattr(self, kw, val)
+
+    def ensure_finalized(self):
+        pass


Property changes on: zpkgtools/trunk/zpkgsetup/tests/support.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Added: zpkgtools/trunk/zpkgsetup/tests/test_build_py.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_build_py.py	2004-07-28 13:45:04 UTC (rev 26806)
+++ zpkgtools/trunk/zpkgsetup/tests/test_build_py.py	2004-07-28 15:07:13 UTC (rev 26807)
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for distutils.command.build_py."""
+
+import os
+import unittest
+
+from zpkgsetup.dist import ZPkgDistribution
+
+from zpkgsetup.tests import support
+
+
+class BuildPyTestCase(support.TempdirManager, unittest.TestCase):
+
+    def test_package_data(self):
+        sources = self.mkdtemp()
+        f = open(os.path.join(sources, "__init__.py"), "w")
+        f.write("# Pretend this is a package.")
+        f.close()
+        f = open(os.path.join(sources, "README.txt"), "w")
+        f.write("Info about this package")
+        f.close()
+
+        destination = self.mkdtemp()
+
+        dist = ZPkgDistribution({"packages": ["pkg"],
+                                 "package_dir": {"pkg": sources},
+                                 "package_data": {"pkg": ["README.txt"]}})
+        # script_name need not exist, it just need to be initialized
+        dist.script_name = os.path.join(sources, "setup.py")
+        dist.command_obj["build"] = support.DummyCommand(
+            force=0,
+            build_lib=destination)
+
+        cmd = dist.get_command_obj("build_py")
+        cmd.compile = 1
+        cmd.ensure_finalized()
+        self.assertEqual(cmd.package_data, dist.package_data)
+
+        cmd.run()
+
+        # This makes sure the list of outputs includes byte-compiled
+        # files for Python modules but not for package data files
+        # (there shouldn't *be* byte-code files for those!).
+        #
+        pkgdest = os.path.join(destination, "pkg")
+        files = os.listdir(pkgdest)
+        files.sort()
+        self.assertEqual(files, ["README.txt",
+                                 "__init__.py",
+                                 "__init__.pyc",
+                                 ])
+
+
+def test_suite():
+    return unittest.makeSuite(BuildPyTestCase)
+
+if __name__ == "__main__":
+    unittest.main(defaultTest="test_suite")


Property changes on: zpkgtools/trunk/zpkgsetup/tests/test_build_py.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native



More information about the Zope-CVS mailing list