Skip to content

Commit

Permalink
add download flag
Browse files Browse the repository at this point in the history
  • Loading branch information
synodriver committed Aug 12, 2022
1 parent adec254 commit a9873b8
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import sys
import platform
import shutil
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
from distutils.version import LooseVersion
Expand All @@ -16,7 +17,6 @@
from setuptools import Extension, find_packages, setup

import six
from tqdm.auto import tqdm
if six.PY2:
from urllib import urlretrieve
else:
Expand Down Expand Up @@ -171,31 +171,20 @@ def escape_macros(macros):
src_top = join("lib", "open_jtalk", "src")


# https://github.com/tqdm/tqdm#hooks-and-callbacks
class _TqdmUpTo(tqdm): # type: ignore
def update_to(self, b=1, bsize=1, tsize=None):
if tsize is not None:
self.total = tsize
return self.update(b * bsize - self.n)


# extract dic
filename = "dic.tar.gz"
print('Downloading: "{}"'.format(_DICT_URL))
with _TqdmUpTo(
unit="B",
unit_scale=True,
unit_divisor=1024,
miniters=1,
desc="dic.tar.gz",
) as t: # all optional kwargs
urlretrieve(_DICT_URL, filename, reporthook=t.update_to)
t.total = t.n
print(f"Downloading: {_DICT_URL}")
urlretrieve(_DICT_URL, filename)
print("Download complete")

print("Extracting tar file {}".format(filename))
with tarfile.open(filename, mode="r|gz") as f:
f.extractall(path="./")
os.remove(filename)

print("Extract complete")
shutil.copytree(f"./{_dict_folder_name}", f"./pyopenjtalk/{_dict_folder_name}")
sys.stdout.flush()

# generate config.h for mecab
# NOTE: need to run cmake to generate config.h
Expand Down

0 comments on commit a9873b8

Please sign in to comment.