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

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5 

6from django.conf import settings 

7 

8from weblate.utils.licensedata import LICENSES 

9 

10ALL_LICENSES = (*LICENSES, *settings.LICENSE_EXTRA) 

11 

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} 

15 

16 

17def is_libre(name: str) -> bool: 

18 return name in LIBRE_IDS 

19 

20 

21def get_license_url(name: str) -> str | None: 

22 return LICENSE_URLS.get(name) 

23 

24 

25def get_license_name(name: str) -> str: 

26 return LICENSE_NAMES.get(name, name) 

27 

28 

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 = [] 

35 

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 ) 

41 

42 result.extend( 

43 (name, verbose) for name, verbose, _url, _is_libre in settings.LICENSE_EXTRA 

44 ) 

45 

46 return result