From 5af6b9d859800f5efe55c468b1967a533bc64d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:41:04 +0800 Subject: [PATCH 1/2] feat: add dict in setup time --- setup.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c68db9c..b7f8feb 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,10 @@ "/execution-charset:utf-8", ] +_dict_folder_name = "open_jtalk_dic_utf_8-1.11" +_dict_download_url = "https://github.com/r9y9/open_jtalk/releases/download/v1.11.1" +_DICT_URL = f"{_dict_download_url}/{_dict_folder_name}.tar.gz" + try: if not _CYTHON_INSTALLED: raise ImportError("No supported version of Cython installed.") @@ -138,6 +142,33 @@ def escape_macros(macros): # open_jtalk sources 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("Extracting tar file {}".format(filename)) +with tarfile.open(filename, mode="r|gz") as f: + f.extractall(path="./") +os.remove(filename) + + # generate config.h for mecab # NOTE: need to run cmake to generate config.h # we could do it on python side but it would be very tricky, @@ -272,7 +303,7 @@ def run(self): url="https://github.com/r9y9/pyopenjtalk", license="MIT", packages=find_packages(), - package_data={"": ["htsvoice/*"]}, + package_data={"": ["htsvoice/*", f"{_dict_folder_name}/*"]}, ext_modules=ext_modules, cmdclass=cmdclass, install_requires=[ From 23641047b3321fc0dac2f8e21446291391555f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:45:38 +0800 Subject: [PATCH 2/2] add imports --- setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.py b/setup.py index b7f8feb..ba0e767 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,15 @@ import setuptools.command.develop from setuptools import Extension, find_packages, setup +import six +from tqdm.auto import tqdm +if six.PY2: + from urllib import urlretrieve +else: + from urllib.request import urlretrieve +import tarfile + + platform_is_windows = sys.platform == "win32" version = "0.3.0"