Skip to content

Commit

Permalink
整理: pip ライセンステキストの置換を共通化 (VOICEVOX#1253)
Browse files Browse the repository at this point in the history
* refactor: pip テキストライセンスの置換を共通化

* fix: 属性置き換え関数の出力を None へ変更

* fix: `replace_license_text()` 引数順序を入れ替え

* refactor: 置き換え可能処理を関数で置き換え
  • Loading branch information
tarepan authored May 22, 2024
1 parent cda64cb commit b57be2d
Showing 1 changed file with 44 additions and 63 deletions.
107 changes: 44 additions & 63 deletions build_util/generate_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ def __init__(
# ライセンステキストをローカルのライセンスファイルから抽出する
self.license_text = Path(license_text).read_text(encoding="utf8")
elif license_text_type == "remote_address":
# ライセンステキストをリモートのライセンスファイルから抽出する
with urllib.request.urlopen(license_text) as res:
_license_text: str = res.read().decode()
self.license_text = _license_text
replace_license_text(self, license_text)
else:
raise Exception("型で保護され実行されないはずのパスが実行されました")


def replace_license_text(license: License, text_url: str) -> None:
"""ライセンステキストを URL が指すテキストで置き換える。"""
with urllib.request.urlopen(text_url) as res:
license.license_text = res.read().decode()


def generate_licenses() -> list[License]:
licenses: list[License] = []

Expand Down Expand Up @@ -81,73 +84,51 @@ def generate_licenses() -> list[License]:
raise LicenseError(
f"ライセンス違反: {license.package_name} is {license.license_name}"
)

package_name = license.package_name.lower()

# FIXME: assert license type
if license.license_text == "UNKNOWN":
if (
license.package_name.lower() == "core"
and license.package_version == "0.0.0"
):
if package_name == "core" and license.package_version == "0.0.0":
continue
elif license.package_name.lower() == "future":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/PythonCharmers/python-future/master/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "pefile":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/erocarrera/pefile/master/LICENSE" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "pyopenjtalk":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/LICENSE.md"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "python-multipart":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/andrew-d/python-multipart/master/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "romkan":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/soimort/python-romkan/master/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "distlib":
with urllib.request.urlopen(
"https://bitbucket.org/pypa/distlib/raw/7d93712134b28401407da27382f2b6236c87623a/LICENSE.txt" # noqa: B950
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "jsonschema":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/python-jsonschema/jsonschema/dbc398245a583cb2366795dc529ae042d10c1577/COPYING"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "lockfile":
with urllib.request.urlopen(
"https://opendev.org/openstack/pylockfile/raw/tag/0.12.2/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "platformdirs":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/platformdirs/platformdirs/aa671aaa97913c7b948567f4d9c77d4f98bfa134/LICENSE"
) as res:
license.license_text = res.read().decode()
elif license.package_name.lower() == "webencodings":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/gsnedders/python-webencodings/fa2cb5d75ab41e63ace691bc0825d3432ba7d694/LICENSE"
) as res:
license.license_text = res.read().decode()
elif package_name == "future":
text_url = "https://raw.githubusercontent.com/PythonCharmers/python-future/master/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "pefile":
text_url = "https://raw.githubusercontent.com/erocarrera/pefile/master/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "pyopenjtalk":
text_url = "https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/LICENSE.md" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "python-multipart":
text_url = "https://raw.githubusercontent.com/andrew-d/python-multipart/master/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "romkan":
text_url = "https://raw.githubusercontent.com/soimort/python-romkan/master/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "distlib":
text_url = "https://bitbucket.org/pypa/distlib/raw/7d93712134b28401407da27382f2b6236c87623a/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "jsonschema":
text_url = "https://raw.githubusercontent.com/python-jsonschema/jsonschema/dbc398245a583cb2366795dc529ae042d10c1577/COPYING" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "lockfile":
text_url = "https://opendev.org/openstack/pylockfile/raw/tag/0.12.2/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "platformdirs":
text_url = "https://raw.githubusercontent.com/platformdirs/platformdirs/aa671aaa97913c7b948567f4d9c77d4f98bfa134/LICENSE" # noqa: B950
replace_license_text(license, text_url)
elif package_name == "webencodings":
text_url = "https://raw.githubusercontent.com/gsnedders/python-webencodings/fa2cb5d75ab41e63ace691bc0825d3432ba7d694/LICENSE" # noqa: B950
replace_license_text(license, text_url)
else:
# ライセンスがpypiに無い
raise Exception(f"No License info provided for {license.package_name}")

# soxr
if license.package_name.lower() == "soxr":
with urllib.request.urlopen(
"https://raw.githubusercontent.com/dofuuz/python-soxr/v0.3.6/LICENSE.txt"
) as res:
license.license_text = res.read().decode()
if package_name == "soxr":
text_url = "https://raw.githubusercontent.com/dofuuz/python-soxr/v0.3.6/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)

licenses.append(license)

Expand Down

0 comments on commit b57be2d

Please sign in to comment.