Skip to content

Commit 91f5613

Browse files
committed
Align scripts with latest ScanCode Toolkit
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent d3a19bd commit 91f5613

7 files changed

+82
-40
lines changed

etc/scripts/fetch_thirdparty.py

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import itertools
1313
import os
1414
import sys
15+
from collections import defaultdict
1516

1617
import click
1718

@@ -110,6 +111,39 @@
110111
is_flag=True,
111112
help="Use on disk cached PyPI indexes list of packages and versions and do not refetch if present.",
112113
)
114+
@click.option(
115+
"--sdist-only",
116+
"sdist_only",
117+
type=str,
118+
metavar="SDIST",
119+
default=tuple(),
120+
show_default=False,
121+
multiple=True,
122+
help="Package name(s) that come only in sdist format (no wheels). "
123+
"The command will not fail and exit if no wheel exists for these names",
124+
)
125+
@click.option(
126+
"--wheel-only",
127+
"wheel_only",
128+
type=str,
129+
metavar="WHEEL",
130+
default=tuple(),
131+
show_default=False,
132+
multiple=True,
133+
help="Package name(s) that come only in wheel format (no sdist). "
134+
"The command will not fail and exit if no sdist exists for these names",
135+
)
136+
@click.option(
137+
"--no-dist",
138+
"no_dist",
139+
type=str,
140+
metavar="DIST",
141+
default=tuple(),
142+
show_default=False,
143+
multiple=True,
144+
help="Package name(s) that do not come either in wheel or sdist format. "
145+
"The command will not fail and exit if no distribution exists for these names",
146+
)
113147
@click.help_option("-h", "--help")
114148
def fetch_thirdparty(
115149
requirements_files,
@@ -122,6 +156,9 @@ def fetch_thirdparty(
122156
sdists,
123157
index_urls,
124158
use_cached_index,
159+
sdist_only,
160+
wheel_only,
161+
no_dist,
125162
):
126163
"""
127164
Download to --dest THIRDPARTY_DIR the PyPI wheels, source distributions,
@@ -204,58 +241,62 @@ def fetch_thirdparty(
204241
)
205242
repos.append(repo)
206243

207-
wheels_fetched = []
208-
wheels_not_found = []
209-
210-
sdists_fetched = []
211-
sdists_not_found = []
244+
wheels_or_sdist_not_found = defaultdict(list)
212245

213246
for name, version in sorted(required_name_versions):
214247
nv = name, version
215248
print(f"Processing: {name} @ {version}")
216249
if wheels:
217250
for environment in environments:
251+
218252
if TRACE:
219253
print(f" ==> Fetching wheel for envt: {environment}")
220-
fwfns = utils_thirdparty.download_wheel(
254+
255+
fetched = utils_thirdparty.download_wheel(
221256
name=name,
222257
version=version,
223258
environment=environment,
224259
dest_dir=dest_dir,
225260
repos=repos,
226261
)
227-
if fwfns:
228-
wheels_fetched.extend(fwfns)
229-
else:
230-
wheels_not_found.append(f"{name}=={version} for: {environment}")
262+
if not fetched:
263+
wheels_or_sdist_not_found[f"{name}=={version}"].append(environment)
231264
if TRACE:
232265
print(f" NOT FOUND")
233266

234-
if sdists:
267+
if (sdists or
268+
(f"{name}=={version}" in wheels_or_sdist_not_found and name in sdist_only)
269+
):
235270
if TRACE:
236271
print(f" ==> Fetching sdist: {name}=={version}")
272+
237273
fetched = utils_thirdparty.download_sdist(
238274
name=name,
239275
version=version,
240276
dest_dir=dest_dir,
241277
repos=repos,
242278
)
243-
if fetched:
244-
sdists_fetched.append(fetched)
245-
else:
246-
sdists_not_found.append(f"{name}=={version}")
279+
if not fetched:
280+
wheels_or_sdist_not_found[f"{name}=={version}"].append("sdist")
247281
if TRACE:
248282
print(f" NOT FOUND")
249283

250-
if wheels and wheels_not_found:
251-
print(f"==> MISSING WHEELS")
252-
for wh in wheels_not_found:
253-
print(f" {wh}")
284+
mia = []
285+
for nv, dists in wheels_or_sdist_not_found.items():
286+
name, _, version = nv.partition("==")
287+
if name in no_dist:
288+
continue
289+
sdist_missing = sdists and "sdist" in dists and not name in wheel_only
290+
if sdist_missing:
291+
mia.append(f"SDist missing: {nv} {dists}")
292+
wheels_missing = wheels and any(d for d in dists if d != "sdist") and not name in sdist_only
293+
if wheels_missing:
294+
mia.append(f"Wheels missing: {nv} {dists}")
254295

255-
if sdists and sdists_not_found:
256-
print(f"==> MISSING SDISTS")
257-
for sd in sdists_not_found:
258-
print(f" {sd}")
296+
if mia:
297+
for m in mia:
298+
print(m)
299+
raise Exception(mia)
259300

260301
print(f"==> FETCHING OR CREATING ABOUT AND LICENSE FILES")
261302
utils_thirdparty.fetch_abouts_and_licenses(dest_dir=dest_dir, use_cached_index=use_cached_index)

etc/scripts/gen_pypi_simple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def build_per_package_index(pkg_name, packages, base_url):
118118
<body>"""
119119
document.append(header)
120120

121-
for package in packages:
121+
for package in sorted(packages, key=lambda p: p.archive_file):
122122
document.append(package.simple_index_entry(base_url))
123123

124124
footer = """ </body>
@@ -141,8 +141,8 @@ def build_links_package_index(packages_by_package_name, base_url):
141141
<body>"""
142142
document.append(header)
143143

144-
for _name, packages in packages_by_package_name.items():
145-
for package in packages:
144+
for _name, packages in sorted(packages_by_package_name.items(), key=lambda i: i[0]):
145+
for package in sorted(packages, key=lambda p: p.archive_file):
146146
document.append(package.simple_index_entry(base_url))
147147

148148
footer = """ </body>

etc/scripts/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pip
88
setuptools
99
twine
1010
wheel
11-
build
11+
build
12+
packvers

etc/scripts/utils_dejacode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import requests
1616
import saneyaml
1717

18-
from packaging import version as packaging_version
18+
from packvers import version as packaging_version
1919

2020
"""
2121
Utility to create and retrieve package and ABOUT file data from DejaCode.

etc/scripts/utils_pip_compatibility_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import re
2929

30-
from packaging.tags import (
30+
from packvers.tags import (
3131
compatible_tags,
3232
cpython_tags,
3333
generic_tags,

etc/scripts/utils_requirements.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# See https://github.com/nexB/skeleton for support or download.
99
# See https://aboutcode.org for more information about nexB OSS projects.
1010
#
11+
12+
import os
1113
import re
1214
import subprocess
1315

etc/scripts/utils_thirdparty.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from commoncode import fileutils
2929
from commoncode.hash import multi_checksums
3030
from commoncode.text import python_safe_name
31-
from packaging import tags as packaging_tags
32-
from packaging import version as packaging_version
31+
from packvers import tags as packaging_tags
32+
from packvers import version as packaging_version
3333

3434
import utils_pip_compatibility_tags
3535

@@ -115,10 +115,9 @@
115115
TRACE_ULTRA_DEEP = False
116116

117117
# Supported environments
118-
PYTHON_VERSIONS = "36", "37", "38", "39", "310"
118+
PYTHON_VERSIONS = "37", "38", "39", "310"
119119

120120
PYTHON_DOT_VERSIONS_BY_VER = {
121-
"36": "3.6",
122121
"37": "3.7",
123122
"38": "3.8",
124123
"39": "3.9",
@@ -134,7 +133,6 @@ def get_python_dot_version(version):
134133

135134

136135
ABIS_BY_PYTHON_VERSION = {
137-
"36": ["cp36", "cp36m", "abi3"],
138136
"37": ["cp37", "cp37m", "abi3"],
139137
"38": ["cp38", "cp38m", "abi3"],
140138
"39": ["cp39", "cp39m", "abi3"],
@@ -912,7 +910,7 @@ def load_pkginfo_data(self, dest_dir=THIRDPARTY_DIR):
912910
declared_license = [raw_data["License"]] + [
913911
c for c in classifiers if c.startswith("License")
914912
]
915-
license_expression = compute_normalized_license_expression(declared_license)
913+
license_expression = get_license_expression(declared_license)
916914
other_classifiers = [c for c in classifiers if not c.startswith("License")]
917915

918916
holder = raw_data["Author"]
@@ -1337,10 +1335,10 @@ def package_from_dists(cls, dists):
13371335
13381336
For example:
13391337
>>> w1 = Wheel(name='bitarray', version='0.8.1', build='',
1340-
... python_versions=['cp36'], abis=['cp36m'],
1338+
... python_versions=['cp38'], abis=['cp38m'],
13411339
... platforms=['linux_x86_64'])
13421340
>>> w2 = Wheel(name='bitarray', version='0.8.1', build='',
1343-
... python_versions=['cp36'], abis=['cp36m'],
1341+
... python_versions=['cp38'], abis=['cp38m'],
13441342
... platforms=['macosx_10_9_x86_64', 'macosx_10_10_x86_64'])
13451343
>>> sd = Sdist(name='bitarray', version='0.8.1')
13461344
>>> package = PypiPackage.package_from_dists(dists=[w1, w2, sd])
@@ -2274,16 +2272,16 @@ def find_problems(
22742272
check_about(dest_dir=dest_dir)
22752273

22762274

2277-
def compute_normalized_license_expression(declared_licenses):
2275+
def get_license_expression(declared_licenses):
22782276
"""
22792277
Return a normalized license expression or None.
22802278
"""
22812279
if not declared_licenses:
22822280
return
22832281
try:
2284-
from packagedcode import pypi
2282+
from packagedcode.licensing import get_only_expression_from_extracted_license
22852283

2286-
return pypi.compute_normalized_license(declared_licenses)
2284+
return get_only_expression_from_extracted_license(declared_licenses)
22872285
except ImportError:
22882286
# Scancode is not installed, clean and join all the licenses
22892287
lics = [python_safe_name(l).lower() for l in declared_licenses]

0 commit comments

Comments
 (0)