[Python-checkins] distutils2 (merge default -> default): Merge

eric.araujo python-checkins at python.org
Wed May 16 07:07:26 CEST 2012


http://hg.python.org/distutils2/rev/089d57251a00
changeset:   1325:089d57251a00
parent:      1324:7daa144a7af0
parent:      1323:52394a308caf
user:        Pierre Paul <info at pierre-paul.com>
date:        Sat May 12 15:03:53 2012 -0400
summary:
  Merge

files:
  CONTRIBUTORS.txt                  |   1 +
  distutils2/database.py            |   6 ++++
  distutils2/install.py             |  24 ++++++++++--------
  distutils2/metadata.py            |   5 +++-
  distutils2/run.py                 |   2 +-
  distutils2/tests/test_database.py |  21 ++++++++++++++--
  distutils2/tests/test_install.py  |  22 +++++++++++++++++
  distutils2/tests/test_metadata.py |   9 +++++++
  8 files changed, 74 insertions(+), 16 deletions(-)


diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -59,6 +59,7 @@
 - Gaël Pasgrimaud
 - George Peristerakis
 - Mathieu Perreault
+- Guillaume Pratte
 - Sean Reifschneider
 - Antoine Reversat
 - Arc Riley
diff --git a/distutils2/database.py b/distutils2/database.py
--- a/distutils2/database.py
+++ b/distutils2/database.py
@@ -161,6 +161,9 @@
         return '<Distribution %r %s at %r>' % (
             self.name, self.version, self.path)
 
+    def __str__(self):
+        return "%s %s" % (self.name, self.version)
+
     def _get_records(self, local=False):
         results = []
         record = self.get_distinfo_file('RECORD')
@@ -365,6 +368,9 @@
         return '<EggInfoDistribution %r %s at %r>' % (
             self.name, self.version, self.path)
 
+    def __str__(self):
+        return "%s %s" % (self.name, self.version)
+
     def list_installed_files(self, local=False):
 
         def _md5(path):
diff --git a/distutils2/install.py b/distutils2/install.py
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -58,7 +58,7 @@
         yield old, new
 
 
-def _run_distutils_install(path):
+def _run_distutils_install(path, dest):
     # backward compat: using setuptools or plain-distutils
     cmd = '%s setup.py install --record=%s'
     record_file = os.path.join(path, 'RECORD')
@@ -69,7 +69,7 @@
         egginfo_to_distinfo(record_file, remove_egginfo=True)
 
 
-def _run_setuptools_install(path):
+def _run_setuptools_install(path, dest):
     cmd = '%s setup.py install --record=%s --single-version-externally-managed'
     record_file = os.path.join(path, 'RECORD')
 
@@ -80,12 +80,12 @@
         egginfo_to_distinfo(record_file, remove_egginfo=True)
 
 
-def _run_packaging_install(path):
+def _run_packaging_install(path, dest):
     # XXX check for a valid setup.cfg?
     dist = Distribution()
     dist.parse_config_files()
     try:
-        dist.run_command('install_dist')
+        dist.run_command('install_dist', dict(prefix=(None,dest)))
         name = dist.metadata['Name']
         return database.get_distribution(name) is not None
     except (IOError, os.error, PackagingError, CCompilerError), msg:
@@ -106,11 +106,13 @@
     if where is None:
         raise ValueError('Cannot locate the unpacked archive')
 
-    return _run_install_from_archive(where)
+    return _run_install_from_archive(where, path)
 
 
 def install_local_project(path):
-    """Install a distribution from a source directory.
+    """Install a distribution from a source directory or archive.
+
+    If *path* is an archive, it will be unarchived first.
 
     If the source directory contains a setup.py install using distutils1.
     If a setup.cfg is found, install using the install_dist command.
@@ -134,14 +136,14 @@
         return False
 
 
-def _run_install_from_archive(source_dir):
+def _run_install_from_archive(source_dir, dest_dir):
     # XXX need a better way
     for item in os.listdir(source_dir):
         fullpath = os.path.join(source_dir, item)
         if os.path.isdir(fullpath):
             source_dir = fullpath
             break
-    return _run_install_from_dir(source_dir)
+    return _run_install_from_dir(source_dir, dest_dir)
 
 
 install_methods = {
@@ -150,7 +152,7 @@
     'distutils': _run_distutils_install}
 
 
-def _run_install_from_dir(source_dir):
+def _run_install_from_dir(source_dir, destination_dir=None):
     old_dir = os.getcwd()
     os.chdir(source_dir)
     install_method = get_install_method(source_dir)
@@ -158,7 +160,7 @@
     try:
         func = install_methods[install_method]
         try:
-            func(source_dir)
+            func(source_dir, destination_dir)
             return True
         except ValueError, err:
             # failed to install
@@ -183,7 +185,7 @@
 
     installed_dists = []
     for dist in dists:
-        logger.info('Installing %r %s...', dist.name, dist.version)
+        logger.info('Installing %s...', dist)
         try:
             _install_dist(dist, path)
             installed_dists.append(dist)
diff --git a/distutils2/metadata.py b/distutils2/metadata.py
--- a/distutils2/metadata.py
+++ b/distutils2/metadata.py
@@ -35,6 +35,9 @@
 
         def system_message(self, level, message, *children, **kwargs):
             self.messages.append((level, message, children, kwargs))
+            return nodes.system_message(message, level=level, type=self.
+                    levels[level], *children, **kwargs)
+
 
     _HAS_DOCUTILS = True
 except ImportError:
@@ -480,7 +483,7 @@
         return value
 
     def check(self, strict=False, restructuredtext=False):
-        """Check if the metadata is compliant. If strict is False then raise if
+        """Check if the metadata is compliant. If strict is True then raise if
         no Name or Version are provided"""
         self.set_metadata_version()
 
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -308,7 +308,7 @@
 
     number = 0
     for dist in results:
-        print '%r %s (from %r)' % (dist.name, dist.version, dist.path)
+        print "%s (from %r)" % (dist, dist.path)
         number += 1
 
     if number == 0:
diff --git a/distutils2/tests/test_database.py b/distutils2/tests/test_database.py
--- a/distutils2/tests/test_database.py
+++ b/distutils2/tests/test_database.py
@@ -80,12 +80,14 @@
     attributes are used in test methods.  See source code for details.
     """
 
+    def _get_dist_path(self, distdir):
+        here = os.path.abspath(os.path.dirname(__file__))
+        return os.path.join(here, 'fake_dists', distdir)
+
     def test_instantiation(self):
         # check that useful attributes are here
         name, version, distdir = self.sample_dist
-        here = os.path.abspath(os.path.dirname(__file__))
-        dist_path = os.path.join(here, 'fake_dists', distdir)
-
+        dist_path = self._get_dist_path(distdir)
         dist = self.dist = self.cls(dist_path)
         self.assertEqual(dist.path, dist_path)
         self.assertEqual(dist.name, name)
@@ -101,6 +103,17 @@
         self.assertIn(self.cls.__name__, repr(dist))
 
     @requires_zlib
+    def test_str(self):
+        name, version, distdir = self.sample_dist
+        dist = self.cls(self._get_dist_path(distdir))
+        self.assertEqual(name, dist.name)
+        # Sanity test: dist.name is unicode,
+        # but str output contains no u prefix.
+        self.assertIsInstance(dist.name, unicode)
+        self.assertEqual(version, dist.version)
+        self.assertEqual(str(dist), self.expected_str_output)
+
+    @requires_zlib
     def test_comparison(self):
         # tests for __eq__ and __hash__
         dist = self.cls(self.dirs[0])
@@ -128,6 +141,7 @@
 
     cls = Distribution
     sample_dist = 'choxie', '2.0.0.9', 'choxie-2.0.0.9.dist-info'
+    expected_str_output = 'choxie 2.0.0.9'
 
     def setUp(self):
         super(TestDistribution, self).setUp()
@@ -265,6 +279,7 @@
 
     cls = EggInfoDistribution
     sample_dist = 'bacon', '0.1', 'bacon-0.1.egg-info'
+    expected_str_output = 'bacon 0.1'
 
     def setUp(self):
         super(TestEggInfoDistribution, self).setUp()
diff --git a/distutils2/tests/test_install.py b/distutils2/tests/test_install.py
--- a/distutils2/tests/test_install.py
+++ b/distutils2/tests/test_install.py
@@ -1,6 +1,8 @@
 """Tests for the distutils2.install module."""
 import os
 import logging
+import sys
+
 from tempfile import mkstemp
 
 from distutils2 import install
@@ -258,6 +260,26 @@
             for key in expect:
                 self.assertEqual(expect[key], dict1[key])
 
+    def test_install_custom_dir(self):
+        dest = self.mkdtemp()
+        src = self.mkdtemp()
+
+        project_dir, dist = self.create_dist(
+            name='Spamlib', version='0.1',
+            data_files={'spamd': '{scripts}/spamd'})
+
+        dist.name = MagicMock(return_value='Spamlib')
+        dist.version = MagicMock(return_value='0.1')
+        dist.unpack = MagicMock(return_value=project_dir)
+
+        self.write_file([project_dir, 'setup.cfg'],
+                        ("[metadata]\n"
+                         "name = mypackage\n"
+                         "version = 0.1.0\n"))
+
+        install.install_from_infos(dest, install=[dist])
+        self.assertEqual(len(os.listdir(dest)), 1)
+
     def test_install_dists_rollback(self):
         # if one of the distribution installation fails, call uninstall on all
         # installed distributions.
diff --git a/distutils2/tests/test_metadata.py b/distutils2/tests/test_metadata.py
--- a/distutils2/tests/test_metadata.py
+++ b/distutils2/tests/test_metadata.py
@@ -379,6 +379,15 @@
         folded_desc = desc.replace('\n', '\n' + (7 * ' ') + '|')
         self.assertIn(folded_desc, out.getvalue())
 
+    def test_description_invalid_rst(self):
+        # make sure bad rst is well handled in the description attribute
+        metadata = Metadata()
+        description_with_bad_rst = ':funkie:`str`'  # Sphinx-specific markup
+        metadata['description'] = description_with_bad_rst
+        missing, warnings = metadata.check(restructuredtext=True)
+        warning = warnings[0][1]
+        self.assertIn('funkie', warning)
+
     def test_project_url(self):
         metadata = Metadata()
         metadata['Project-URL'] = [('one', 'http://ok')]

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


More information about the Python-checkins mailing list