Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改为运行时从 json 文件中读取单字和词语拼音数据,缓解 Python 3.12 环境中存在的性能劣化问题 #324

Merged
merged 8 commits into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -38,3 +38,9 @@ jobs:
python -m pip install dist/*.gz
python -m pypinyin test
python -m pypinyin.tools.toneconvert to-tone 'zhong4 xin1'

- name: test import time
if: startsWith(matrix.os,'ubuntu')
run: |
set -xe
time python -c 'from pypinyin import pinyin'
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -4,18 +4,18 @@ repos:
hooks:
- id: check-merge-conflict
- id: debug-statements
exclude: 'tools/|(pypinyin/(phrases_dict.py|pinyin_dict.py|phonetic_symbol.py))'
exclude: 'tools/|(pypinyin/(legacy/|phonetic_symbol.py))'
- id: double-quote-string-fixer
exclude: 'pypinyin/(phrases_dict.py|pinyin_dict.py|phonetic_symbol.py)'
exclude: 'pypinyin/(legacy/|phonetic_symbol.py)'
- id: end-of-file-fixer
exclude: '.bumpversion.cfg'
exclude: '.bumpversion.cfg|.*.json'
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
exclude: 'tools|pypinyin/(phrases_dict.py|pinyin_dict.py|phonetic_symbol.py)|(docs/conf.py)'
exclude: 'tools|pypinyin/(legacy/|phonetic_symbol.py)|(docs/conf.py)'
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: 'v0.812'
# hooks:
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include README.rst LICENSE.txt CHANGELOG.rst
recursive-include pypinyin *.pyi py.typed
recursive-include pypinyin *.pyi py.typed *.json
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -53,12 +53,18 @@ gen_data: sync_submodule gen_pinyin_dict gen_phrases_dict

.PHONY: gen_pinyin_dict
gen_pinyin_dict: sync_submodule
python gen_pinyin_dict.py pinyin-data/pinyin.txt pypinyin/pinyin_dict.py
python gen_pinyin_dict.py pinyin-data/pinyin.txt pypinyin/legacy/pinyin_dict.py
$(MAKE) to_json source=pypinyin/legacy/pinyin_dict.py var=pinyin_dict dst=pypinyin/pinyin_dict.json

.PHONY: gen_phrases_dict
gen_phrases_dict: sync_submodule
python gen_phrases_dict.py phrase-pinyin-data/pinyin.txt pypinyin/phrases_dict_large.py
python tidy_phrases_dict.py
python gen_phrases_dict.py phrase-pinyin-data/pinyin.txt pypinyin/legacy/phrases_dict.py
$(MAKE) to_json source=pypinyin/legacy/phrases_dict.py var=phrases_dict dst=pypinyin/phrases_dict.json


.PHONY: to_json
to_json:
python -c 'import json; exec(open("$(source)").read()); json.dump($(var), open("$(dst)", "w"), ensure_ascii=False, sort_keys=True, indent="")'

.PHONY: sync_submodule
sync_submodule:
Empty file added pypinyin/legacy/__init__.py
Empty file.
47,104 changes: 47,104 additions & 0 deletions pypinyin/legacy/phrases_dict.py

Large diffs are not rendered by default.

8,688 changes: 8,688 additions & 0 deletions pypinyin/legacy/phrases_dict_tidy.py

Large diffs are not rendered by default.

Loading