diff --git a/hab/cache.py b/hab/cache.py index 9271d57..9dea411 100644 --- a/hab/cache.py +++ b/hab/cache.py @@ -114,7 +114,9 @@ def generate_cache(self, resolver, site_file, version=1): for path in sorted(glob.glob(str(dirname / glob_str))): path = Path(path) try: - data = cls(forest={}, resolver=resolver)._load_raw(path) + data = cls(forest={}, resolver=resolver)._load( + path, cached=False + ) except ( InvalidVersion, InvalidVersionError, diff --git a/hab/parsers/distro_version.py b/hab/parsers/distro_version.py index fbef6a3..bbe830b 100644 --- a/hab/parsers/distro_version.py +++ b/hab/parsers/distro_version.py @@ -1,5 +1,3 @@ -from pathlib import Path - from packaging.version import InvalidVersion, Version from .. import NotSet @@ -100,15 +98,16 @@ def alias_mods(self): """ return self._alias_mods - def _load_raw(self, filename): - """Load the raw cache data and resolve any extra cached data.""" - ret = super()._load_raw(filename) + def _load(self, filename, cached=True): + """Sets self.filename and parses the json file returning the data.""" + ret = super()._load(filename, cached=cached) - # Ensure the version is added to the return and is valid - self.filename = Path(filename) - self.version = self._resolve_version(ret, filename) - ret["version"] = str(self.version) + # Resolve the version from the various supported ways its stored. + self._resolve_version(ret, filename) + if not cached: + # Ensure the version is stored on the returned dictionary + ret["version"] = str(self.version) return ret def load(self, filename): @@ -119,9 +118,6 @@ def load(self, filename): # Store any alias_mods, they will be processed later when flattening self._alias_mods = data.get("alias_mods", NotSet) - # Resolve the version from the various supported ways its stored. - self.version = self._resolve_version(data, filename) - # The name should be the version == specifier. self.distro_name = data.get("name") self.name = "{}=={}".format(self.distro_name, self.version) diff --git a/hab/parsers/hab_base.py b/hab/parsers/hab_base.py index 3cd64a3..65700f9 100644 --- a/hab/parsers/hab_base.py +++ b/hab/parsers/hab_base.py @@ -520,23 +520,25 @@ def inherits(self): # Note: Sub-classes need to override this method to enable inheritance. return False - def _load(self, filename): - """Sets self.filename and parses the json file returning the data.""" + def _load(self, filename, cached=True): + """Sets self.filename and parses the json file returning the data dict. + + Args: + filename (pathlib.Path): The file to load. + cached (bool, optional): Enables loading of cached data instead of + loading the data from disk. + """ self.filename = Path(filename) - ret = self._cache().get(Path(filename).as_posix()) - if ret: - logger.debug(f'Cached: "{filename}"') - return ret + if cached: + ret = self._cache().get(Path(filename).as_posix()) + if ret: + logger.debug(f'Cached: "{filename}"') + return ret logger.debug(f'Loading "{filename}"') return utils.load_json_file(self.filename) - def _load_raw(self, filename): - """Load the raw cache data and resolve any extra cached data.""" - logger.debug(f'Loading "{filename}"') - return utils.load_json_file(filename) - def load(self, filename, data=None): """Load this objects configuration from the given json filename.