misc: fix code style issues pointed out my ruff

This commit is contained in:
Fabio Valentini 2024-02-20 17:40:48 +01:00
parent 21a78ae13f
commit 712f596844
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF
8 changed files with 33 additions and 16 deletions

View file

@ -1,5 +1,7 @@
from rust2rpm import licensing
__all__ = ["licensing"]
# Versioning policy:
#
# - Increment major version if rendered spec files have changed

View file

@ -58,7 +58,7 @@ def main():
sys.exit(1)
except InvalidVersionError:
log.error(
f"Could not determine project name and version automatically. "
"Could not determine project name and version automatically. "
"Please specify the project version on the command line."
)
sys.exit(1)
@ -185,7 +185,7 @@ def main():
sys.exit(1)
if vendor_tarball and not (package.is_bin() or package.is_cdylib()):
log.error(f"Building library-only crates with vendored dependencies is not supported.")
log.error("Building library-only crates with vendored dependencies is not supported.")
sys.exit(1)
warn_if_package_uses_restrictive_dependencies(package)

View file

@ -6,6 +6,8 @@ from pyparsing import ParseException
from rust2rpm import log, TARGET_ARCHES
__all__ = ["ParseException", "parse_and_evaluate", "IDENT_CHARS"]
pp.ParserElement.enablePackrat()
# ConfigurationPredicate :

View file

@ -157,9 +157,9 @@ def to_list(s, sort=True):
if not s:
return []
if sort:
return list(sorted(filter(None, (l.strip() for l in s.splitlines()))))
return list(sorted(filter(None, (elem.strip() for elem in s.splitlines()))))
else:
return list(filter(None, (l.strip() for l in s.splitlines())))
return list(filter(None, (elem.strip() for elem in s.splitlines())))
class ConfError(ValueError):
@ -531,7 +531,7 @@ def load_config(features: set[str], target: str) -> TomlConf:
try:
tomlconf = TomlConf.load("rust2rpm.toml", features)
except FileNotFoundError as exc:
except FileNotFoundError as _exc:
tomlconf = None
except tomllib.TOMLDecodeError as exc:

View file

@ -40,12 +40,17 @@ def query_newest_version(crate: str) -> str:
req.raise_for_status()
versions = req.json()["versions"]
is_stable = lambda s: not re.search("alpha|beta|rc|pre", s["num"])
is_not_yanked = lambda s: not s["yanked"]
def is_stable(s):
return not re.search("alpha|beta|rc|pre", s["num"])
def is_not_yanked(s):
return not s["yanked"]
# return the most recent, non-yanked stable version
is_not_yanked_and_stable = lambda s: is_stable(s) and is_not_yanked(s)
def is_not_yanked_and_stable(s):
return is_stable(s) and is_not_yanked(s)
not_yanked_and_stable = [*filter(is_not_yanked_and_stable, versions)]
if len(not_yanked_and_stable) > 0:
version = not_yanked_and_stable[0]["num"]

View file

@ -32,6 +32,17 @@ RUST_PACKAGING_TARGET_MIN: dict[str, int] = {
}
def license_is_composite(license: str) -> bool:
return (
" " in license
and " WITH " not in license
and "(" not in license
and ")" not in license
or "(" in license
or ")" in license
)
def min_rust_packaging_dep(
package: Package, target: str, is_bin: bool, is_cdylib: bool, vendor_tarball: Optional[str]
) -> int:
@ -589,11 +600,8 @@ def spec_render_workspace(
if len(license_strs) == 1:
rpm_license_tag, rpm_license_comments = translate_license(target, license_strs[0])
else:
is_composite = (
lambda x: (" " in x and " WITH " not in x and "(" not in x and ")" not in x) or "(" in x or ")" in x
)
license_strs = [
license_str if not is_composite(license_str) else f"({license_str})"
license_str if not license_is_composite(license_str) else f"({license_str})"
for license_str in license_strs
if license_str is not None
]

View file

@ -10,7 +10,7 @@ SPDX_TO_FEDORA_CSV = os.path.dirname(__file__) + "/spdx_to_fedora.csv"
def translate_slashes(license: str) -> str:
"Replace all slashes with OR, emit warning"
split = [l.strip() for l in license.split("/")]
split = [part.strip() for part in license.split("/")]
if len(split) > 1:
log.info('Upstream uses deprecated "/" syntax. Replacing with "OR"')
return " OR ".join(split)

View file

@ -92,7 +92,7 @@ def guess_crate_name() -> Optional[str]:
if len(specs) > 1:
log.error(
f"Found multiple spec files in the current working directory; "
"Found multiple spec files in the current working directory; "
+ "unable to determine crate name automatically."
)
return None
@ -106,12 +106,12 @@ def guess_crate_name() -> Optional[str]:
if crate:
log.error(
f"Found multiple definitions of the '%crate' macro in {spec!r}; "
+ f"unable to determine crate name automatically."
+ "unable to determine crate name automatically."
)
return None
crate = m.group(1)
if "%" in crate:
log.error(f"The value of the %crate macro appears to contain other macros and cannot be parsed.")
log.error("The value of the %crate macro appears to contain other macros and cannot be parsed.")
return None
if crate:
log.success(f"Found valid spec file {spec!r} for the {crate!r} crate.")