diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-01-09 04:11:44 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-01-09 04:11:44 (GMT) |
commit | 960cf0fd9b2c1e892dfdd5027a6b5020f09ba20f (patch) | |
tree | da7e96648a7bae3ca73d9980234cd08628b9f91f /Lib/distutils | |
parent | 3563153793623f693b8cd5697cd8a2ae6094d240 (diff) | |
download | cpython-960cf0fd9b2c1e892dfdd5027a6b5020f09ba20f.zip cpython-960cf0fd9b2c1e892dfdd5027a6b5020f09ba20f.tar.gz cpython-960cf0fd9b2c1e892dfdd5027a6b5020f09ba20f.tar.bz2 |
Merged revisions 68167,68276,68292-68293,68344 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68167 | vinay.sajip | 2009-01-02 12:53:04 -0600 (Fri, 02 Jan 2009) | 1 line
Minor documentation changes relating to NullHandler, the module used for handlers and references to ConfigParser.
........
r68276 | tarek.ziade | 2009-01-03 18:04:49 -0600 (Sat, 03 Jan 2009) | 1 line
fixed #1702551: distutils sdist was not pruning VCS directories under win32
........
r68292 | skip.montanaro | 2009-01-04 04:36:58 -0600 (Sun, 04 Jan 2009) | 3 lines
If user configures --without-gcc give preference to $CC instead of blindly
assuming the compiler will be "cc".
........
r68293 | tarek.ziade | 2009-01-04 04:37:52 -0600 (Sun, 04 Jan 2009) | 1 line
using clearer syntax
........
r68344 | marc-andre.lemburg | 2009-01-05 13:43:35 -0600 (Mon, 05 Jan 2009) | 7 lines
Fix #4846 (Py_UNICODE_ISSPACE causes linker error) by moving the declaration
into the extern "C" section.
Add a few more comments and apply some minor edits to make the file contents
fit the original structure again.
........
Diffstat (limited to 'Lib/distutils')
-rw-r--r-- | Lib/distutils/command/sdist.py | 18 | ||||
-rw-r--r-- | Lib/distutils/tests/test_sdist.py | 110 |
2 files changed, 125 insertions, 3 deletions
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py index b29fc64..96fb7fa 100644 --- a/Lib/distutils/command/sdist.py +++ b/Lib/distutils/command/sdist.py @@ -4,7 +4,10 @@ Implements the Distutils 'sdist' command (create a source distribution).""" __revision__ = "$Id$" -import sys, os +import os +import string +import sys +from types import * from glob import glob from distutils.core import Command from distutils import dir_util, dep_util, file_util, archive_util @@ -332,9 +335,18 @@ class sdist (Command): self.filelist.exclude_pattern(None, prefix=build.build_base) self.filelist.exclude_pattern(None, prefix=base_dir) - self.filelist.exclude_pattern(r'(^|/)(RCS|CVS|\.svn|\.hg|\.git|\.bzr|_darcs)/.*', is_regex=1) - def write_manifest(self): + if sys.platform == 'win32': + seps = r'/|\\' + else: + seps = '/' + + vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr', + '_darcs'] + vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps) + self.filelist.exclude_pattern(vcs_ptrn, is_regex=1) + + def write_manifest (self): """Write the file list in 'self.filelist' (presumably as filled in by 'add_defaults()' and 'read_template()') to the manifest file named by 'self.manifest'. diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py new file mode 100644 index 0000000..7cc04cf --- /dev/null +++ b/Lib/distutils/tests/test_sdist.py @@ -0,0 +1,110 @@ +"""Tests for distutils.command.sdist.""" +import os +import unittest +import shutil +import zipfile +from os.path import join + +from distutils.command.sdist import sdist +from distutils.core import Distribution +from distutils.tests.test_config import PyPIRCCommandTestCase + +CURDIR = os.path.dirname(__file__) +TEMP_PKG = join(CURDIR, 'temppkg') + +SETUP_PY = """ +from distutils.core import setup +import somecode + +setup(name='fake') +""" + +MANIFEST_IN = """ +recursive-include somecode * +""" + +class sdistTestCase(PyPIRCCommandTestCase): + + def setUp(self): + PyPIRCCommandTestCase.setUp(self) + self.old_path = os.getcwd() + + def tearDown(self): + os.chdir(self.old_path) + if os.path.exists(TEMP_PKG): + shutil.rmtree(TEMP_PKG) + PyPIRCCommandTestCase.tearDown(self) + + def _write(self, path, content): + f = open(path, 'w') + try: + f.write(content) + finally: + f.close() + + def test_prune_file_list(self): + # this test creates a package with some vcs dirs in it + # and launch sdist to make sure they get pruned + # on all systems + if not os.path.exists(TEMP_PKG): + os.mkdir(TEMP_PKG) + os.mkdir(join(TEMP_PKG, 'somecode')) + + # creating a MANIFEST, a package, and a README + self._write(join(TEMP_PKG, 'MANIFEST.in'), MANIFEST_IN) + self._write(join(TEMP_PKG, 'README'), 'xxx') + self._write(join(TEMP_PKG, 'somecode', '__init__.py'), '#') + self._write(join(TEMP_PKG, 'setup.py'), SETUP_PY) + + # creating VCS directories with some files in them + os.mkdir(join(TEMP_PKG, 'somecode', '.svn')) + self._write(join(TEMP_PKG, 'somecode', '.svn', 'ok.py'), 'xxx') + + os.mkdir(join(TEMP_PKG, 'somecode', '.hg')) + self._write(join(TEMP_PKG, 'somecode', '.hg', + 'ok'), 'xxx') + + os.mkdir(join(TEMP_PKG, 'somecode', '.git')) + self._write(join(TEMP_PKG, 'somecode', '.git', + 'ok'), 'xxx') + + os.chdir(TEMP_PKG) + + # now building a sdist + dist = Distribution() + dist.script_name = 'setup.py' + dist.metadata.name = 'fake' + dist.metadata.version = '1.0' + dist.metadata.url = 'http://xxx' + dist.metadata.author = dist.metadata.author_email = 'xxx' + dist.packages = ['somecode'] + dist.include_package_data = True + cmd = sdist(dist) + cmd.manifest = 'MANIFEST' + cmd.template = 'MANIFEST.in' + cmd.dist_dir = 'dist' + + # zip is available universally + # (tar might not be installed under win32) + cmd.formats = ['zip'] + cmd.run() + + # now let's check what we have + dist_folder = join(TEMP_PKG, 'dist') + files = os.listdir(dist_folder) + self.assertEquals(files, ['fake-1.0.zip']) + + zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip')) + try: + content = zip_file.namelist() + finally: + zip_file.close() + + # making sure everything has been pruned correctly + self.assertEquals(len(content), 4) + +def test_suite(): + return unittest.makeSuite(sdistTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") |