cli: add automatic --compat flag, deprecate manual --suffix argument
This commit is contained in:
parent
d0d3742a07
commit
26aa680301
5 changed files with 61 additions and 3 deletions
|
@ -18,6 +18,7 @@ from rust2rpm.utils import (
|
|||
detect_rpmautospec,
|
||||
exit_on_common_errors,
|
||||
guess_crate_name,
|
||||
package_name_compat,
|
||||
package_name_suffixed,
|
||||
)
|
||||
|
||||
|
@ -57,7 +58,14 @@ def main():
|
|||
rpm_name = project
|
||||
else:
|
||||
base_name = metadata.packages[0].name
|
||||
rpm_name = package_name_suffixed(base_name, args.suffix)
|
||||
|
||||
if args.suffix:
|
||||
log.warn("The '--suffix' argument is deprecated, use the '--compat' flag instead.")
|
||||
rpm_name = package_name_suffixed(base_name, args.suffix)
|
||||
elif args.compat:
|
||||
rpm_name = package_name_compat(base_name, args.version)
|
||||
else:
|
||||
rpm_name = package_name_suffixed(base_name, None)
|
||||
|
||||
patch_files = (
|
||||
f"{base_name}-fix-metadata-auto.diff" if diffs[0] else None,
|
||||
|
|
|
@ -87,6 +87,11 @@ def get_parser():
|
|||
action="store",
|
||||
help="Package suffix",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--compat",
|
||||
action="store_true",
|
||||
help="Create a compat package with appropriate version suffix",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--interactive",
|
||||
|
|
31
rust2rpm/tests/test_utils.py
Normal file
31
rust2rpm/tests/test_utils.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import pytest
|
||||
|
||||
from rust2rpm.utils import package_name_suffixed, package_name_compat
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"crate,suffix,expected",
|
||||
[
|
||||
("syn", "0.4", "rust-syn0.4"),
|
||||
("syn", "1", "rust-syn1"),
|
||||
("socket2", "0.3", "rust-socket2_0.3"),
|
||||
("version-compare", "0.0.11", "rust-version-compare0.0.11"),
|
||||
],
|
||||
ids=repr,
|
||||
)
|
||||
def test_package_name_suffixed(crate: str, suffix: str, expected: str):
|
||||
package_name_suffixed(crate, suffix) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"crate,version,expected",
|
||||
[
|
||||
("syn", "0.4.0", "rust-syn0.4"),
|
||||
("syn", "1.0.109", "rust-syn1"),
|
||||
("socket2", "0.3.4", "rust-socket2_0.3"),
|
||||
("version-compare", "0.0.11", "rust-version-compare0.0.11"),
|
||||
],
|
||||
ids=repr,
|
||||
)
|
||||
def test_package_name_compat(crate: str, version: str, expected: str):
|
||||
package_name_compat(crate, version) == expected
|
|
@ -7,6 +7,9 @@ import shlex
|
|||
import shutil
|
||||
import subprocess
|
||||
import requests
|
||||
from typing import Optional
|
||||
|
||||
from cargo2rpm.metadata import Version
|
||||
|
||||
from rust2rpm import log
|
||||
|
||||
|
@ -124,11 +127,22 @@ def guess_crate_name():
|
|||
return None
|
||||
|
||||
|
||||
def package_name_suffixed(name, suffix):
|
||||
def package_name_suffixed(name: str, suffix: Optional[str]):
|
||||
joiner = "_" if suffix and name[-1].isdigit() else ""
|
||||
return "rust-" + name + joiner + (suffix or "")
|
||||
|
||||
|
||||
def package_name_compat(name: str, version: str):
|
||||
sv = Version.parse(version)
|
||||
if sv.major > 0:
|
||||
suffix = str(sv.major)
|
||||
elif sv.minor > 0:
|
||||
suffix = f"0.{str(sv.minor)}"
|
||||
else:
|
||||
suffix = f"0.0.{str(sv.patch)}"
|
||||
return package_name_suffixed(name, suffix)
|
||||
|
||||
|
||||
def detect_rpmautospec(default_target, spec_file):
|
||||
"""Guess whether %autorelease+%autochangelog should be used
|
||||
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -1,5 +1,5 @@
|
|||
[tox]
|
||||
envlist = py310,py311
|
||||
envlist = py310,py311,py312
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
|
|
Loading…
Reference in a new issue