diff --git a/build_util/generate_licenses.py b/build_util/generate_licenses.py index ff49cbcb0..6ee30aa14 100644 --- a/build_util/generate_licenses.py +++ b/build_util/generate_licenses.py @@ -14,26 +14,26 @@ class LicenseError(Exception): class License: def __init__( self, - name: str, # TODO: `package_name` へリネーム - version: str | None, # TODO: `package_version` へリネーム - license: str | None, # TODO: `license_name` へリネーム - text: str, # TODO: `license_text` へリネーム + package_name: str, + package_version: str | None, + license_name: str | None, + license_text: str, license_text_type: Literal["raw", "local_address", "remote_address"], ): - self.name = name # TODO: `package_name` へリネーム - self.version = version # TODO: `package_version` へリネーム - self.license = license # TODO: `license_name` へリネーム + self.package_name = package_name + self.package_version = package_version + self.license_name = license_name if license_text_type == "raw": - self.text = text # TODO: `license_text` へリネーム + self.license_text = license_text elif license_text_type == "local_address": # ライセンステキストをローカルのライセンスファイルから抽出する - self.text = Path(text).read_text(encoding="utf8") + self.license_text = Path(license_text).read_text(encoding="utf8") elif license_text_type == "remote_address": # ライセンステキストをリモートのライセンスファイルから抽出する - with urllib.request.urlopen(text) as res: - license_text: str = res.read().decode() - self.text = license_text + with urllib.request.urlopen(license_text) as res: + _license_text: str = res.read().decode() + self.license_text = _license_text else: raise Exception("型で保護され実行されないはずのパスが実行されました") @@ -63,13 +63,13 @@ def generate_licenses() -> list[License]: licenses_json = json.loads(pip_licenses_output) for license_json in licenses_json: license = License( - name=license_json["Name"], - version=license_json["Version"], - license=license_json["License"], - text=license_json["LicenseText"], + 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 or "" + license_names_str = license.license_name or "" license_names = license_names_str.split("; ") for license_name in license_names: if license_name in [ @@ -79,72 +79,75 @@ def generate_licenses() -> list[License]: "GNU Affero General Public License v3 (AGPL-3)", ]: raise LicenseError( - f"ライセンス違反: {license.name} is {license.license}" + f"ライセンス違反: {license.package_name} is {license.license_name}" ) # FIXME: assert license type - if license.text == "UNKNOWN": - if license.name.lower() == "core" and license.version == "0.0.0": + if license.license_text == "UNKNOWN": + if ( + license.package_name.lower() == "core" + and license.package_version == "0.0.0" + ): continue - elif license.name.lower() == "future": + 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.text = res.read().decode() - elif license.name.lower() == "pefile": + 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.text = res.read().decode() - elif license.name.lower() == "pyopenjtalk": + 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.text = res.read().decode() - elif license.name.lower() == "python-multipart": + 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.text = res.read().decode() - elif license.name.lower() == "romkan": + 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.text = res.read().decode() - elif license.name.lower() == "distlib": + 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.text = res.read().decode() - elif license.name.lower() == "jsonschema": + 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.text = res.read().decode() - elif license.name.lower() == "lockfile": + 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.text = res.read().decode() - elif license.name.lower() == "platformdirs": + 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.text = res.read().decode() - elif license.name.lower() == "webencodings": + 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.text = res.read().decode() + license.license_text = res.read().decode() else: # ライセンスがpypiに無い - raise Exception(f"No License info provided for {license.name}") + raise Exception(f"No License info provided for {license.package_name}") # soxr - if license.name.lower() == "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.text = res.read().decode() + license.license_text = res.read().decode() licenses.append(license) @@ -153,135 +156,135 @@ def generate_licenses() -> list[License]: licenses += [ # https://sourceforge.net/projects/open-jtalk/files/Open%20JTalk/open_jtalk-1.11/ License( - name="Open JTalk", - version="1.11", - license="Modified BSD license", - text="docs/licenses/open_jtalk/COPYING", + package_name="Open JTalk", + package_version="1.11", + license_name="Modified BSD license", + license_text="docs/licenses/open_jtalk/COPYING", license_text_type="local_address", ), License( - name="MeCab", - version=None, - license="Modified BSD license", - text="docs/licenses/open_jtalk/mecab/COPYING", + package_name="MeCab", + package_version=None, + license_name="Modified BSD license", + license_text="docs/licenses/open_jtalk/mecab/COPYING", license_text_type="local_address", ), License( - name="NAIST Japanese Dictionary", - version=None, - license="Modified BSD license", - text="docs/licenses//open_jtalk/mecab-naist-jdic/COPYING", + package_name="NAIST Japanese Dictionary", + package_version=None, + license_name="Modified BSD license", + license_text="docs/licenses//open_jtalk/mecab-naist-jdic/COPYING", license_text_type="local_address", ), License( - name='HTS Voice "Mei"', - version=None, - license="Creative Commons Attribution 3.0 license", - text="https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/pyopenjtalk/htsvoice/LICENSE_mei_normal.htsvoice", # noqa: B950 + package_name='HTS Voice "Mei"', + package_version=None, + license_name="Creative Commons Attribution 3.0 license", + license_text="https://raw.githubusercontent.com/r9y9/pyopenjtalk/master/pyopenjtalk/htsvoice/LICENSE_mei_normal.htsvoice", # noqa: B950 license_text_type="remote_address", ), License( - name="VOICEVOX CORE", - version=None, - license="MIT license", - text="https://raw.githubusercontent.com/VOICEVOX/voicevox_core/main/LICENSE", + package_name="VOICEVOX CORE", + package_version=None, + license_name="MIT license", + license_text="https://raw.githubusercontent.com/VOICEVOX/voicevox_core/main/LICENSE", license_text_type="remote_address", ), License( - name="VOICEVOX ENGINE", - version=None, - license="LGPL license", - text="https://raw.githubusercontent.com/VOICEVOX/voicevox_engine/master/LGPL_LICENSE", + package_name="VOICEVOX ENGINE", + package_version=None, + license_name="LGPL license", + license_text="https://raw.githubusercontent.com/VOICEVOX/voicevox_engine/master/LGPL_LICENSE", license_text_type="remote_address", ), License( - name="world", - version=None, - license="Modified BSD license", - text="https://raw.githubusercontent.com/mmorise/World/master/LICENSE.txt", + package_name="world", + package_version=None, + license_name="Modified BSD license", + license_text="https://raw.githubusercontent.com/mmorise/World/master/LICENSE.txt", license_text_type="remote_address", ), License( - name="PyTorch", - version="1.9.0", - license="BSD-style license", - text="https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE", + package_name="PyTorch", + package_version="1.9.0", + license_name="BSD-style license", + license_text="https://raw.githubusercontent.com/pytorch/pytorch/master/LICENSE", license_text_type="remote_address", ), License( - name="ONNX Runtime", - version="1.13.1", - license="MIT license", - text="https://raw.githubusercontent.com/microsoft/onnxruntime/master/LICENSE", + package_name="ONNX Runtime", + package_version="1.13.1", + license_name="MIT license", + license_text="https://raw.githubusercontent.com/microsoft/onnxruntime/master/LICENSE", license_text_type="remote_address", ), License( - name="Python", - version=python_version, - license="Python Software Foundation License", - text=f"https://raw.githubusercontent.com/python/cpython/v{python_version}/LICENSE", + package_name="Python", + package_version=python_version, + license_name="Python Software Foundation License", + license_text=f"https://raw.githubusercontent.com/python/cpython/v{python_version}/LICENSE", license_text_type="remote_address", ), # OpenBLAS License( - name="OpenBLAS", - version=None, - license="BSD 3-clause license", - text="https://raw.githubusercontent.com/xianyi/OpenBLAS/develop/LICENSE", + package_name="OpenBLAS", + package_version=None, + license_name="BSD 3-clause license", + license_text="https://raw.githubusercontent.com/xianyi/OpenBLAS/develop/LICENSE", license_text_type="remote_address", ), License( - name="libsndfile-binaries", - version="1.2.0", - license="LGPL-2.1 license", - text="https://raw.githubusercontent.com/bastibe/libsndfile-binaries/d9887ef926bb11cf1a2526be4ab6f9dc690234c0/COPYING", # noqa: B950 + package_name="libsndfile-binaries", + package_version="1.2.0", + license_name="LGPL-2.1 license", + license_text="https://raw.githubusercontent.com/bastibe/libsndfile-binaries/d9887ef926bb11cf1a2526be4ab6f9dc690234c0/COPYING", # noqa: B950 license_text_type="remote_address", ), License( - name="libogg", - version="1.3.5", - license="BSD 3-clause license", - text="https://raw.githubusercontent.com/xiph/ogg/v1.3.5/COPYING", + package_name="libogg", + package_version="1.3.5", + license_name="BSD 3-clause license", + license_text="https://raw.githubusercontent.com/xiph/ogg/v1.3.5/COPYING", license_text_type="remote_address", ), License( - name="libvorbis", - version="1.3.7", - license="BSD 3-clause license", - text="https://raw.githubusercontent.com/xiph/vorbis/v1.3.7/COPYING", + package_name="libvorbis", + package_version="1.3.7", + license_name="BSD 3-clause license", + license_text="https://raw.githubusercontent.com/xiph/vorbis/v1.3.7/COPYING", license_text_type="remote_address", ), # libflac License( - name="FLAC", - version="1.4.2", - license="Xiph.org's BSD-like license", - text="https://raw.githubusercontent.com/xiph/flac/1.4.2/COPYING.Xiph", + package_name="FLAC", + package_version="1.4.2", + license_name="Xiph.org's BSD-like license", + license_text="https://raw.githubusercontent.com/xiph/flac/1.4.2/COPYING.Xiph", license_text_type="remote_address", ), # libopus License( - name="Opus", - version="1.3.1", - license="BSD 3-clause license", - text="https://raw.githubusercontent.com/xiph/opus/v1.3.1/COPYING", + package_name="Opus", + package_version="1.3.1", + license_name="BSD 3-clause license", + license_text="https://raw.githubusercontent.com/xiph/opus/v1.3.1/COPYING", license_text_type="remote_address", ), # https://sourceforge.net/projects/mpg123/files/mpg123/1.30.2/ License( - name="mpg123", - version="1.30.2", - license="LGPL-2.1 license", - text="docs/licenses/mpg123/COPYING", + package_name="mpg123", + package_version="1.30.2", + license_name="LGPL-2.1 license", + license_text="docs/licenses/mpg123/COPYING", license_text_type="local_address", ), # liblame # https://sourceforge.net/projects/lame/files/lame/3.100/ License( - name="lame", - version="3.100", - license="LGPL-2.0 license", - text="https://svn.code.sf.net/p/lame/svn/tags/RELEASE__3_100/lame/COPYING", + package_name="lame", + package_version="3.100", + license_name="LGPL-2.0 license", + license_text="https://svn.code.sf.net/p/lame/svn/tags/RELEASE__3_100/lame/COPYING", license_text_type="remote_address", ), # license text from CUDA 11.8.0 @@ -289,10 +292,10 @@ def generate_licenses() -> list[License]: # https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_522.06_windows.exe # noqa: B950 # cuda_11.8.0_522.06_windows.exe (cuda_documentation/Doc/EULA.txt) License( - name="CUDA Toolkit", - version="11.8.0", - license=None, - text="docs/licenses/cuda/EULA.txt", + package_name="CUDA Toolkit", + package_version="11.8.0", + license_name=None, + license_text="docs/licenses/cuda/EULA.txt", license_text_type="local_address", ), # license text from cuDNN v8.9.2 (June 1st, 2023), for CUDA 11.x, cuDNN Library for Windows # noqa: B950 @@ -300,10 +303,10 @@ def generate_licenses() -> list[License]: # https://developer.download.nvidia.com/compute/cudnn/redist/cudnn/windows-x86_64/cudnn-windows-x86_64-8.9.2.26_cuda11-archive.zip # noqa: B950 # cudnn-windows-x86_64-8.9.2.26_cuda11-archive.zip (cudnn-windows-x86_64-8.9.2.26_cuda11-archive/LICENSE) # noqa: B950 License( - name="cuDNN", - version="8.9.2", - license=None, - text="docs/licenses/cudnn/LICENSE", + package_name="cuDNN", + package_version="8.9.2", + license_name=None, + license_text="docs/licenses/cudnn/LICENSE", license_text_type="local_address", ), ] @@ -328,10 +331,10 @@ def generate_licenses() -> list[License]: json.dump( [ { - "name": license.name, - "version": license.version, - "license": license.license, - "text": license.text, + "name": license.package_name, + "version": license.package_version, + "license": license.license_name, + "text": license.license_text, } for license in licenses ],