Repository: nltk/nltk

Issue:
Downloader fails when download_dir is a nested folder that doesn't exist
### Problem
When the download folder doesn't exist, it is created by the downloader. But when that folder is nested, the creation fails.

### Code example

```python
nltk.download("punkt", force=True, download_dir="some/nested/folder")
```

Will give the following error:

```
File "my_env/lib/python3.7/site-packages/nltk/downloader.py", line 776, in download
    for msg in self.incr_download(info_or_id, download_dir, force):
  File "my_env/lib/python3.7/site-packages/nltk/downloader.py", line 641, in incr_download
    yield from self._download_package(info, download_dir, force)
  File "my_env/lib/python3.7/site-packages/nltk/downloader.py", line 698, in _download_package
    os.mkdir(download_dir)
FileNotFoundError: [Errno 2] No such file or directory: 'some/nested/folder'
```

### Suggested solution

The following line throws the error: https://github.com/nltk/nltk/blob/develop/nltk/downloader.py#L698

`os.makedirs(download_dir)` could be used instead of `os.mkdir(download_dir)`



Discussion:
iliakur: I wonder how easy it would be to add tests for this... pytest has some fixtures to create temporary directories.

Patch:
diff --git a/AUTHORS.md b/AUTHORS.md
index 04592e11c..8c7345577 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -286,6 +286,7 @@
 - Ahmet Yildirim <https://github.com/RnDevelover>
 - Yuta Nakamura <https://github.com/yutanakamura-tky>
 - Adam Hawley <https://github.com/adamjhawley>
+- Panagiotis Simakis <https://github.com/sp1thas>
 
 ## Others whose work we've taken and included in NLTK, but who didn't directly contribute it:
 
diff --git a/nltk/downloader.py b/nltk/downloader.py
index e513435a5..78b0d0ee0 100644
--- a/nltk/downloader.py
+++ b/nltk/downloader.py
@@ -695,9 +695,9 @@ class Downloader:
 
         # Ensure the download_dir exists
         if not os.path.exists(download_dir):
-            os.mkdir(download_dir)
+            os.makedirs(download_dir)
         if not os.path.exists(os.path.join(download_dir, info.subdir)):
-            os.mkdir(os.path.join(download_dir, info.subdir))
+            os.makedirs(os.path.join(download_dir, info.subdir))
 
         # Download the file.  This will raise an IOError if the url
         # is not found.


Test patch:
diff --git a/nltk/test/unit/test_downloader.py b/nltk/test/unit/test_downloader.py
new file mode 100644
index 000000000..036b56bb4
--- /dev/null
+++ b/nltk/test/unit/test_downloader.py
@@ -0,0 +1,19 @@
+from nltk import download
+
+
+def test_downloader_using_existing_parent_download_dir(tmp_path):
+    """Test that download works properly when the parent folder of the download_dir exists"""
+
+    download_dir = str(tmp_path.joinpath("another_dir"))
+    download_status = download("mwa_ppdb", download_dir)
+    assert download_status is True
+
+
+def test_downloader_using_non_existing_parent_download_dir(tmp_path):
+    """Test that download works properly when the parent folder of the download_dir does not exist"""
+
+    download_dir = str(
+        tmp_path.joinpath("non-existing-parent-folder", "another-non-existing-folder")
+    )
+    download_status = download("mwa_ppdb", download_dir)
+    assert download_status is True