def _update_provider_index(self): # Check modification dates of all packages self._fast_package_check() def read(): with open(self.index_file) as f: self._provider_index = ProviderIndex.from_yaml(f) # Read the old ProviderIndex, or make a new one. key = self._cache_file index_existed = spack.misc_cache.init_entry(key) if index_existed and not self._needs_update: with spack.misc_cache.read_transaction(key) as f: self._provider_index = ProviderIndex.from_yaml(f) else: with spack.misc_cache.write_transaction(key) as (old, new): if old: self._provider_index = ProviderIndex.from_yaml(old) else: self._provider_index = ProviderIndex() for pkg_name in self._needs_update: namespaced_name = '%s.%s' % (self.namespace, pkg_name) self._provider_index.remove_provider(namespaced_name) self._provider_index.update(namespaced_name) self._provider_index.to_yaml(new)
def _update_provider_index(self): # Check modification dates of all packages self._fast_package_check() def read(): with open(self.index_file) as f: self._provider_index = ProviderIndex.from_yaml(f) # Read the old ProviderIndex, or make a new one. key = self._cache_file index_existed = spack.misc_cache.init_entry(key) if index_existed and not self._needs_update: with spack.misc_cache.read_transaction(key) as f: self._provider_index = ProviderIndex.from_yaml(f) else: with spack.misc_cache.write_transaction(key) as (old, new): if old: self._provider_index = ProviderIndex.from_yaml(old) else: self._provider_index = ProviderIndex() for pkg_name in self._needs_update: namespaced_name = '%s.%s' % (self.namespace, pkg_name) self._provider_index.remove_provider(namespaced_name) self._provider_index.update(namespaced_name) self._provider_index.to_yaml(new)
def make_provider_index_cache(packages_path, namespace): """Lazily updates the provider index cache associated with a repository, if need be, then returns it. Caches results for later look-ups. Args: packages_path: path of the repository namespace: namespace of the repository Returns: instance of ProviderIndex """ # Map that goes from package names to stat info fast_package_checker = FastPackageChecker(packages_path) # Filename of the provider index cache cache_filename = 'providers/{0}-index.yaml'.format(namespace) # Compute which packages needs to be updated in the cache misc_cache = spack.caches.misc_cache index_mtime = misc_cache.mtime(cache_filename) needs_update = [ x for x, sinfo in fast_package_checker.items() if sinfo.st_mtime > index_mtime ] # Read the old ProviderIndex, or make a new one. index_existed = misc_cache.init_entry(cache_filename) if index_existed and not needs_update: # If the provider index exists and doesn't need an update # just read from it with misc_cache.read_transaction(cache_filename) as f: index = ProviderIndex.from_yaml(f) else: # Otherwise we need a write transaction to update it with misc_cache.write_transaction(cache_filename) as (old, new): index = ProviderIndex.from_yaml(old) if old else ProviderIndex() for pkg_name in needs_update: namespaced_name = '{0}.{1}'.format(namespace, pkg_name) index.remove_provider(namespaced_name) index.update(namespaced_name) index.to_yaml(new) return index
def make_provider_index_cache(packages_path, namespace): """Lazily updates the provider index cache associated with a repository, if need be, then returns it. Caches results for later look-ups. Args: packages_path: path of the repository namespace: namespace of the repository Returns: instance of ProviderIndex """ # Map that goes from package names to stat info fast_package_checker = FastPackageChecker(packages_path) # Filename of the provider index cache cache_filename = 'providers/{0}-index.yaml'.format(namespace) # Compute which packages needs to be updated in the cache misc_cache = spack.caches.misc_cache index_mtime = misc_cache.mtime(cache_filename) needs_update = [ x for x, sinfo in fast_package_checker.items() if sinfo.st_mtime > index_mtime ] # Read the old ProviderIndex, or make a new one. index_existed = misc_cache.init_entry(cache_filename) if index_existed and not needs_update: # If the provider index exists and doesn't need an update # just read from it with misc_cache.read_transaction(cache_filename) as f: index = ProviderIndex.from_yaml(f) else: # Otherwise we need a write transaction to update it with misc_cache.write_transaction(cache_filename) as (old, new): index = ProviderIndex.from_yaml(old) if old else ProviderIndex() for pkg_name in needs_update: namespaced_name = '{0}.{1}'.format(namespace, pkg_name) index.remove_provider(namespaced_name) index.update(namespaced_name) index.to_yaml(new) return index
def test_yaml_round_trip(mock_packages): p = ProviderIndex(spack.repo.all_package_names()) ostream = StringIO() p.to_yaml(ostream) istream = StringIO(ostream.getvalue()) q = ProviderIndex.from_yaml(istream) assert p == q
def test_yaml_round_trip(mock_packages): p = ProviderIndex(spack.repo.all_package_names()) ostream = StringIO() p.to_yaml(ostream) istream = StringIO(ostream.getvalue()) q = ProviderIndex.from_yaml(istream) assert p == q
def test_yaml_round_trip(self): p = ProviderIndex(spack.repo.all_package_names()) ostream = StringIO() p.to_yaml(ostream) istream = StringIO(ostream.getvalue()) q = ProviderIndex.from_yaml(istream) self.assertEqual(p, q)
def read(): with open(self.index_file) as f: self._provider_index = ProviderIndex.from_yaml(f)
def read(): with open(self.index_file) as f: self._provider_index = ProviderIndex.from_yaml(f)