Skip to content

Commit

Permalink
extract->extractall (PaddlePaddle#213)
Browse files Browse the repository at this point in the history
* extract->extractall

* add tests requirements
  • Loading branch information
joey12300 authored Apr 2, 2021
1 parent 8e7d2ed commit d1c11f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion paddlenlp/datasets/experimental/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np

from paddle.dataset.common import md5file
from paddle.utils.download import get_path_from_url
from paddlenlp.utils.downloader import get_path_from_url
from paddlenlp.utils.env import DATA_HOME
from . import DatasetBuilder

Expand Down
10 changes: 3 additions & 7 deletions paddlenlp/utils/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,27 +293,23 @@ def _uncompress_file_zip(filepath):
def _uncompress_file_tar(filepath, mode="r:*"):
files = tarfile.open(filepath, mode)
file_list = files.getnames()

file_dir = os.path.dirname(filepath)

if _is_a_single_file(file_list):
rootpath = file_list[0]
uncompressed_path = os.path.join(file_dir, rootpath)
for item in file_list:
files.extract(item, file_dir)
files.extractall(file_dir, files.getmembers())
elif _is_a_single_dir(file_list):
rootpath = os.path.splitext(file_list[0])[0].split(os.sep)[-1]
uncompressed_path = os.path.join(file_dir, rootpath)
for item in file_list:
files.extract(item, file_dir)
files.extractall(file_dir, files.getmembers())
else:
rootpath = os.path.splitext(filepath)[0].split(os.sep)[-1]
uncompressed_path = os.path.join(file_dir, rootpath)
if not os.path.exists(uncompressed_path):
os.makedirs(uncompressed_path)

for item in file_list:
files.extract(item, os.path.join(file_dir, rootpath))
files.extractall(os.path.join(file_dir, rootpath), files.getmembers())

files.close()

Expand Down
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sentencepiece
regex

0 comments on commit d1c11f3

Please sign in to comment.