summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Leduc-Hamel <mlhamel@mtlpy.org>2012-04-21 17:42:52 -0400
committerMathieu Leduc-Hamel <mlhamel@mtlpy.org>2012-04-21 17:42:52 -0400
commit1b564162d67761a1107a1802f8e7751f9dda2195 (patch)
tree6822ce7ea4bd9700d1046571c6e3d0e27c3b4ca4
parentf44715e753d2c9c20065988de383a993b835d979 (diff)
downloaddisutils2-1b564162d67761a1107a1802f8e7751f9dda2195.tar.gz
#14270: Fixes to add dest_dir params working when using install_from_infos
-rw-r--r--distutils2/install.py18
-rw-r--r--distutils2/tests/test_install.py22
2 files changed, 31 insertions, 9 deletions
diff --git a/distutils2/install.py b/distutils2/install.py
index 85af932..ee6b022 100644
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -58,7 +58,7 @@ def _move_files(files, destination):
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 @@ def _run_distutils_install(path):
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 @@ def _run_setuptools_install(path):
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,7 +106,7 @@ def _install_dist(dist, path):
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):
@@ -134,14 +134,14 @@ def install_local_project(path):
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 +150,7 @@ install_methods = {
'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 +158,7 @@ def _run_install_from_dir(source_dir):
try:
func = install_methods[install_method]
try:
- func(source_dir)
+ func(source_dir, destination_dir)
return True
except ValueError, err:
# failed to install
diff --git a/distutils2/tests/test_install.py b/distutils2/tests/test_install.py
index cb1d499..f613b22 100644
--- 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 @@ class TestInstall(LoggingCatcher, TempdirManager, unittest.TestCase):
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.