Esempio n. 1
0
def _get_last_installed_version(
    name: utils.DatasetName,
) -> Optional[_InstalledPackage]:
  """Checks whether the datasets is installed locally and returns it."""
  root_dir = (
      cache.module_path() / _IMPORT_MODULE_NAME / name.namespace / name.name
  )
  if not root_dir.exists():  # Dataset not found
    return None

  all_installed_package_metadatas = [
      package / _METADATA_FILENAME for package in root_dir.iterdir()
  ]
  all_installed_packages = [
      _InstalledPackage.from_json(json.loads(metadata.read_text()))
      for metadata in all_installed_package_metadatas
      if metadata.exists()
  ]
  all_installed_packages = sorted(
      all_installed_packages, key=lambda p: p.instalation_date
  )

  if not all_installed_packages:  # No valid package found
    return None
  else:
    return all_installed_packages[-1]  # Most recently installed package
 def installation_path(self) -> utils.ReadWritePath:
     """Local path of the package."""
     name = self.package.name
     sub_dir = f'{_IMPORT_MODULE_NAME}/{name.namespace}/{name.name}/{self.hash}'
     return cache.module_path() / sub_dir
def test_mock_cache_path(tmp_path: pathlib.Path):
    with mock_cache_path(tmp_path):
        assert os.fspath(tmp_path) not in sys.path
        assert cache.cache_path() == tmp_path
        assert cache.module_path() == tmp_path / 'modules'
        assert os.fspath(tmp_path / 'modules') in sys.path