From 29447ade5ed56dbf49972c4a32e156e001bb9dbe Mon Sep 17 00:00:00 2001 From: Runmin Zhang Date: Wed, 27 May 2020 22:13:22 -0400 Subject: [PATCH 1/3] create '.data' automatically --- torchtext/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/torchtext/utils.py b/torchtext/utils.py index 45f242f84b..9ce26b5c56 100644 --- a/torchtext/utils.py +++ b/torchtext/utils.py @@ -78,9 +78,12 @@ def _process_response(r, root, filename): root, filename = os.path.split(path) if not os.path.exists(root): - raise RuntimeError( - "Download directory {} does not exist. " - "Did you create it?".format(root)) + if root == ".data": + os.makedirs(".data") + else: + raise RuntimeError( + "Download directory {} does not exist. " + "Did you create it?".format(root)) if 'drive.google.com' not in url: response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}, stream=True) From 091e26353618cb4f09965462980fbfcc2567c53a Mon Sep 17 00:00:00 2001 From: Runmin Zhang Date: Thu, 28 May 2020 20:27:24 -0400 Subject: [PATCH 2/3] update --- torchtext/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/torchtext/utils.py b/torchtext/utils.py index 9ce26b5c56..d8fe625144 100644 --- a/torchtext/utils.py +++ b/torchtext/utils.py @@ -78,12 +78,11 @@ def _process_response(r, root, filename): root, filename = os.path.split(path) if not os.path.exists(root): - if root == ".data": - os.makedirs(".data") - else: + try: + os.makedirs(root) + except: raise RuntimeError( - "Download directory {} does not exist. " - "Did you create it?".format(root)) + "Can't create the download directory {}.".format(root)) if 'drive.google.com' not in url: response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}, stream=True) From 0900bac831a099d551a16a102d45d999c0a327db Mon Sep 17 00:00:00 2001 From: Runmin Zhang Date: Fri, 29 May 2020 19:22:17 -0400 Subject: [PATCH 3/3] Use the default OSError --- torchtext/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torchtext/utils.py b/torchtext/utils.py index d8fe625144..41ac14ecbb 100644 --- a/torchtext/utils.py +++ b/torchtext/utils.py @@ -80,9 +80,9 @@ def _process_response(r, root, filename): if not os.path.exists(root): try: os.makedirs(root) - except: - raise RuntimeError( - "Can't create the download directory {}.".format(root)) + except OSError: + print("Can't create the download directory {}.".format(root)) + raise if 'drive.google.com' not in url: response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}, stream=True)