[Zope-CVS] SVN: zpkgtools/trunk/ Remove dependency on setuptools.

Fred L. Drake, Jr. fred at zope.com
Thu Jun 17 16:44:11 EDT 2004


Log message for revision 25895:
Remove dependency on setuptools.

The zpkg tool no longer requires setuptools, and no longer bundles it
in generated distributions.  The build_py command from setuptools has
been copied into zpkgsetup, and is used only for Python versions
before 2.4 (which includes the same functionality).

The code in zpkgsetup.dist deals with distutils differences across
different versions of Python.



-=-
Modified: zpkgtools/trunk/doc/TODO.txt
===================================================================
--- zpkgtools/trunk/doc/TODO.txt	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/doc/TODO.txt	2004-06-17 20:44:09 UTC (rev 25895)
@@ -16,11 +16,6 @@
     when building an "application" distribution since that has some
     support to select from different available Python interpreters.)
 
-  - Instead of using setuptools to pick up only the package_data
-    facility, copy the build_py implementation into the **zpkg**
-    runtime package and use it from there.  This removes a large chunk
-    of unused code from distributions (the rest of setuptools).
-
   - When installing an application bundle, it should be an error if
     the installation directory already exists and the user hasn't
     explicitly said that's ok (-f/--force).

Modified: zpkgtools/trunk/doc/zpkg.txt
===================================================================
--- zpkgtools/trunk/doc/zpkg.txt	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/doc/zpkg.txt	2004-06-17 20:44:09 UTC (rev 25895)
@@ -60,8 +60,7 @@
 -S
   Don't include the required support packages in the distribution.
   This can be used to generate smaller distributions when the
-  ``setuptools`` and ``zpkgsetup`` packages are known to be available
-  on target systems.
+  ``zpkgsetup`` package is known to be available on target systems.
 
 -v VERSION
   Set the version number of the release to `VERSION`.
@@ -97,9 +96,9 @@
 bundles the support code along with the resulting distribution.  The
 value is a boolean, where the strings ``true`` and ``false`` can be
 used in the configuration file.  If true (the default), copies of the
-``zpkgsetup`` and ``setuptools`` packages will be included in the
-distribution (less their test code).  If false, the packages will be
-assumed to be available for import on target systems.
+``zpkgsetup`` package will be included in the distribution (less the
+test code).  If false, the package will be assumed to be available for
+import on target systems.
 
 The value for ``resource-map`` is a path or URL (including
 ``cvs:`` URLs) for a file that defines the map.  Relative paths are
@@ -216,9 +215,8 @@
 copy available on the local system and add a resource entry for it
 using a ``file:`` URL::
 
-  setuptools  file:///home/myuser/stuff/setuptools/setuptools
   zpkgsetup   file:///home/myuser/stuff/zpkgtools/zpkgsetup
 
 (The path should identify the directory that contains the
-``setuptools`` or ``zpkgsetup`` package itself, not the directory that
+``zpkgsetup`` package itself, not the directory that
 would be on ``sys.path`` to allow it to be importable.)

Added: zpkgtools/trunk/zpkgsetup/build_py.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/build_py.py	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/zpkgsetup/build_py.py	2004-06-17 20:44:09 UTC (rev 25895)
@@ -0,0 +1,93 @@
+# This file was copied from Phillip Eby's "setuptools" package, and is
+# covered by the PSF license.
+
+import os.path
+
+from distutils.command.build_py import build_py as _build_py
+from distutils.util import convert_path
+from glob import glob
+
+
+class build_py(_build_py):
+    """Enhanced 'build_py' command that includes data files with packages
+
+    The data files are specified via a 'package_data' argument to 'setup()'.
+    See 'setuptools.dist.Distribution' for more details.
+
+    Also, this version of the 'build_py' command allows you to specify both
+    'py_modules' and 'packages' in the same setup operation.
+    """
+
+    def finalize_options(self):
+        _build_py.finalize_options(self)
+        self.package_data = self.distribution.package_data
+        self.data_files = self.get_data_files()
+
+    def run(self):
+        """Build modules, packages, and copy data files to build directory"""
+        if not self.py_modules and not self.packages:
+            return
+
+        if self.py_modules:
+            self.build_modules()
+
+        if self.packages:
+            self.build_packages()
+            self.build_package_data()
+
+        # Only compile actual .py files, using our base class' idea of what our
+        # output files are.
+        self.byte_compile(_build_py.get_outputs(self, include_bytecode=0))
+
+    def get_data_files(self):
+        """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
+        data = []
+        for package in self.packages:
+            # Locate package source directory
+            src_dir = self.get_package_dir(package)
+
+            # Compute package build directory
+            build_dir = os.path.join(*([self.build_lib] + package.split('.')))
+
+            # Length of path to strip from found files
+            plen = len(src_dir)+1
+
+            # Strip directory from globbed filenames
+            filenames = [
+                file[plen:] for file in self.find_data_files(package, src_dir)
+                ]
+            data.append( (package, src_dir, build_dir, filenames) )
+        return data
+
+    def find_data_files(self, package, src_dir):
+        """Return filenames for package's data files in 'src_dir'"""
+        globs = (self.package_data.get('', [])
+                 + self.package_data.get(package, []))
+        files = []
+        for pattern in globs:
+            # Each pattern has to be converted to a platform-specific path
+            files.extend(glob(os.path.join(src_dir, convert_path(pattern))))
+        return files
+
+    def build_package_data(self):
+        """Copy data files into build directory"""
+        lastdir = None
+        for package, src_dir, build_dir, filenames in self.data_files:
+            for filename in filenames:
+                target = os.path.join(build_dir, filename)
+                self.mkpath(os.path.dirname(target))
+                self.copy_file(os.path.join(src_dir, filename), target)
+
+    def get_outputs(self, include_bytecode=1):
+        """Return complete list of files copied to the build directory
+
+        This includes both '.py' files and data files, as well as '.pyc' and
+        '.pyo' files if 'include_bytecode' is true.  (This method is needed for
+        the 'install_lib' command to do its job properly, and to generate a
+        correct installation manifest.)
+        """
+        return _build_py.get_outputs(self, include_bytecode) + [
+            os.path.join(build_dir, filename)
+            for package, src_dir, build_dir,filenames in self.data_files
+            for filename in filenames
+            ]


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

Added: zpkgtools/trunk/zpkgsetup/dist.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/dist.py	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/zpkgsetup/dist.py	2004-06-17 20:44:09 UTC (rev 25895)
@@ -0,0 +1,34 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Distribution class which ensure we can operate with or without Python 2.4.
+
+$Id$
+"""
+import distutils.dist
+import sys
+
+
+if sys.version_info < (2, 3):
+    distutils.dist.DistributionMetadata.classifiers = None
+    distutils.dist.DistributionMetadata.download_url = None
+
+
+class ZPkgDistribution(distutils.dist.Distribution):
+
+    def __init__ (self, attrs=None):
+        self.package_data = None
+        distutils.dist.Distribution.__init__(self, attrs)
+        if self.package_data and sys.version_info < (2, 4):
+            from zpkgsetup.build_py import build_py
+            self.cmdclass.setdefault('build_py', build_py)


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

Modified: zpkgtools/trunk/zpkgsetup/setup.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/setup.py	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/zpkgsetup/setup.py	2004-06-17 20:44:09 UTC (rev 25895)
@@ -112,19 +112,9 @@
                 if e.errno != errno.EPIPE:
                     raise
         else:
-            if sys.version_info < (2, 3):
-                from distutils.dist import DistributionMetadata
-                DistributionMetadata.classifiers = None
-                DistributionMetadata.download_url = None
-            try:
-                from setuptools import setup
-            except ImportError:
-                # package_data can't be handled this way ;-(
-                if self.package_data:
-                    print >>sys.stderr, (
-                        "can't import setuptools;"
-                        " some package data will not be properly installed")
-                from distutils.core import setup
+            from zpkgsetup.dist import ZPkgDistribution
+            from distutils.core import setup
+            kwargs["distclass"] = ZPkgDistribution
             setup(**kwargs)
 
     def load_metadata(self, path):

Added: zpkgtools/trunk/zpkgsetup/tests/test_dist.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_dist.py	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/zpkgsetup/tests/test_dist.py	2004-06-17 20:44:09 UTC (rev 25895)
@@ -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.
+#
+##############################################################################
+"""Tests for zpkgsetup.dist.
+
+$Id$
+"""
+import unittest
+
+from zpkgsetup import dist
+
+
+class ZPkgDistributionTestCase(unittest.TestCase):
+
+    def test_package_data_recognized(self):
+        # Make sure the package_data keyword isn't dropped:
+        package_data = {"pkg": ["foo.h"]}
+        d = dist.ZPkgDistribution({"package_data": package_data,
+                                   "packages": ["pkg"]})
+        self.assertEqual(d.package_data, package_data)
+        # Make sure the build_py command object sees it:
+        cmd = d.get_command_obj("build_py")
+        cmd.ensure_finalized()
+        self.assertEqual(cmd.package_data, package_data)
+
+    def test_classifiers_recognized(self):
+        # Make sure the classifiers keyword isn't dropped:
+        classifiers = ["foo", "bar"]
+        d = dist.ZPkgDistribution({"classifiers": classifiers})
+        self.assertEqual(d.metadata.classifiers, classifiers)
+
+
+def test_suite():
+    return unittest.makeSuite(ZPkgDistributionTestCase)


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

Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py	2004-06-17 17:43:13 UTC (rev 25894)
+++ zpkgtools/trunk/zpkgtools/app.py	2004-06-17 20:44:09 UTC (rev 25895)
@@ -197,13 +197,11 @@
         shutil.copymode(template, output)
 
     def include_support_code(self):
-        """Include any support code needed by the generated setup.py
-        files.
+        """Include any support code needed by the generated setup.py.
 
-        This will add the ``setuptools`` and ``zpkgsetup`` packages to
-        the output directory if not already present, but they won't be
-        added to the set of packages that will be installed by the
-        resulting distribution.
+        This will add the ``zpkgsetup`` package to the Support
+        directory, but they won't be added to the set of packages that
+        will be installed by the resulting distribution.
         """
         old_loader = self.loader
         if self.options.revision_tag:
@@ -213,9 +211,6 @@
         self.include_support_package(
             "zpkgsetup", ("svn://svn.zope.org/repos/main/zpkgtools/tags/*/"
                           "zpkgsetup"))
-        self.include_support_package(
-            "setuptools", ("cvs://cvs.python.sourceforge.net/cvsroot/python"
-                           ":python/nondist/sandbox/setuptools/setuptools"))
         if self.options.revision_tag:
             self.loader.cleanup()
         self.loader = old_loader




More information about the Zope-CVS mailing list