fosslight-util 2.2.24__tar.gz → 2.2.26__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {fosslight_util-2.2.24/src/fosslight_util.egg-info → fosslight_util-2.2.26}/PKG-INFO +1 -1
  2. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/pyproject.toml +1 -1
  3. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/_get_downloadable_url.py +72 -67
  4. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/download.py +4 -0
  5. {fosslight_util-2.2.24 → fosslight_util-2.2.26/src/fosslight_util.egg-info}/PKG-INFO +1 -1
  6. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util.egg-info/SOURCES.txt +1 -0
  7. fosslight_util-2.2.26/tests/test_download_pypi.py +102 -0
  8. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_version_hint.py +2 -0
  9. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/LICENSE +0 -0
  10. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/MANIFEST.in +0 -0
  11. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/README.md +0 -0
  12. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/setup.cfg +0 -0
  13. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/__init__.py +0 -0
  14. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/compare_yaml.py +0 -0
  15. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/constant.py +0 -0
  16. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/correct.py +0 -0
  17. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/cover.py +0 -0
  18. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/exclude.py +0 -0
  19. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/get_pom_license.py +0 -0
  20. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/help.py +0 -0
  21. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/merge.py +0 -0
  22. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/oss_item.py +0 -0
  23. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/output_format.py +0 -0
  24. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/parsing_yaml.py +0 -0
  25. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/read_excel.py +0 -0
  26. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  27. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  28. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/resources/licenses.json +0 -0
  29. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/set_log.py +0 -0
  30. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/spdx_licenses.py +0 -0
  31. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/time.py +0 -0
  32. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/timer_thread.py +0 -0
  33. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_cyclonedx.py +0 -0
  34. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_excel.py +0 -0
  35. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_opossum.py +0 -0
  36. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_scancodejson.py +0 -0
  37. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_spdx.py +0 -0
  38. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_txt.py +0 -0
  39. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util/write_yaml.py +0 -0
  40. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  41. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  42. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util.egg-info/requires.txt +0 -0
  43. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/src/fosslight_util.egg-info/top_level.txt +0 -0
  44. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_chromium_gitiles.py +0 -0
  45. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_cyclonedx.py +0 -0
  46. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_decide_checkout.py +0 -0
  47. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download.py +0 -0
  48. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_maven.py +0 -0
  49. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_packagist.py +0 -0
  50. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_timeout.py +0 -0
  51. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_user_agent.py +0 -0
  52. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_download_version_attempts.py +0 -0
  53. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_opossum.py +0 -0
  54. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_spdx.py +0 -0
  55. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_spdx_licenses.py +0 -0
  56. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_text.py +0 -0
  57. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_write_excel_hidden_sheet.py +0 -0
  58. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_write_output.py +0 -0
  59. {fosslight_util-2.2.24 → fosslight_util-2.2.26}/tests/test_write_yaml.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.24
3
+ Version: 2.2.26
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "fosslight_util"
10
- version = "2.2.24"
10
+ version = "2.2.26"
11
11
  description = "FOSSLight Util"
12
12
  readme = "README.md"
13
13
  license = "Apache-2.0"
@@ -8,6 +8,7 @@ import requests
8
8
  import xml.etree.ElementTree as ET
9
9
  from lastversion import latest
10
10
  from bs4 import BeautifulSoup
11
+ from urllib.parse import quote, unquote
11
12
  from urllib.request import urlopen
12
13
  import fosslight_util.constant as constant
13
14
 
@@ -952,87 +953,91 @@ def get_download_location_for_go(link):
952
953
  return ret, new_link
953
954
 
954
955
 
955
- def get_available_wheel_urls(name, version):
956
- try:
957
- api_url = f'https://pypi.org/pypi/{name}/{version}/json'
958
- response = requests.get(api_url, timeout=_HTTP_TIMEOUT)
959
- if response.status_code == 200:
960
- data = response.json()
961
- wheel_urls = []
956
+ def _pypi_api_path(value):
957
+ """Encode one PyPI JSON path segment without changing '.' or '-'."""
958
+ return quote(value or "", safe=".-_")
962
959
 
963
- for file_info in data.get('urls', []):
964
- if file_info.get('packagetype') == 'bdist_wheel':
965
- wheel_urls.append(file_info.get('url'))
966
960
 
967
- return wheel_urls
968
- else:
969
- logger.warning(f'Cannot get PyPI API data for {name}({version})')
970
- return []
961
+ def _pypi_release_files(name, version):
962
+ """Return the ``urls`` list from the PyPI JSON API for one release."""
963
+ api_url = (
964
+ f"https://pypi.org/pypi/{_pypi_api_path(name)}/{_pypi_api_path(version)}/json"
965
+ )
966
+ response = requests.get(api_url, timeout=_HTTP_TIMEOUT)
967
+ if response.status_code != 200:
968
+ logger.warning(f'Cannot get PyPI API data for {name}({version})')
969
+ return []
970
+ files = response.json().get('urls') or []
971
+ return [item for item in files if isinstance(item, dict)]
972
+
973
+
974
+ def _pypi_file_rank(file_info, suffixes):
975
+ filename = (file_info.get('filename') or file_info.get('url') or '').lower()
976
+ for index, suffix in enumerate(suffixes):
977
+ if filename.endswith(suffix):
978
+ return index
979
+ return len(suffixes)
980
+
981
+
982
+ def _select_pypi_download_url(files):
983
+ """Prefer an sdist URL from the JSON file list, then a wheel."""
984
+ sdists = [
985
+ item for item in files
986
+ if item.get('packagetype') == 'sdist' and item.get('url')
987
+ ]
988
+ if sdists:
989
+ chosen = sorted(sdists, key=lambda item: _pypi_file_rank(item, ('.tar.gz', '.tgz', '.zip')))[0]
990
+ return chosen.get('url'), False
991
+
992
+ wheels = [
993
+ item for item in files
994
+ if item.get('packagetype') == 'bdist_wheel' and item.get('url')
995
+ ]
996
+ for wheel in wheels:
997
+ url = wheel.get('url') or ''
998
+ if 'py3-none-any' in url or 'py2.py3-none-any' in url:
999
+ return url, True
1000
+ if wheels:
1001
+ return wheels[0].get('url'), True
1002
+ return '', False
1003
+
971
1004
 
1005
+ def get_available_wheel_urls(name, version):
1006
+ try:
1007
+ files = _pypi_release_files(name, version)
1008
+ return [
1009
+ item.get('url') for item in files
1010
+ if item.get('packagetype') == 'bdist_wheel' and item.get('url')
1011
+ ]
972
1012
  except Exception as error:
973
1013
  logger.warning(f'Failed to get wheel URLs from PyPI API: {error}')
974
1014
  return []
975
1015
 
976
1016
 
977
1017
  def get_download_location_for_pypi(link):
978
- # get the url for downloading source file: https://docs.pypi.org/api/ Predictable URLs
1018
+ """Resolve a PyPI project URL to the file URL published in the JSON API."""
979
1019
  ret = False
980
1020
  new_link = ''
981
- host = 'https://files.pythonhosted.org'
982
1021
 
983
1022
  try:
984
1023
  dn_loc_re = re.findall(r'pypi.org\/project\/?([^\/]*)\/?([^\/]*)', link)
985
- oss_name = dn_loc_re[0][0]
986
- oss_name = re.sub(r"[-_.]+", "-", oss_name)
987
- oss_version = dn_loc_re[0][1]
988
-
989
- # 1. Source distribution 시도
990
- new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
991
- try:
992
- res = urlopen(new_link, timeout=_HTTP_TIMEOUT)
993
- if res.getcode() == 200:
994
- ret = True
995
- return ret, new_link
996
- except Exception:
997
- oss_name = re.sub(r"[-]+", "_", oss_name)
998
- new_link = f'{host}/packages/source/{oss_name[0]}/{oss_name}/{oss_name}-{oss_version}.tar.gz'
999
- try:
1000
- res = urlopen(new_link, timeout=_HTTP_TIMEOUT)
1001
- if res.getcode() == 200:
1002
- ret = True
1003
- return ret, new_link
1004
- except Exception:
1005
- pass
1006
-
1007
- # 2. Source distribution이 없으면 wheel 파일들을 시도
1008
- wheel_urls = get_available_wheel_urls(oss_name, oss_version)
1009
-
1010
- if wheel_urls:
1011
- # Pure Python wheel을 우선적으로 찾기
1012
- for wheel_url in wheel_urls:
1013
- if 'py3-none-any' in wheel_url or 'py2.py3-none-any' in wheel_url:
1014
- try:
1015
- res = urlopen(wheel_url, timeout=_HTTP_TIMEOUT)
1016
- if res.getcode() == 200:
1017
- ret = True
1018
- new_link = wheel_url
1019
- logger.info(f'Using wheel file : {wheel_url}')
1020
- return ret, new_link
1021
- except Exception:
1022
- continue
1023
-
1024
- # Pure Python wheel이 없으면 첫 번째 wheel 시도
1025
- if wheel_urls:
1026
- try:
1027
- res = urlopen(wheel_urls[0], timeout=_HTTP_TIMEOUT)
1028
- if res.getcode() == 200:
1029
- ret = True
1030
- new_link = wheel_urls[0]
1031
- logger.info(f'Using wheel file : {wheel_urls[0]}')
1032
- return ret, new_link
1033
- except Exception:
1034
- pass
1035
-
1024
+ if not dn_loc_re:
1025
+ return ret, new_link
1026
+ oss_name = unquote(dn_loc_re[0][0])
1027
+ oss_version = unquote(dn_loc_re[0][1])
1028
+ if not oss_name or not oss_version:
1029
+ return ret, new_link
1030
+
1031
+ chosen_url, is_wheel = _select_pypi_download_url(
1032
+ _pypi_release_files(oss_name, oss_version)
1033
+ )
1034
+ if chosen_url:
1035
+ ret = True
1036
+ new_link = chosen_url
1037
+ if is_wheel:
1038
+ logger.info(f'Using wheel file : {chosen_url}')
1039
+ return ret, new_link
1040
+ logger.warning(f'Cannot find the link for pypi (url:{link})')
1036
1041
  except Exception as error:
1037
1042
  ret = False
1038
1043
  logger.warning(f'Cannot find the link for pypi (url:{link}({new_link})) e:{str(error)}')
@@ -861,6 +861,8 @@ _SEMVER_DOT_QUALIFIER_IN_STR = re.compile(
861
861
  re.IGNORECASE,
862
862
  )
863
863
  _CLARIFIED_MAJOR_ONLY_FULL = re.compile(r'^(?:v\.? ?)?(\d+)$', re.IGNORECASE)
864
+ # PEP 440 epoch (N!version). The release after '!' is not a reliable clarified version.
865
+ _PEP440_EPOCH_VERSION = re.compile(r'^\d+!')
864
866
  # Maven / OSGi style: 1.1.7.7 (more than three numeric segments; not strict semver)
865
867
  _PURE_DOT_NUMERIC_VERSION = re.compile(r'^\d+(\.\d+)+$')
866
868
  # Three-part x.y.z anywhere (e.g. R0.3.6, pkg0.3.6) — tried before two-part fallback
@@ -903,6 +905,8 @@ def clarified_version_from_oss_version(oss_version: str) -> str:
903
905
  s = (oss_version or "").strip()
904
906
  if not s:
905
907
  return ""
908
+ if _PEP440_EPOCH_VERSION.match(s):
909
+ return ""
906
910
  core = _strip_leading_v_prefix(_strip_debian_epoch_prefix(s))
907
911
  if _PURE_DOT_NUMERIC_VERSION.match(core):
908
912
  return core
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_util
3
- Version: 2.2.24
3
+ Version: 2.2.26
4
4
  Summary: FOSSLight Util
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -43,6 +43,7 @@ tests/test_decide_checkout.py
43
43
  tests/test_download.py
44
44
  tests/test_download_maven.py
45
45
  tests/test_download_packagist.py
46
+ tests/test_download_pypi.py
46
47
  tests/test_download_timeout.py
47
48
  tests/test_download_user_agent.py
48
49
  tests/test_download_version_attempts.py
@@ -0,0 +1,102 @@
1
+ # Copyright (c) 2026 LG Electronics Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ """PyPI project URLs resolve to the file URL from the JSON API."""
4
+
5
+ from unittest.mock import Mock, patch
6
+
7
+ from fosslight_util._get_downloadable_url import get_download_location_for_pypi
8
+
9
+ _SDIST = (
10
+ "https://files.pythonhosted.org/packages/9b/5a/abc/"
11
+ "winrt_windows_storage_streams-4!10.0.28000.2957.tar.gz"
12
+ )
13
+ _WHEEL = (
14
+ "https://files.pythonhosted.org/packages/d5/8d/abc/"
15
+ "winrt_windows_storage_streams-4!10.0.28000.2957-py3-none-any.whl"
16
+ )
17
+ _PROJECT = "https://pypi.org/project/winrt-Windows.Storage.Streams/4!10.0.28000.2957"
18
+
19
+
20
+ def _response(status_code, urls):
21
+ response = Mock()
22
+ response.status_code = status_code
23
+ response.json.return_value = {"urls": urls}
24
+ return response
25
+
26
+
27
+ @patch("fosslight_util._get_downloadable_url.requests.get")
28
+ def test_pypi_json_prefers_sdist_for_mixed_case_name(mock_get):
29
+ mock_get.return_value = _response(200, [
30
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": _WHEEL},
31
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
32
+ {"packagetype": "sdist", "filename": "pkg.zip", "url": "https://example.invalid/pkg.zip"},
33
+ ])
34
+
35
+ found, link = get_download_location_for_pypi(_PROJECT)
36
+
37
+ assert found is True
38
+ assert link == _SDIST
39
+ requested = mock_get.call_args.args[0]
40
+ assert "winrt-Windows.Storage.Streams" in requested
41
+ assert "4%2110.0.28000.2957" in requested
42
+ assert "packages/source/" not in link
43
+
44
+
45
+ @patch("fosslight_util._get_downloadable_url.requests.get")
46
+ def test_pypi_json_uses_pure_wheel_when_sdist_is_missing(mock_get):
47
+ platform_wheel = "https://files.pythonhosted.org/packages/aa/pkg-1.0-cp312-cp312-win_amd64.whl"
48
+ mock_get.return_value = _response(200, [
49
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": platform_wheel},
50
+ {"packagetype": "bdist_wheel", "filename": "pkg-none.whl", "url": _WHEEL},
51
+ ])
52
+
53
+ found, link = get_download_location_for_pypi("https://pypi.org/project/pkg/1.0")
54
+
55
+ assert found is True
56
+ assert link == _WHEEL
57
+
58
+
59
+ @patch("fosslight_util._get_downloadable_url.requests.get")
60
+ def test_pypi_json_keeps_yanked_release_file(mock_get):
61
+ mock_get.return_value = _response(200, [
62
+ {"packagetype": "bdist_wheel", "filename": "pkg.whl", "url": _WHEEL, "yanked": True},
63
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST, "yanked": True},
64
+ ])
65
+
66
+ found, link = get_download_location_for_pypi(_PROJECT)
67
+
68
+ assert found is True
69
+ assert link == _SDIST
70
+
71
+
72
+ @patch("fosslight_util._get_downloadable_url.requests.get")
73
+ def test_pypi_json_decodes_percent_encoded_version(mock_get):
74
+ mock_get.return_value = _response(200, [
75
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
76
+ ])
77
+ encoded = "https://pypi.org/project/winrt-Windows.Storage.Streams/4%2110.0.28000.2957"
78
+
79
+ found, link = get_download_location_for_pypi(encoded)
80
+
81
+ assert found is True
82
+ assert link == _SDIST
83
+ encoded_request = mock_get.call_args.args[0]
84
+ assert "4%2110.0.28000.2957" in encoded_request
85
+ assert "%2521" not in encoded_request
86
+
87
+ mock_get.reset_mock()
88
+ mock_get.return_value = _response(200, [
89
+ {"packagetype": "sdist", "filename": "pkg.tar.gz", "url": _SDIST},
90
+ ])
91
+ get_download_location_for_pypi(_PROJECT)
92
+ assert mock_get.call_args.args[0] == encoded_request
93
+
94
+
95
+ @patch("fosslight_util._get_downloadable_url.requests.get")
96
+ def test_pypi_json_failure_does_not_invent_a_file_url(mock_get):
97
+ mock_get.return_value = _response(404, [])
98
+
99
+ found, link = get_download_location_for_pypi(_PROJECT)
100
+
101
+ assert found is False
102
+ assert link == ""
@@ -112,6 +112,8 @@ def test_oss_version_hint_from_wget_link(link, downloaded_file, expected_hint):
112
112
  ("android-15.0.0_r1", "15.0.0"),
113
113
  ("4:10.2.1-1", "10.2.1"),
114
114
  ("1:3.118+deb11u1", "3.118"),
115
+ # PEP 440 epoch is not simplified into a clarified version
116
+ ("4!10.0.28000.2957", ""),
115
117
  # Embedded three-part versions must not collapse to trailing x.y
116
118
  ("R0.3.6", "0.3.6"),
117
119
  ("rel0.3.6", "0.3.6"),
File without changes