Makes test_debian_compatibility more robust

Ignores packages on HTTP error
pull/845/head
Tpt 9 months ago committed by Thomas Tanon
parent 1d5843fddc
commit 83aa8170ea
  1. 32
      lints/test_debian_compatibility.py

@ -1,7 +1,6 @@
import json import json
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from time import sleep
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
@ -22,10 +21,6 @@ cargo_metadata = json.loads(
subprocess.check_output(["cargo", "metadata", "--format-version", "1"]) subprocess.check_output(["cargo", "metadata", "--format-version", "1"])
) )
package_by_id = {package["id"]: package for package in cargo_metadata["packages"]} package_by_id = {package["id"]: package for package in cargo_metadata["packages"]}
workspace_packages = {
package_id.split(" ")[0]
for package_id in cargo_metadata["workspace_default_members"]
}
debian_cache = {} debian_cache = {}
errors = set() errors = set()
@ -34,34 +29,27 @@ def parse_version(version):
return tuple(int(e) for e in version.split("-")[0].split(".")) return tuple(int(e) for e in version.split("-")[0].split("."))
def fetch_debian_package_desc(debian_name):
url = f"https://sources.debian.org/api/src/{debian_name}/"
for i in range(0, 10):
try:
with urlopen(url) as response:
return json.loads(response.read().decode())
except HTTPError as e:
wait = 2**i
print(f"Error {e} from {url}, retrying after {wait}s")
sleep(wait)
raise Exception(f"Failed to fetch {url}")
for package_id in cargo_metadata["workspace_default_members"]: for package_id in cargo_metadata["workspace_default_members"]:
package = package_by_id[package_id] package = package_by_id[package_id]
if package["name"] in IGNORE_PACKAGES: if package["name"] in IGNORE_PACKAGES:
continue continue
for dependency in package["dependencies"]: for dependency in package["dependencies"]:
if ( if (
dependency["name"] in workspace_packages "path" in dependency
or dependency["name"] in ALLOWED_MISSING_PACKAGES or dependency["name"] in ALLOWED_MISSING_PACKAGES
): ):
continue continue
candidate_debian_name = f"rust-{dependency['name'].replace('_', '-')}" candidate_debian_name = f"rust-{dependency['name'].replace('_', '-')}"
if dependency["name"] not in debian_cache: if dependency["name"] not in debian_cache:
debian_cache[candidate_debian_name] = fetch_debian_package_desc( url = f"https://sources.debian.org/api/src/{candidate_debian_name}/"
candidate_debian_name try:
) with urlopen(url) as response:
debian_cache[candidate_debian_name] = json.loads(
response.read().decode()
)
except HTTPError as e:
print(f"Error {e} from {url}, skipping {dependency['name']}")
continue
debian_package = debian_cache[candidate_debian_name] debian_package = debian_cache[candidate_debian_name]
if "error" in debian_package: if "error" in debian_package:
errors.add(f"No Debian package found for {dependency['name']}") errors.add(f"No Debian package found for {dependency['name']}")

Loading…
Cancel
Save