Convert lazy singleton functions to Singleton object

- simplify the singleton pattern across the codebase
- reduce lines of code needed for crufty initialization
- reduce functions that need to mess with a global

- Singletons whose semantics changed:
  - spack.store.store() -> spack.store
  - spack.repo.path() -> spack.repo.path
  - spack.config.config() -> spack.config.config
  - spack.caches.fetch_cache() -> spack.caches.fetch_cache
  - spack.caches.misc_cache() -> spack.caches.misc_cache
This commit is contained in:
Todd Gamblin
2018-05-16 10:57:40 -07:00
committed by scheibelp
parent 3493f7e793
commit f202198777
66 changed files with 514 additions and 553 deletions

View File

@@ -50,8 +50,8 @@ class Aspell(AutotoolsPackage):
# - dest_dir instead of self.prefix in tree.(find_conflict|merge)()
def activate(self, extension, **kwargs):
extensions_layout = kwargs.get("extensions_layout",
spack.store.store().extensions)
if extensions_layout is not spack.store.store().extensions:
spack.store.extensions)
if extensions_layout is not spack.store.extensions:
raise ExtensionError(
'aspell does not support non-global extensions')
@@ -60,7 +60,7 @@ def activate(self, extension, **kwargs):
tree = LinkTree(extension.prefix.lib)
def ignore(filename):
return (filename in spack.store.store().layout.hidden_file_paths or
return (filename in spack.store.layout.hidden_file_paths or
kwargs.get('ignore', lambda f: False)(filename))
conflict = tree.find_conflict(dest_dir, ignore=ignore)
@@ -71,8 +71,8 @@ def ignore(filename):
def deactivate(self, extension, **kwargs):
extensions_layout = kwargs.get("extensions_layout",
spack.store.store().extensions)
if extensions_layout is not spack.store.store().extensions:
spack.store.extensions)
if extensions_layout is not spack.store.extensions:
raise ExtensionError(
'aspell does not support non-global extensions')
@@ -80,7 +80,7 @@ def deactivate(self, extension, **kwargs):
dest_dir = aspell('dump', 'config', 'dict-dir', output=str).strip()
def ignore(filename):
return (filename in spack.store.store().layout.hidden_file_paths or
return (filename in spack.store.layout.hidden_file_paths or
kwargs.get('ignore', lambda f: False)(filename))
tree = LinkTree(extension.prefix.lib)

View File

@@ -193,7 +193,7 @@ def set_CrayLoginNode_cmakeOptions(self, spec, cmakeOptions):
# the login node components with this spack invocation. We
# need these paths to be the ones created in the CNL
# spack invocation.
store = spack.store.store()
store = spack.store
be_cbtf = store.db.query_one('cbtf arch=cray-CNL-haswell')
be_cbtfk = store.db.query_one('cbtf-krell arch=cray-CNL-haswell')
be_papi = store.db.query_one('papi arch=cray-CNL-haswell')

View File

@@ -197,7 +197,7 @@ def set_CrayLoginNode_cmakeOptions(self, spec, cmakeOptions):
# spec['cbtf'].prefix is the login node value for this build, as
# we only get here when building the login node components and
# that is all that is known to spack.
store = spack.store.store()
store = spack.store
be_ck = store.db.query_one('cbtf-krell arch=cray-CNL-haswell')
# Equivalent to install-tool cmake arg:

View File

@@ -264,7 +264,7 @@ def activate(self, ext_pkg, **args):
super(Perl, self).activate(ext_pkg, **args)
extensions_layout = args.get("extensions_layout",
spack.store.store().extensions)
spack.store.extensions)
exts = extensions_layout.extension_map(self.spec)
exts[ext_pkg.name] = ext_pkg.spec
@@ -276,7 +276,7 @@ def deactivate(self, ext_pkg, **args):
super(Perl, self).deactivate(ext_pkg, **args)
extensions_layout = args.get("extensions_layout",
spack.store.store().extensions)
spack.store.extensions)
exts = extensions_layout.extension_map(self.spec)
# Make deactivate idempotent

View File

@@ -320,7 +320,7 @@ def _save_distutil_vars(self, prefix):
output_filename = None
try:
output_filename = join_path(
spack.store.store().layout.metadata_path(self.spec),
spack.store.layout.metadata_path(self.spec),
Python._DISTUTIL_CACHE_FILENAME)
with open(output_filename, 'w') as output_file:
sjson.dump(self._distutil_vars, output_file)
@@ -342,7 +342,7 @@ def _load_distutil_vars(self):
if not self._distutil_vars and self.installed:
try:
input_filename = join_path(
spack.store.store().layout.metadata_path(self.spec),
spack.store.layout.metadata_path(self.spec),
Python._DISTUTIL_CACHE_FILENAME)
if os.path.isfile(input_filename):
with open(input_filename) as input_file:
@@ -680,7 +680,7 @@ def activate(self, ext_pkg, **args):
args.update(ignore=ignore)
extensions_layout = args.get("extensions_layout",
spack.store.store().extensions)
spack.store.extensions)
super(Python, self).activate(ext_pkg, **args)
@@ -696,7 +696,7 @@ def deactivate(self, ext_pkg, **args):
super(Python, self).deactivate(ext_pkg, **args)
extensions_layout = args.get("extensions_layout",
spack.store.store().extensions)
spack.store.extensions)
exts = extensions_layout.extension_map(self.spec)
# Make deactivate idempotent