Coverage for app/venv/lib/python3.14/site-packages/weblate/utils/licenses.py: 82%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
6from django.conf import settings
8from weblate.utils.licensedata import LICENSES
10ALL_LICENSES = (*LICENSES, *settings.LICENSE_EXTRA)
12LIBRE_IDS = {name for name, _verbose, _url, is_libre in ALL_LICENSES if is_libre}
13LICENSE_URLS = {name: url for name, _verbose, url, _is_libre in ALL_LICENSES}
14LICENSE_NAMES = {name: verbose for name, verbose, _url, _is_libre in ALL_LICENSES}
17def is_libre(name: str) -> bool:
18 return name in LIBRE_IDS
21def get_license_url(name: str) -> str | None:
22 return LICENSE_URLS.get(name)
25def get_license_name(name: str) -> str:
26 return LICENSE_NAMES.get(name, name)
29def get_license_choices() -> list[tuple[str, str]]:
30 license_filter = settings.LICENSE_FILTER
31 if license_filter is None or "proprietary" in license_filter: 31 ↛ 34line 31 didn't jump to line 34 because the condition on line 31 was always true
32 result = [("proprietary", "Proprietary")]
33 else:
34 result = []
36 result.extend(
37 (name, verbose)
38 for name, verbose, _url, _is_libre in LICENSES
39 if license_filter is None or name in license_filter
40 )
42 result.extend(
43 (name, verbose) for name, verbose, _url, _is_libre in settings.LICENSE_EXTRA
44 )
46 return result