summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/package.py23
-rw-r--r--lib/spack/spack/test/stage.py40
2 files changed, 49 insertions, 14 deletions
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index 049d193eef..d9f76b411e 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -247,17 +247,16 @@ class Package(object):
"""
#
- # These variables are per-package metadata will be defined by subclasses.
+ # These variables are defaults for the various relations defined on
+ # packages. Subclasses will have their own versions of these.
#
- """By default a package has no dependencies."""
+ """Specs of dependency packages, keyed by name."""
dependencies = {}
- """List of specs of virtual packages provided by this package."""
+ """Specs of virtual packages provided by this package, keyed by name."""
provided = {}
- """List of specs of conflicting packages.
- TODO: implement conflicts.
- """
+ """Specs of conflicting packages, keyed by name. """
conflicted = {}
#
@@ -272,6 +271,7 @@ class Package(object):
"""Controls whether install and uninstall check deps before running."""
ignore_dependencies = False
+
def __init__(self, spec):
# These attributes are required for all packages.
attr_required(self, 'homepage')
@@ -292,18 +292,17 @@ class Package(object):
validate.url(self.url)
# Set up version
+ # TODO: get rid of version attr and use spec
+ # TODO: roll this into available_versions
if not hasattr(self, 'version'):
try:
self.version = url.parse_version(self.url)
except UndetectableVersionError:
tty.die("Couldn't extract a default version from %s. You " +
"must specify it explicitly in the package." % self.url)
- elif type(self.version) == string:
+ elif type(self.version) != Version:
self.version = Version(self.version)
- # Empty at first; only compute dependent packages if necessary
- self._dependents = None
-
# This is set by scraping a web page.
self._available_versions = None
@@ -312,6 +311,9 @@ class Package(object):
if self.versions and type(self.versions) != VersionList:
self.versions = VersionList(self.versions)
+ # Empty at first; only compute dependent packages if necessary
+ self._dependents = None
+
# stage used to build this package.
# TODO: hash the concrete spec and use that as the stage name.
self.stage = Stage(self.url, "%s-%s" % (self.name, self.version))
@@ -390,6 +392,7 @@ class Package(object):
def preorder_traversal(self, visited=None):
+ """This does a preorder traversal of the package's dependence DAG."""
if visited is None:
visited = set()
diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py
index 19c0ed2fb3..4fa9ce2f4d 100644
--- a/lib/spack/spack/test/stage.py
+++ b/lib/spack/spack/test/stage.py
@@ -118,15 +118,19 @@ class StageTest(unittest.TestCase):
def check_fetch(self, stage, stage_name):
stage_path = self.get_stage_path(stage, stage_name)
- self.assertTrue(archive_name in os.listdir(stage_path))
+ self.assertIn(archive_name, os.listdir(stage_path))
self.assertEqual(new_path(stage_path, archive_name),
stage.archive_file)
def check_expand_archive(self, stage, stage_name):
stage_path = self.get_stage_path(stage, stage_name)
- self.assertTrue(archive_name in os.listdir(stage_path))
- self.assertTrue(archive_dir in os.listdir(stage_path))
+ self.assertIn(archive_name, os.listdir(stage_path))
+ self.assertIn(archive_dir, os.listdir(stage_path))
+
+ self.assertEqual(
+ new_path(stage_path, archive_dir),
+ stage.expanded_archive_path)
readme = new_path(stage_path, archive_dir, readme_name)
self.assertTrue(os.path.isfile(readme))
@@ -226,7 +230,7 @@ class StageTest(unittest.TestCase):
self.check_destroy(stage, stage_name)
- def test_zexpand_archive(self):
+ def test_expand_archive(self):
stage = Stage(archive_url, stage_name)
stage.fetch()
@@ -240,3 +244,31 @@ class StageTest(unittest.TestCase):
stage.destroy()
self.check_destroy(stage, stage_name)
+
+
+ def test_restage(self):
+ stage = Stage(archive_url, stage_name)
+
+ stage.fetch()
+ stage.expand_archive()
+ stage.chdir_to_archive()
+ self.check_expand_archive(stage, stage_name)
+ self.check_chdir_to_archive(stage, stage_name)
+
+ # Try to make a file in the old archive dir
+ with closing(open('foobar', 'w')) as file:
+ file.write("this file is to be destroyed.")
+
+ self.assertIn('foobar', os.listdir(stage.expanded_archive_path))
+
+ # Make sure the file is not there after restage.
+ stage.restage()
+ self.check_chdir(stage, stage_name)
+ self.check_fetch(stage, stage_name)
+
+ stage.chdir_to_archive()
+ self.check_chdir_to_archive(stage, stage_name)
+ self.assertNotIn('foobar', os.listdir(stage.expanded_archive_path))
+
+ stage.destroy()
+ self.check_destroy(stage, stage_name)