diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/mirror.py | 3 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 14 | ||||
-rw-r--r-- | lib/spack/spack/url.py | 21 |
3 files changed, 27 insertions, 11 deletions
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py index 9c700cd551..929c514b61 100644 --- a/lib/spack/spack/mirror.py +++ b/lib/spack/spack/mirror.py @@ -37,6 +37,7 @@ from llnl.util.filesystem import * import spack import spack.error +import spack.url as url import spack.fetch_strategy as fs from spack.spec import Spec from spack.stage import Stage @@ -52,7 +53,7 @@ def mirror_archive_filename(spec): fetcher = spec.package.fetcher if isinstance(fetcher, fs.URLFetchStrategy): # If we fetch this version with a URLFetchStrategy, use URL's archive type - ext = extension(fetcher.url) + ext = url.downloaded_file_extension(fetcher.url) else: # Otherwise we'll make a .tar.gz ourselves ext = 'tar.gz' diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index bb6180c521..d296e6c189 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -51,6 +51,7 @@ import spack import spack.spec import spack.error import spack.compilers +import spack.mirror import spack.hooks import spack.build_environment as build_env import spack.url as url @@ -453,9 +454,9 @@ class Package(object): raise ValueError("Can only get a stage for a concrete package.") if self._stage is None: - self._stage = Stage(self.fetcher, - mirror_path=self.mirror_path(), - name=self.spec.short_spec) + mp = spack.mirror.mirror_archive_filename(self.spec) + self._stage = Stage( + self.fetcher, mirror_path=mp, name=self.spec.short_spec) return self._stage @@ -475,13 +476,6 @@ class Package(object): self._fetcher = f - def mirror_path(self): - """Get path to this package's archive in a mirror.""" - filename = "%s-%s." % (self.name, self.version) - filename += extension(self.url) if self.url else "tar.gz" - return "%s/%s" % (self.name, filename) - - def preorder_traversal(self, visited=None, **kwargs): """This does a preorder traversal of the package's dependence DAG.""" virtual = kwargs.get("virtual", False) diff --git a/lib/spack/spack/url.py b/lib/spack/spack/url.py index 2948c12df5..58838306af 100644 --- a/lib/spack/spack/url.py +++ b/lib/spack/spack/url.py @@ -140,6 +140,27 @@ def split_url_extension(path): return prefix, ext, suffix +def downloaded_file_extension(path): + """This returns the type of archive a URL refers to. This is + sometimes confusing becasue of URLs like: + + (1) https://github.com/petdance/ack/tarball/1.93_02 + + Where the URL doesn't actually contain the filename. We need + to know what type it is so that we can appropriately name files + in mirrors. + """ + match = re.search(r'github.com/.+/(zip|tar)ball/', path) + if match: + if match.group(1) == 'zip': return 'zip' + elif match.group(1) == 'tar': return 'tar.gz' + + prefix, ext, suffix = split_url_extension(path) + if not ext: + raise UrlParseError("Cannot deduce archive type in %s" % path, path) + return ext + + def parse_version_offset(path): """Try to extract a version string from a filename or URL. This is taken largely from Homebrew's Version class.""" |