Include default system and arch synonyms
All checks were successful
continuous-integration/drone/push Build is passing

Some projects use different system and arch names in their assets.
Sometimes due to convention or differeing tools and systems. For
example, on macOS 13.6, Python will return the system as `Darwin`.
However, some release assets will be named `macOS` or `macos`. Similarly
`arm64` and `aarch64` are used interchangeably.

This patch adds a few lists of synonymous values such that
release-gitter can make an attempt at matching the intended binary.
These lists of synonyms can be expanded to be more complete as time goes
on.

These synonyms are only used if there is no user provided mapping. In
the case that any user provided mapping exists, the map will be the
sole source of truth. Eg. If you provide a map for `Windows=>windows`,
no other values will be mapped and we won't assume that `Darwin=>macos`
anymore.
This commit is contained in:
IamTheFij 2023-11-01 15:52:34 -07:00
parent ddf509e9a4
commit 1365fc48bf

View File

@ -6,6 +6,7 @@ import platform
from collections.abc import Sequence
from dataclasses import dataclass
from io import BytesIO
from itertools import product
from mimetypes import guess_type
from pathlib import Path
from subprocess import check_call
@ -47,6 +48,31 @@ def removesuffix(s: str, suf: str) -> str:
return s[: -len(suf)] if s and s.endswith(suf) else s
SYSTEM_SYNONYMS: list[list[str]] = [
["Darwin", "darwin", "macos", "macOS"],
["Windows", "windows", "win", "win64"],
["Linux", "linux"],
]
ARCH_SYNONYMS: list[list[str]] = [
["arm"],
["x86_64", "amd64"],
["arm64", "aarch64", "armv8b", "armv8l"],
["i386", "x86"],
]
def get_synonyms(value: str, thesaurus: list[list[str]]) -> list[str]:
"""Gets synonym list for a given value."""
results = [value]
for l in thesaurus:
if value in l:
results += l
return results
@dataclass
class GitRemoteInfo:
"""Extracts information about a repository"""
@ -245,21 +271,29 @@ def match_asset(
system = platform.system()
if system_mapping:
system = system_mapping.get(system, system)
systems = [system_mapping.get(system, system)]
else:
systems = get_synonyms(system, SYSTEM_SYNONYMS)
arch = platform.machine()
if arch_mapping:
arch = arch_mapping.get(arch, arch)
archs = [arch_mapping.get(arch, arch)]
else:
archs = get_synonyms(arch, ARCH_SYNONYMS)
expected_names = {
format.format(
version=normalized_version,
system=system,
arch=arch,
version=version_opt,
system=system_opt,
arch=arch_opt,
)
for normalized_version in (
version.lstrip("v"),
"v" + version if not version.startswith("v") else version,
for version_opt, system_opt, arch_opt in product(
(
version.lstrip("v"),
"v" + version if not version.startswith("v") else version,
),
systems,
archs,
)
}