Remove DIYStage (#44949)

This commit is contained in:
Harmen Stoppels 2024-07-01 08:33:56 +02:00 committed by Harmen Stoppels
parent d299e17d43
commit eb2b5739b2
4 changed files with 9 additions and 141 deletions

View file

@ -1561,13 +1561,11 @@ def do_patch(self):
tty.debug("Patching failed last time. Restaging.") tty.debug("Patching failed last time. Restaging.")
self.stage.restage() self.stage.restage()
else: else:
# develop specs/ DIYStages may have patch failures but # develop specs may have patch failures but should never be restaged
# should never be restaged tty.warn(
msg = ( f"A patch failure was detected in {self.name}."
"A patch failure was detected in %s." % self.name " Build errors may occur due to this."
+ " Build errors may occur due to this."
) )
tty.warn(msg)
return return
# If this file exists, then we already applied all the patches. # If this file exists, then we already applied all the patches.

View file

@ -346,7 +346,7 @@ class Stage(LockableStagingDir):
similar, and are intended to persist for only one run of spack. similar, and are intended to persist for only one run of spack.
""" """
#: Most staging is managed by Spack. DIYStage is one exception. #: Most staging is managed by Spack. DevelopStage is one exception.
needs_fetching = True needs_fetching = True
requires_patch_success = True requires_patch_success = True
@ -822,62 +822,6 @@ def keep(self, value):
item.keep = value item.keep = value
class DIYStage:
"""
Simple class that allows any directory to be a spack stage. Consequently,
it does not expect or require that the source path adhere to the standard
directory naming convention.
"""
needs_fetching = False
requires_patch_success = False
def __init__(self, path):
if path is None:
raise ValueError("Cannot construct DIYStage without a path.")
elif not os.path.isdir(path):
raise StagePathError("The stage path directory does not exist:", path)
self.archive_file = None
self.path = path
self.source_path = path
self.created = True
# DIY stages do nothing as context managers.
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
pass
def fetch(self, *args, **kwargs):
tty.debug("No need to fetch for DIY.")
def check(self):
tty.debug("No checksum needed for DIY.")
def expand_archive(self):
tty.debug("Using source directory: {0}".format(self.source_path))
@property
def expanded(self):
"""Returns True since the source_path must exist."""
return True
def restage(self):
raise RestageError("Cannot restage a DIY stage.")
def create(self):
self.created = True
def destroy(self):
# No need to destroy DIY stage.
pass
def cache_local(self):
tty.debug("Sources for DIY stages are not cached")
class DevelopStage(LockableStagingDir): class DevelopStage(LockableStagingDir):
needs_fetching = False needs_fetching = False
requires_patch_success = False requires_patch_success = False

View file

@ -103,23 +103,6 @@ def test_repo(_create_test_repo, monkeypatch, mock_stage):
yield mock_repo_path yield mock_repo_path
class MakeStage:
def __init__(self, stage):
self.stage = stage
def __call__(self, *args, **kwargs):
return self.stage
@pytest.fixture
def fake_installs(monkeypatch, tmpdir):
stage_path = str(tmpdir.ensure("fake-stage", dir=True))
universal_unused_stage = spack.stage.DIYStage(stage_path)
monkeypatch.setattr(
spack.build_systems.generic.Package, "_make_stage", MakeStage(universal_unused_stage)
)
def test_one_package_multiple_reqs(concretize_scope, test_repo): def test_one_package_multiple_reqs(concretize_scope, test_repo):
conf_str = """\ conf_str = """\
packages: packages:
@ -514,7 +497,7 @@ def test_oneof_ordering(concretize_scope, test_repo):
assert s2.satisfies("@2.5") assert s2.satisfies("@2.5")
def test_reuse_oneof(concretize_scope, _create_test_repo, mutable_database, fake_installs): def test_reuse_oneof(concretize_scope, _create_test_repo, mutable_database, mock_fetch):
conf_str = """\ conf_str = """\
packages: packages:
y: y:

View file

@ -23,7 +23,7 @@
import spack.util.executable import spack.util.executable
import spack.util.url as url_util import spack.util.url as url_util
from spack.resource import Resource from spack.resource import Resource
from spack.stage import DevelopStage, DIYStage, ResourceStage, Stage, StageComposite from spack.stage import DevelopStage, ResourceStage, Stage, StageComposite
from spack.util.path import canonicalize_path from spack.util.path import canonicalize_path
# The following values are used for common fetch and stage mocking fixtures: # The following values are used for common fetch and stage mocking fixtures:
@ -146,9 +146,8 @@ def check_destroy(stage, stage_name):
assert not os.path.exists(stage_path) assert not os.path.exists(stage_path)
# tmp stage needs to remove tmp dir too. # tmp stage needs to remove tmp dir too.
if not isinstance(stage, DIYStage): target = os.path.realpath(stage_path)
target = os.path.realpath(stage_path) assert not os.path.exists(target)
assert not os.path.exists(target)
def check_setup(stage, stage_name, archive): def check_setup(stage, stage_name, archive):
@ -801,62 +800,6 @@ def test_stage_constructor_with_path(self, tmpdir):
with Stage("file:///does-not-exist", path=testpath) as stage: with Stage("file:///does-not-exist", path=testpath) as stage:
assert stage.path == testpath assert stage.path == testpath
def test_diystage_path_none(self):
"""Ensure DIYStage for path=None behaves as expected."""
with pytest.raises(ValueError):
DIYStage(None)
def test_diystage_path_invalid(self):
"""Ensure DIYStage for an invalid path behaves as expected."""
with pytest.raises(spack.stage.StagePathError):
DIYStage("/path/does/not/exist")
def test_diystage_path_valid(self, tmpdir):
"""Ensure DIYStage for a valid path behaves as expected."""
path = str(tmpdir)
stage = DIYStage(path)
assert stage.path == path
assert stage.source_path == path
# Order doesn't really matter for DIYStage since they are
# basically NOOPs; however, call each since they are part
# of the normal stage usage and to ensure full test coverage.
stage.create() # Only sets the flag value
assert stage.created
stage.cache_local() # Only outputs a message
stage.fetch() # Only outputs a message
stage.check() # Only outputs a message
stage.expand_archive() # Only outputs a message
assert stage.expanded # The path/source_path does exist
with pytest.raises(spack.stage.RestageError):
stage.restage()
stage.destroy() # A no-op
assert stage.path == path # Ensure can still access attributes
assert os.path.exists(stage.source_path) # Ensure path still exists
def test_diystage_preserve_file(self, tmpdir):
"""Ensure DIYStage preserves an existing file."""
# Write a file to the temporary directory
fn = tmpdir.join(_readme_fn)
fn.write(_readme_contents)
# Instantiate the DIYStage and ensure the above file is unchanged.
path = str(tmpdir)
stage = DIYStage(path)
assert os.path.isdir(path)
assert os.path.isfile(str(fn))
stage.create() # Only sets the flag value
readmefn = str(fn)
assert os.path.isfile(readmefn)
with open(readmefn) as _file:
_file.read() == _readme_contents
def _create_files_from_tree(base, tree): def _create_files_from_tree(base, tree):
for name, content in tree.items(): for name, content in tree.items():