Better mirror path calculation.
- Add support in spack.url for extrapolating actual file type for URL - Move mirror path computation to mirror.py from package.py
This commit is contained in:
parent
2f90068661
commit
722e73f309
@ -37,6 +37,7 @@
|
||||
|
||||
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'
|
||||
|
@ -51,6 +51,7 @@
|
||||
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 @@ def stage(self):
|
||||
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 @@ def fetcher(self, f):
|
||||
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)
|
||||
|
@ -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."""
|
||||
|
Loading…
Reference in New Issue
Block a user