From 97ac443ebbef3df53d1279416539263faa33d3a8 Mon Sep 17 00:00:00 2001 From: Jim Chiang Date: Fri, 13 Jan 2017 14:50:48 -0800 Subject: [PATCH] code to copy installed versions of packages to install directory --- bin/install.py | 3 +++ tests/test_install.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/install.py b/bin/install.py index aed3fee..b767963 100755 --- a/bin/install.py +++ b/bin/install.py @@ -2,6 +2,7 @@ from __future__ import print_function, absolute_import import os import glob +import shutil import subprocess import warnings import ConfigParser @@ -35,6 +36,8 @@ def __init__(self, version_file, inst_dir='.', self.version_file = os.path.abspath(version_file) if inst_dir is not None: self.inst_dir = os.path.abspath(inst_dir) + shutil.copy(self.version_file, + os.path.join(self.inst_dir, 'installed_versions.txt')) self.hj_folders = hj_folders self.site = site self._package_dirs = None diff --git a/tests/test_install.py b/tests/test_install.py index c8d81dc..6d5763d 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -10,26 +10,31 @@ class InstallTestCase(unittest.TestCase): "TestCase class for install.py execution." def setUp(self): - subprocess.call('rm -rf tmp/', shell=True) - os.mkdir('tmp') + self.inst_dir = 'tmp' + subprocess.call('rm -rf %s/' % self.inst_dir, shell=True) + os.mkdir(self.inst_dir) def tearDown(self): os.remove('install.log') - subprocess.call('rm -rf tmp/', shell=True) + subprocess.call('rm -rf %s/' % self.inst_dir, shell=True) def test_install_py(self): "Test install.py" - command = '(../bin/install.py --inst_dir tmp test_install_versions.txt) >& install.log' + command = '(../bin/install.py --inst_dir %s test_install_versions.txt) >& install.log' % self.inst_dir self.assertEqual(subprocess.check_call(command, shell=True, executable='/bin/bash'), 0) - command = 'source tmp/setup.sh; python -c "import siteUtils; import metUtils; import vendorFitsTranslators; import eotestUtils; import lsst.eotest.sensor"' + command = 'source %s/setup.sh; python -c "import siteUtils; import metUtils; import vendorFitsTranslators; import eotestUtils; import lsst.eotest.sensor"' % self.inst_dir self.assertEqual(subprocess.check_call(command, shell=True, executable='/bin/bash'), 0) - args = ('source tmp/setup.sh; python -c "import foobar"',) + args = ('source %s/setup.sh; python -c "import foobar"' + % self.inst_dir,) kwds = dict(shell=True, executable='/bin/bash', stderr=subprocess.STDOUT) self.assertRaises(subprocess.CalledProcessError, subprocess.check_output, *args, **kwds) + self.assertTrue(os.path.isfile(os.path.join(self.inst_dir, + 'installed_versions.txt'))) + if __name__ == '__main__': unittest.main()