From 678639749c447ba79cea9dfd731bdfd40f9f5dac Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 26 Apr 2018 15:31:37 -0700 Subject: init: remove binary_cache_retrieved_specs global variable - remove variable from spack/__init__.py - clean up imports and some code structure in binary_distribution.py --- lib/spack/spack/__init__.py | 11 ----------- lib/spack/spack/binary_distribution.py | 36 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index 2467596a34..714f0e7377 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -25,17 +25,6 @@ ############################################################################## import sys -#----------------------------------------------------------------------------- -# Below code imports spack packages. -#----------------------------------------------------------------------------- -# The imports depend on paths above, or on each other, so ordering is tricky. -# TODO: refactor everything below to be more init order agnostic. - - -# TODO: get this out of __init__.py -binary_cache_retrieved_specs = set() - - #----------------------------------------------------------------------------- # Initialize various data structures & objects at the core of Spack. # diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py index fe0924fddb..2a0dd7633d 100644 --- a/lib/spack/spack/binary_distribution.py +++ b/lib/spack/spack/binary_distribution.py @@ -26,24 +26,26 @@ import os import re import tarfile -import yaml import shutil import platform import tempfile +import hashlib +from contextlib import closing + +import yaml import llnl.util.tty as tty -from spack.util.gpg import Gpg from llnl.util.filesystem import mkdirp, join_path, install_tree -from spack.util.web import spider -import spack.cmd + import spack -from spack.stage import Stage +import spack.cmd import spack.fetch_strategy as fs -from contextlib import closing import spack.util.gpg as gpg_util -import hashlib -from spack.util.executable import ProcessError import spack.relocate as relocate +from spack.stage import Stage +from spack.util.gpg import Gpg +from spack.util.web import spider +from spack.util.executable import ProcessError class NoOverwriteException(Exception): @@ -529,14 +531,19 @@ def extract_tarball(spec, filename, allow_root=False, unsigned=False, shutil.rmtree(tmpdir) +#: Internal cache for get_specs +_cached_specs = None + + def get_specs(force=False): """ Get spec.yaml's for build caches available on mirror """ - if spack.binary_cache_retrieved_specs: + global _cached_specs + + if _cached_specs: tty.debug("Using previously-retrieved specs") - previously_retrieved = spack.binary_cache_retrieved_specs - return previously_retrieved + return _cached_specs mirrors = spack.config.get('mirrors') if len(mirrors) == 0: @@ -562,7 +569,7 @@ def get_specs(force=False): if re.search("spec.yaml", link) and re.search(path, link): urls.add(link) - specs = set() + _cached_specs = set() for link in urls: with Stage(link, name="build_cache", keep=True) as stage: if force and os.path.exists(stage.save_filename): @@ -578,10 +585,9 @@ def get_specs(force=False): # we need to mark this spec concrete on read-in. spec = spack.spec.Spec.from_yaml(f) spec._mark_concrete() - specs.add(spec) + _cached_specs.add(spec) - spack.binary_cache_retrieved_specs = specs - return specs + return _cached_specs def get_keys(install=False, trust=False, force=False): -- cgit v1.2.3-70-g09d2