Skip to content

Commit

Permalink
解决#326:使 PyInstaller 在 Windows 下无需手动加 --collect-data pypinyin 就可打包程序 (#…
Browse files Browse the repository at this point in the history
…329)

* Fix issue #326: now pypinyin.__pyinstaller contains hooks to collect data files automatically

* Ignore pypinyin/__pyinstaller for testing

---------

Co-authored-by: Shengjie Xu <[email protected]>
  • Loading branch information
xushengj and Shengjie Xu authored Sep 9, 2024
1 parent 0110225 commit ae570e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pypinyin/__pyinstaller/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)]

6 changes: 6 additions & 0 deletions pypinyin/__pyinstaller/hook-pypinyin.py
Original file line number Diff line number Diff line change
@@ -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'])

2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'pypinyin.seg',
'pypinyin.style',
'pypinyin.tools',
'pypinyin.__pyinstaller',
]

requirements = []
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit ae570e6

Please sign in to comment.