Use Stage.archive_file to access non-expanded download (#11817)

Fixes #11816

Allow packages to refer to non-expanded downloads (e.g. a single
script) using Stage.archive_file. This addresses a regression from
#11688 and adds a unit test for it.
This commit is contained in:
Peter Scheibel 2019-06-21 16:56:38 -07:00 committed by GitHub
parent 98d21193ff
commit 1ae03b327c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -296,13 +296,21 @@ def _need_to_create_path(self):
def expected_archive_files(self):
"""Possible archive file paths."""
paths = []
fnames = []
expanded = True
if isinstance(self.default_fetcher, fs.URLFetchStrategy):
paths.append(os.path.join(
self.path, os.path.basename(self.default_fetcher.url)))
expanded = self.default_fetcher.expand_archive
fnames.append(os.path.basename(self.default_fetcher.url))
if self.mirror_path:
paths.append(os.path.join(
self.path, os.path.basename(self.mirror_path)))
fnames.append(os.path.basename(self.mirror_path))
paths.extend(os.path.join(self.path, f) for f in fnames)
if not expanded:
# If the download file is not compressed, the "archive" is a
# single file placed in Stage.source_path
paths.extend(os.path.join(self.source_path, f) for f in fnames)
return paths

View File

@ -465,6 +465,19 @@ def test_setup_and_destroy_no_name_with_tmp(self, mock_stage_archive):
check_setup(stage, None, archive)
check_destroy(stage, None)
@pytest.mark.usefixtures('tmpdir_for_stage')
def test_noexpand_stage_file(
self, mock_stage_archive, mock_noexpand_resource):
"""When creating a stage with a nonexpanding URL, the 'archive_file'
property of the stage should refer to the path of that file.
"""
test_noexpand_fetcher = spack.fetch_strategy.from_kwargs(
url='file://' + mock_noexpand_resource, expand=False)
with Stage(test_noexpand_fetcher) as stage:
stage.fetch()
stage.expand_archive()
assert os.path.exists(stage.archive_file)
@pytest.mark.disable_clean_stage_check
@pytest.mark.usefixtures('tmpdir_for_stage')
def test_composite_stage_with_noexpand_resource(