From 1ae03b327cd8297cdf1067c03ec833d739d36d8b Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Fri, 21 Jun 2019 16:56:38 -0700 Subject: 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. --- lib/spack/spack/stage.py | 16 ++++++++++++---- lib/spack/spack/test/stage.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py index 6d5848da38..4249ec6f85 100644 --- a/lib/spack/spack/stage.py +++ b/lib/spack/spack/stage.py @@ -296,13 +296,21 @@ class Stage(object): 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 diff --git a/lib/spack/spack/test/stage.py b/lib/spack/spack/test/stage.py index 908771de90..9f5e7363f5 100644 --- a/lib/spack/spack/test/stage.py +++ b/lib/spack/spack/test/stage.py @@ -465,6 +465,19 @@ class TestStage(object): 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( -- cgit v1.2.3-70-g09d2