Skip to content

Commit 2e39fdf

Browse files
committed
treat metadata_dir as an instance variable but dont set it from kwargs; this follows several other hardcoded variables which must be consistent between upstream and downstream DBs. Also update DirectoryLayout.metadata_path to work entirely with Spec.prefix, since Spec.prefix is set from the DB when available (so metadata_path was duplicating that logic)
1 parent 1cecc40 commit 2e39fdf

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

lib/spack/spack/directory_layout.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ class YamlDirectoryLayout(DirectoryLayout):
171171
arguments hash_len and path_scheme.
172172
"""
173173

174-
metadata_dir = '.spack'
175-
176174
def __init__(self, root, **kwargs):
177175
super(YamlDirectoryLayout, self).__init__(root)
178176
self.hash_len = kwargs.get('hash_len')
@@ -187,6 +185,9 @@ def __init__(self, root, **kwargs):
187185
self.path_scheme = self.path_scheme.replace(
188186
"${HASH}", "${HASH:%d}" % self.hash_len)
189187

188+
# If any of these paths change, downstream databases may not be able to
189+
# locate files in older upstream databases
190+
self.metadata_dir = '.spack'
190191
self.spec_file_name = 'spec.yaml'
191192
self.extension_file_name = 'extensions.yaml'
192193
self.build_log_name = 'build.out' # build log.
@@ -195,7 +196,7 @@ def __init__(self, root, **kwargs):
195196

196197
@property
197198
def hidden_file_paths(self):
198-
return (YamlDirectoryLayout.metadata_dir,)
199+
return (self.metadata_dir,)
199200

200201
def relative_path_for_spec(self, spec):
201202
_check_concrete(spec)
@@ -236,11 +237,7 @@ def disable_upstream_check(self):
236237
self.check_upstream = True
237238

238239
def metadata_path(self, spec):
239-
if self.check_upstream and spec.package.installed_upstream:
240-
return os.path.join(spec.prefix, YamlDirectoryLayout.metadata_dir)
241-
else:
242-
return os.path.join(
243-
self.path_for_spec(spec), YamlDirectoryLayout.metadata_dir)
240+
return os.path.join(spec.prefix, self.metadata_dir)
244241

245242
def build_log_path(self, spec):
246243
return os.path.join(self.metadata_path(spec), self.build_log_name)
@@ -308,7 +305,7 @@ def all_specs(self):
308305
return []
309306

310307
path_elems = ["*"] * len(self.path_scheme.split(os.sep))
311-
path_elems += [YamlDirectoryLayout.metadata_dir, self.spec_file_name]
308+
path_elems += [self.metadata_dir, self.spec_file_name]
312309
pattern = os.path.join(self.root, *path_elems)
313310
spec_files = glob.glob(pattern)
314311
return [self.read_spec(s) for s in spec_files]
@@ -374,11 +371,11 @@ def extension_file_path(self, spec):
374371
# For backwards compatibility, when the view is the extended
375372
# package's installation directory, do not include the spec name
376373
# as a subdirectory.
377-
components = [view_prefix, YamlDirectoryLayout.metadata_dir,
374+
components = [view_prefix, self.metadata_dir,
378375
self.extension_file_name]
379376
else:
380-
components = [view_prefix, YamlDirectoryLayout.metadata_dir,
381-
spec.name, self.extension_file_name]
377+
components = [view_prefix, self.metadata_dir, spec.name,
378+
self.extension_file_name]
382379

383380
return os.path.join(*components)
384381

lib/spack/spack/test/directory_layout.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
@pytest.fixture()
2323
def layout_and_dir(tmpdir):
2424
"""Returns a directory layout and the corresponding directory."""
25-
yield YamlDirectoryLayout(str(tmpdir)), str(tmpdir)
25+
layout = YamlDirectoryLayout(str(tmpdir))
26+
old_layout = spack.store.layout
27+
spack.store.layout = layout
28+
yield layout, str(tmpdir)
29+
spack.store.layout = old_layout
2630

2731

2832
def test_yaml_directory_layout_parameters(

0 commit comments

Comments
 (0)