From ae570e64ecbf404c073cabb38fd73f944445c88b Mon Sep 17 00:00:00 2001 From: Shengjie Xu Date: Mon, 9 Sep 2024 10:12:24 -0400 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3#326=EF=BC=9A=E4=BD=BF=20PyIn?= =?UTF-8?q?staller=20=E5=9C=A8=20Windows=20=E4=B8=8B=E6=97=A0=E9=9C=80?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=8A=A0=20--collect-data=20pypinyin=20?= =?UTF-8?q?=E5=B0=B1=E5=8F=AF=E6=89=93=E5=8C=85=E7=A8=8B=E5=BA=8F=20(#329)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix issue #326: now pypinyin.__pyinstaller contains hooks to collect data files automatically * Ignore pypinyin/__pyinstaller for testing --------- Co-authored-by: Shengjie Xu --- pypinyin/__pyinstaller/__init__.py | 7 +++++++ pypinyin/__pyinstaller/hook-pypinyin.py | 6 ++++++ pytest.ini | 2 +- setup.py | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pypinyin/__pyinstaller/__init__.py create mode 100644 pypinyin/__pyinstaller/hook-pypinyin.py diff --git a/pypinyin/__pyinstaller/__init__.py b/pypinyin/__pyinstaller/__init__.py new file mode 100644 index 0000000..3ae3c37 --- /dev/null +++ b/pypinyin/__pyinstaller/__init__.py @@ -0,0 +1,7 @@ +# reference: https://github.com/pyinstaller/hooksample/blob/master/src/pyi_hooksample/__pyinstaller/__init__.py + +import os + +def get_hook_dirs(): + return [os.path.dirname(__file__)] + diff --git a/pypinyin/__pyinstaller/hook-pypinyin.py b/pypinyin/__pyinstaller/hook-pypinyin.py new file mode 100644 index 0000000..85f909d --- /dev/null +++ b/pypinyin/__pyinstaller/hook-pypinyin.py @@ -0,0 +1,6 @@ +# reference: https://github.com/pyinstaller/hooksample/blob/master/src/pyi_hooksample/__pyinstaller/hook-pyi_hooksample.py + +from PyInstaller.utils.hooks import collect_data_files + +datas = collect_data_files('pypinyin', excludes=['__pyinstaller']) + diff --git a/pytest.ini b/pytest.ini index df24a90..c7b348c 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,4 +3,4 @@ python_files = test_*.py python_classes = Test python_functions = test addopts = -slv --cov-report term-missing --tb=short --durations=10 --doctest-modules -norecursedirs = .git __pycache__ +norecursedirs = .git __pycache__ pypinyin/__pyinstaller diff --git a/setup.py b/setup.py index 780963c..bc37d4f 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ 'pypinyin.seg', 'pypinyin.style', 'pypinyin.tools', + 'pypinyin.__pyinstaller', ] requirements = [] @@ -77,6 +78,9 @@ def long_description(): 'console_scripts': [ 'pypinyin = pypinyin.__main__:main', ], + 'pyinstaller40': [ + 'hook-dirs = pypinyin.__pyinstaller:get_hook_dirs' + ], }, classifiers=[ 'Development Status :: 5 - Production/Stable',