Index: Lib/distutils/command/build_py.py =================================================================== --- Lib/distutils/command/build_py.py (revision 55679) +++ Lib/distutils/command/build_py.py (working copy) @@ -114,7 +114,9 @@ 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: Lib/distutils/tests/test_build_py.py =================================================================== --- Lib/distutils/tests/test_build_py.py (revision 55644) +++ Lib/distutils/tests/test_build_py.py (working copy) @@ -5,6 +5,7 @@ from distutils.command.build_py import build_py from distutils.core import Distribution +from distutils.errors import DistutilsFileError from distutils.tests import support @@ -53,7 +54,39 @@ self.assert_("__init__.pyc" in files) self.assert_("README.txt" in files) + # If package_dir is '', there is some problem in copying files + # specified with 'package_data'. It is fixed with patch 1720897 + # and this test case validates the fix. + def test_1720897 (self): + # create the distribution files. + cwd = os.getcwd() + 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() + error = False + os.chdir(sources) + 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: + error = True + finally: + # if directory is not reverted, cleanup is failing on windows. + os.chdir(cwd) + if error: + self.fail("failed the test for package_data when package_dir is ''") + def test_suite(): return unittest.makeSuite(BuildPyTestCase)