[Python-checkins] cpython (merge 3.2 -> 3.3): Merge with 3.2 for Issue #19286.

jason.coombs python-checkins at python.org
Sat Nov 2 18:05:10 CET 2013


http://hg.python.org/cpython/rev/69f8288056eb
changeset:   86862:69f8288056eb
branch:      3.3
parent:      86856:576ffbaa6363
parent:      86861:7d399099334d
user:        Jason R. Coombs <jaraco at jaraco.com>
date:        Sat Nov 02 13:01:46 2013 -0400
summary:
  Merge with 3.2 for Issue #19286.

files:
  Lib/distutils/command/build_py.py    |   3 +-
  Lib/distutils/tests/test_build_py.py |  31 ++++++++++++++++
  Misc/NEWS                            |   3 +
  3 files changed, 36 insertions(+), 1 deletions(-)


diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py
--- a/Lib/distutils/command/build_py.py
+++ b/Lib/distutils/command/build_py.py
@@ -127,7 +127,8 @@
             # Each pattern has to be converted to a platform-specific path
             filelist = glob(os.path.join(src_dir, convert_path(pattern)))
             # Files that match more than one pattern are only added once
-            files.extend([fn for fn in filelist if fn not in files])
+            files.extend([fn for fn in filelist if fn not in files
+                and os.path.isfile(fn)])
         return files
 
     def build_package_data(self):
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -121,6 +121,37 @@
         found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
         self.assertEqual(sorted(found), ['boiledeggs.%s.pyo' % imp.get_tag()])
 
+    def test_dir_in_package_data(self):
+        """
+        A directory in package_data should not be added to the filelist.
+        """
+        # See bug 19286
+        sources = self.mkdtemp()
+        pkg_dir = os.path.join(sources, "pkg")
+
+        os.mkdir(pkg_dir)
+        open(os.path.join(pkg_dir, "__init__.py"), "w").close()
+
+        docdir = os.path.join(pkg_dir, "doc")
+        os.mkdir(docdir)
+        open(os.path.join(docdir, "testfile"), "w").close()
+
+        # create the directory that could be incorrectly detected as a file
+        os.mkdir(os.path.join(docdir, 'otherdir'))
+
+        os.chdir(sources)
+        dist = Distribution({"packages": ["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 when data dir includes a dir")
+
     def test_dont_write_bytecode(self):
         # makes sure byte_compile is not used
         dist = self.create_dist()[1]
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
 Library
 -------
 
+- Issue #19286: Directories in ``package_data`` are no longer added to
+  the filelist, preventing failure outlined in the ticket.
+
 - Issue #19435: Fix directory traversal attack on CGIHttpRequestHandler.
 
 Tests

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list