]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 55731:
authorNeal Norwitz <nnorwitz@gmail.com>
Sat, 2 Jun 2007 18:53:07 +0000 (18:53 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sat, 2 Jun 2007 18:53:07 +0000 (18:53 +0000)
SF 1668596/1720897: distutils now copies data files
even if package_dir is empty.

Lib/distutils/command/build_py.py
Lib/distutils/tests/test_build_py.py
Misc/ACKS
Misc/NEWS

index 621bcb4af3cde17304a30aa4975edd3ee47510af..b9f39bae79ccc5d9e99e51f2ec9a18d3e55fac48 100644 (file)
@@ -114,7 +114,9 @@ class build_py (Command):
             build_dir = os.path.join(*([self.build_lib] + package.split('.')))
 
             # Length of path to strip from found files
-            plen = len(src_dir)+1
+            plen = 0
+            if src_dir:
+                plen = len(src_dir)+1
 
             # Strip directory from globbed filenames
             filenames = [
index 78e4c55ed4839584137731b9006f29be631af8a4..54a4ed80fd30bc3a20c370ba7c51b7d0cddf1d31 100644 (file)
@@ -1,10 +1,13 @@
 """Tests for distutils.command.build_py."""
 
 import os
+import sys
+import StringIO
 import unittest
 
 from distutils.command.build_py import build_py
 from distutils.core import Distribution
+from distutils.errors import DistutilsFileError
 
 from distutils.tests import support
 
@@ -53,6 +56,38 @@ class BuildPyTestCase(support.TempdirManager,
         self.assert_("__init__.pyc" in files)
         self.assert_("README.txt" in files)
 
+    def test_empty_package_dir (self):
+        # See SF 1668596/1720897.
+        cwd = os.getcwd()
+
+        # create the distribution files.
+        sources = self.mkdtemp()
+        open(os.path.join(sources, "__init__.py"), "w").close()
+
+        testdir = os.path.join(sources, "doc")
+        os.mkdir(testdir)
+        open(os.path.join(testdir, "testfile"), "w").close()
+
+        os.chdir(sources)
+        sys.stdout = StringIO.StringIO()
+
+        try:
+            dist = Distribution({"packages": ["pkg"],
+                                 "package_dir": {"pkg": ""},
+                                 "package_data": {"pkg": ["doc/*"]}})
+            # script_name need not exist, it just need to be initialized
+            dist.script_name = os.path.join(sources, "setup.py")
+            dist.script_args = ["build"]
+            dist.parse_command_line()
+
+            try:
+                dist.run_commands()
+            except DistutilsFileError:
+                self.fail("failed package_data test when package_dir is ''")
+        finally:
+            # Restore state.
+            os.chdir(cwd)
+            sys.stdout = sys.__stdout__
 
 def test_suite():
     return unittest.makeSuite(BuildPyTestCase)
index 58dab22d02492135bee1a350bf07a0b3e3b54cc8..d39442eeb7257c9b9003240a9e25fee97f1119b5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -155,6 +155,7 @@ Jonathan Dasteel
 John DeGood
 Vincent Delft
 Roger Dev
+Raghuram Devarakonda
 Toby Dickenson
 Yves Dionne
 Daniel Dittmar
index 4d1ca27a3ce66f9e4cab0b81dbdb1969674e4066..a397e4d9fe62a2f53f3bde4ad135854e665d6541 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.2c1?
 Library
 -------
 
+- SF 1668596/1720897: distutils now copies data files
+  even if package_dir is empty.
+
 - Fix bug in marshal where bad data would cause a segfault due to
   lack of an infinite recursion check.