Use walrus more

It was already used in other places, so this doesn't change much.
Walrus was added in 3.8, so drop 3.7 from the compat list.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-07-12 11:04:23 +02:00
parent cd1281d709
commit 365d47a843
3 changed files with 4 additions and 10 deletions

View file

@ -62,8 +62,7 @@ def read_os_release():
line = line.rstrip()
if not line or line.startswith('#'):
continue
m = re.match(r'([A-Z][A-Z_0-9]+)=(.*)', line)
if m:
if m := re.match(r'([A-Z][A-Z_0-9]+)=(.*)', line):
name, val = m.groups()
if val and val[0] in '"\'':
val = ast.literal_eval(val)
@ -517,9 +516,7 @@ def main():
if args.target in {"fedora"} and args.existence_check and not os.path.exists(spec_file):
# No specfile, so this is probably a new package
package_info = get_package_info(pkg_name)
if package_info:
if package_info := get_package_info(pkg_name):
if args.suffix:
print(f"Versions {args.suffix}.* of the crate '{metadata.name}' are already")
print(f"packaged for Fedora: {package_info['full_url']}")

View file

@ -54,13 +54,11 @@ def detect_packager():
return packager
# If we're detecting packager identity through rpmdev-packager...
rpmdev_packager = shutil.which('rpmdev-packager')
if rpmdev_packager is not None:
if rpmdev_packager := shutil.which('rpmdev-packager'):
return subprocess.check_output(rpmdev_packager, text=True).strip()
# If we're detecting packager identity through git configuration...
git = shutil.which('git')
if git is not None:
if git := shutil.which('git'):
name = subprocess.check_output([git, 'config', 'user.name'], text=True).strip()
email = subprocess.check_output([git, 'config', 'user.email'], text=True).strip()
return f'{name} <{email}>'

View file

@ -49,7 +49,6 @@ ARGS = dict(
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",