_download_all.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. Platform independent script to download all the
  3. `scipy.datasets` module data files.
  4. This doesn't require a full scipy build.
  5. Run: python _download_all.py <download_dir>
  6. """
  7. import argparse
  8. try:
  9. import pooch
  10. except ImportError:
  11. pooch = None
  12. if __package__ is None or __package__ == '':
  13. # Running as python script, use absolute import
  14. import _registry # type: ignore
  15. else:
  16. # Running as python module, use relative import
  17. from . import _registry
  18. def download_all(path=None):
  19. """
  20. Utility method to download all the dataset files
  21. for `scipy.datasets` module.
  22. Parameters
  23. ----------
  24. path : str, optional
  25. Directory path to download all the dataset files.
  26. If None, default to the system cache_dir detected by pooch.
  27. """
  28. if pooch is None:
  29. raise ImportError("Missing optional dependency 'pooch' required "
  30. "for scipy.datasets module. Please use pip or "
  31. "conda to install 'pooch'.")
  32. if path is None:
  33. path = pooch.os_cache('scipy-data')
  34. for dataset_name, dataset_hash in _registry.registry.items():
  35. pooch.retrieve(url=_registry.registry_urls[dataset_name],
  36. known_hash=dataset_hash,
  37. fname=dataset_name, path=path)
  38. def main():
  39. parser = argparse.ArgumentParser(description='Download SciPy data files.')
  40. parser.add_argument("path", nargs='?', type=str,
  41. default=pooch.os_cache('scipy-data'),
  42. help="Directory path to download all the data files.")
  43. args = parser.parse_args()
  44. download_all(args.path)
  45. if __name__ == "__main__":
  46. main()