44このスクリプトを実行する前に、必ず scripts/merge_vvm.py を実行してVVMファイルを結合してください。
55"""
66
7+ import argparse
78import json
89import re
910import zipfile
1314from urllib import request
1415
1516
17+ @dataclass
18+ class Args :
19+ voicevox_resource_ref : str
20+ voicevox_nemo_resource_ref : str
21+
22+
1623@dataclass
1724class Terms :
1825 markdown : str
@@ -31,7 +38,9 @@ class StyleEntry:
3138
3239
3340def main ():
34- terms = fetch_and_generate_terms ()
41+ refs = parse_args ()
42+
43+ terms = fetch_and_generate_terms (refs )
3544
3645 vvm_files = get_vvm_files ()
3746 assert len (vvm_files ) > 0 , "VVMが見つかりませんでした。"
@@ -46,22 +55,51 @@ def main():
4655 print (f"{ terms_path } has been updated!" )
4756
4857
49- def fetch_and_generate_terms () -> Terms :
58+ def parse_args () -> Args :
59+ """コマンドライン引数をパース"""
60+ env = load_env ()
61+
62+ parser = argparse .ArgumentParser (
63+ description = "VVM関連の利用規約とドキュメントを更新する"
64+ )
65+ parser .add_argument (
66+ "--voicevox-resource-ref" ,
67+ default = env ["VOICEVOX_RESOURCE_VERSION" ],
68+ help = f"voicevox_resourceのタグ名またはブランチ名(デフォルト: { env ['VOICEVOX_RESOURCE_VERSION' ]} )" ,
69+ )
70+ parser .add_argument (
71+ "--voicevox-nemo-resource-ref" ,
72+ default = env ["VOICEVOX_NEMO_RESOURCE_VERSION" ],
73+ help = f"voicevox_nemo_resourceのタグ名またはブランチ名(デフォルト: { env ['VOICEVOX_NEMO_RESOURCE_VERSION' ]} )" ,
74+ )
75+ args = parser .parse_args ()
76+ return Args (
77+ voicevox_resource_ref = args .voicevox_resource_ref ,
78+ voicevox_nemo_resource_ref = args .voicevox_nemo_resource_ref ,
79+ )
80+
81+
82+ def load_env () -> dict [str , str ]:
83+ """env.jsonから環境変数を読み込む"""
84+ ENV_JSON_PATH = Path (__file__ ).parent .parent / "env.json"
85+ with open (ENV_JSON_PATH , encoding = "utf-8" ) as f :
86+ return json .load (f )
87+
88+
89+ def fetch_and_generate_terms (refs : Args ) -> Terms :
5090 """VOICEVOXとVOICEVOX Nemoの利用規約を取得し、利用規約を生成"""
51- voicevox_terms = fetch_voicevox_terms ()
52- nemo_terms = fetch_and_extract_nemo_terms ()
91+ voicevox_terms = fetch_voicevox_terms (refs . voicevox_resource_ref )
92+ nemo_terms = fetch_and_extract_nemo_terms (refs . voicevox_nemo_resource_ref )
5393
5494 combined_markdown = voicevox_terms .markdown .rstrip () + "\n \n " + nemo_terms .markdown
5595 combined_text = voicevox_terms .text .rstrip () + "\n \n " + nemo_terms .text
5696
5797 return Terms (markdown = combined_markdown , text = combined_text )
5898
5999
60- def fetch_voicevox_terms () -> Terms :
100+ def fetch_voicevox_terms (ref : str ) -> Terms :
61101 """VOICEVOXのリポジトリから利用規約を取得"""
62- base_url = (
63- "https://raw.githubusercontent.com/VOICEVOX/voicevox_resource/refs/heads/main/"
64- )
102+ base_url = f"https://raw.githubusercontent.com/VOICEVOX/voicevox_resource/{ ref } /"
65103
66104 markdown_url = base_url + "vvm/README.md"
67105 with request .urlopen (markdown_url ) as response :
@@ -74,11 +112,10 @@ def fetch_voicevox_terms() -> Terms:
74112 return Terms (markdown = markdown , text = text )
75113
76114
77- def fetch_and_extract_nemo_terms () -> Terms :
115+ def fetch_and_extract_nemo_terms (ref : str ) -> Terms :
78116 """VOICEVOX Nemoの音声ライブラリ利用規約部分を抽出"""
79117 base_url = (
80- "https://raw.githubusercontent.com/VOICEVOX/voicevox_nemo_resource/"
81- "refs/heads/main/"
118+ f"https://raw.githubusercontent.com/VOICEVOX/voicevox_nemo_resource/{ ref } /"
82119 )
83120
84121 markdown_url = base_url + "voicevox_nemo/vvm/README.md"
0 commit comments