Skip to content

Commit

Permalink
Merge 40d62f8 into 3d8b1e4
Browse files Browse the repository at this point in the history
  • Loading branch information
tarepan authored May 22, 2024
2 parents 3d8b1e4 + 40d62f8 commit 8dd02fb
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions build_util/generate_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def __init__(
# ライセンステキストをローカルのライセンスファイルから抽出する
self.license_text = Path(license_text).read_text(encoding="utf8")
elif license_text_type == "remote_address":
replace_license_text(self, license_text)
self.license_text = get_license_text(license_text)
else:
raise Exception("型で保護され実行されないはずのパスが実行されました")


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


def generate_licenses() -> list[License]:
Expand All @@ -65,70 +65,70 @@ def generate_licenses() -> list[License]:

licenses_json = json.loads(pip_licenses_output)
for license_json in licenses_json:
license = License(
package_name=license_json["Name"],
package_version=license_json["Version"],
license_name=license_json["License"],
license_text=license_json["LicenseText"],
license_text_type="raw",
)
license_names_str = license.license_name or ""
license_names = license_names_str.split("; ")
for license_name in license_names:
if license_name in [
"GNU General Public License v2 (GPLv2)",
"GNU General Public License (GPL)",
"GNU General Public License v3 (GPLv3)",
"GNU Affero General Public License v3 (AGPL-3)",
]:
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 package_name == "core" and license.package_version == "0.0.0":
# ライセンス文を pip 外で取得されたもので上書きする
package_name: str = license_json["Name"].lower()
if license_json["LicenseText"] == "UNKNOWN":
if package_name == "core" and license_json["Version"] == "0.0.0":
continue
elif package_name == "future":
text_url = "https://raw.githubusercontent.com/PythonCharmers/python-future/master/LICENSE.txt" # noqa: B950
replace_license_text(license, text_url)
license_json["LicenseText"] = get_license_text(text_url)
elif package_name == "pefile":
text_url = "https://raw.githubusercontent.com/erocarrera/pefile/master/LICENSE" # noqa: B950
replace_license_text(license, text_url)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(text_url)
elif package_name == "platformdirs":
text_url = "https://raw.githubusercontent.com/platformdirs/platformdirs/aa671aaa97913c7b948567f4d9c77d4f98bfa134/LICENSE" # noqa: B950
replace_license_text(license, text_url)
license_json["LicenseText"] = get_license_text(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)
license_json["LicenseText"] = get_license_text(text_url)
else:
# ライセンスがpypiに無い
raise Exception(f"No License info provided for {license.package_name}")

raise Exception(f"No License info provided for {package_name}")
# soxr
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)
license_json["LicenseText"] = get_license_text(text_url)

license = License(
package_name=license_json["Name"],
package_version=license_json["Version"],
license_name=license_json["License"],
license_text=license_json["LicenseText"],
license_text_type="raw",
)

# ライセンスを確認する
license_names_str = license.license_name or ""
license_names = license_names_str.split("; ")
for license_name in license_names:
if license_name in [
"GNU General Public License v2 (GPLv2)",
"GNU General Public License (GPL)",
"GNU General Public License v3 (GPLv3)",
"GNU Affero General Public License v3 (AGPL-3)",
]:
raise LicenseError(
f"ライセンス違反: {license.package_name} is {license.license_name}"
)

licenses.append(license)

Expand Down

0 comments on commit 8dd02fb

Please sign in to comment.