Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free disk space #255

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'termcolor',
'tqdm',
'wrapt',
'psutil'
]

TESTS_REQUIRE = [
Expand Down
17 changes: 15 additions & 2 deletions tensorflow_datasets/core/dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from absl import logging
import six
import psutil
import tensorflow as tf

from tensorflow_datasets.core import api_utils
Expand Down Expand Up @@ -385,13 +386,25 @@ def _log_download_bytes(self):
# Print is intentional: we want this to always go to stdout so user has
# information needed to cancel download/preparation if needed.
# This comes right before the progress bar.

dataset_size = self.info.size_in_bytes
disk_size = psutil.disk_usage(self._data_dir_root).free

def _check_disk_size():
if dataset_size > disk_size:
raise IOError("Not enough disk space!!\nDataset size : {dataset_size} \nFree size : {free_disk_size} "
"\nYou need to extra {needed_disk_size} to download. "
.format(dataset_size=units.size_str(dataset_size),
free_disk_size=units.size_str(disk_size),
needed_disk_size=units.size_str(dataset_size - disk_size)))

_check_disk_size()

size_text = units.size_str(self.info.size_in_bytes)
termcolor.cprint(
"Downloading / extracting dataset %s (%s) to %s..." %
(self.name, size_text, self._data_dir),
attrs=["bold"])
# TODO(tfds): Should try to estimate the available free disk space (if
# possible) and raise an error if not.

@abc.abstractmethod
def _info(self):
Expand Down