diff options
-rwxr-xr-x | setuptools/command/sdist.py | 11 | ||||
-rw-r--r-- | setuptools/tests/test_sdist.py | 28 | ||||
-rw-r--r-- | setuptools/utils.py | 11 |
3 files changed, 46 insertions, 4 deletions
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 2aa1ee20..dc8d6773 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -8,6 +8,8 @@ import sys from setuptools import svn_utils from setuptools.compat import PY3 +from setuptools.utils import cs_path_exists + import pkg_resources READMES = ('README', 'README.rst', 'README.txt') @@ -146,7 +148,7 @@ class sdist(orig.sdist): alts = fn got_it = 0 for fn in alts: - if os.path.exists(fn): + if cs_path_exists(fn): got_it = 1 self.filelist.append(fn) break @@ -155,16 +157,17 @@ class sdist(orig.sdist): self.warn("standard file not found: should have one of " + ', '.join(alts)) else: - if os.path.exists(fn): + if cs_path_exists(fn): self.filelist.append(fn) else: self.warn("standard file '%s' not found" % fn) optional = ['test/test*.py', 'setup.cfg'] for pattern in optional: - files = list(filter(os.path.isfile, glob(pattern))) + files = list(filter(cs_path_exists, glob(pattern))) if files: - self.filelist.extend(files) + actual_fnames = map(os.path.normcase, files) + self.filelist.extend(actual_fnames) # getting python files if self.distribution.has_pure_modules(): diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py index 5b3862e9..5f8a190f 100644 --- a/setuptools/tests/test_sdist.py +++ b/setuptools/tests/test_sdist.py @@ -86,6 +86,7 @@ class TestSdistTest(unittest.TestCase): f = open(os.path.join(self.temp_dir, 'setup.py'), 'w') f.write(SETUP_PY) f.close() + # Set up the rest of the test package test_pkg = os.path.join(self.temp_dir, 'sdist_test') os.mkdir(test_pkg) @@ -121,6 +122,33 @@ class TestSdistTest(unittest.TestCase): self.assertTrue(os.path.join('sdist_test', 'b.txt') in manifest) self.assertTrue(os.path.join('sdist_test', 'c.rst') not in manifest) + + def test_defaults_case_sensitivity(self): + """ + Make sure default files (README.*, etc.) are added in a case-sensitive + way to avoid problems with packages built on Windows. + """ + + open(os.path.join(self.temp_dir, 'readme.rst'), 'w').close() + open(os.path.join(self.temp_dir, 'SETUP.cfg'), 'w').close() + + dist = Distribution(SETUP_ATTRS) + # the extension deliberately capitalized for this test + # to make sure the actual filename (not capitalized) gets added + # to the manifest + dist.script_name = 'setup.PY' + cmd = sdist(dist) + cmd.ensure_finalized() + + with quiet(): + cmd.run() + + # lowercase all names so we can test in a case-insensitive way to make sure the files are not included + manifest = map(lambda x: x.lower(), cmd.filelist.files) + self.assertFalse('readme.rst' in manifest, manifest) + self.assertFalse('setup.py' in manifest, manifest) + self.assertFalse('setup.cfg' in manifest, manifest) + def test_manifest_is_written_with_utf8_encoding(self): # Test for #303. dist = Distribution(SETUP_ATTRS) diff --git a/setuptools/utils.py b/setuptools/utils.py new file mode 100644 index 00000000..91e4b87f --- /dev/null +++ b/setuptools/utils.py @@ -0,0 +1,11 @@ +import os +import os.path + + +def cs_path_exists(fspath): + if not os.path.exists(fspath): + return False + # make absolute so we always have a directory + abspath = os.path.abspath(fspath) + directory, filename = os.path.split(abspath) + return filename in os.listdir(directory)
\ No newline at end of file |