From 8a9813f3e2bc5eb156fcddf8e2fe6334f88327c6 Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Feb 26 2017 16:06:24 +0000 Subject: metadata: add support for wildcards in version Closes: https://pagure.io/fedora-rust/rust2rpm/issue/6 Signed-off-by: Igor Gnatenko --- diff --git a/rust2rpm/metadata.py b/rust2rpm/metadata.py index 9561d86..1ff42a9 100644 --- a/rust2rpm/metadata.py +++ b/rust2rpm/metadata.py @@ -17,8 +17,6 @@ class Target(object): class Dependency(object): def __init__(self, name, req, features=(), provides=False): self.name = name - if "*" in req: - raise NotImplementedError("https://github.com/rbarrois/python-semanticversion/issues/51") self.spec = self._parse_req(req) self.features = features self.provides = provides @@ -34,6 +32,13 @@ class Dependency(object): if spec is not None: if spec.kind == spec.KIND_EQUAL: spec.kind = spec.KIND_SHORTEQ + if spec.kind == spec.KIND_ANY: + if spec.spec == "": + # Just wildcard + return basestr + else: + # Wildcard in string + assert False, spec.spec return "{} {} {}".format(basestr, spec.kind, spec.spec) else: return basestr @@ -76,10 +81,16 @@ class Dependency(object): @staticmethod def _parse_req(s): + if "*" in s and s != "*": + # XXX: https://github.com/rbarrois/python-semanticversion/issues/51 + s = "~{}".format(s.replace(".*", "", 1)) spec = semver.Spec(s.replace(" ", "")) parsed = [] for req in spec.specs: ver = req.spec + if req.kind == req.KIND_ANY: + parsed.append("*") + continue coerced = semver.Version.coerce(str(ver)) if req.kind in (req.KIND_CARET, req.KIND_TILDE): if req.kind == req.KIND_CARET: diff --git a/test.py b/test.py index 9d13e60..00aef8d 100644 --- a/test.py +++ b/test.py @@ -180,7 +180,7 @@ def cargo_toml(request): ["(crate(libc) >= 1.2.3 with crate(libc) < 1.3.0)"]), # Wildcard requirements - pytest.mark.xfail((""" + (""" [package] name = "hello" version = "0.0.0" @@ -189,8 +189,8 @@ def cargo_toml(request): libc = "*" """, ["crate(hello) = 0.0.0"], - ["crate(libc) >= 0.0.0"])), - pytest.mark.xfail((""" + ["crate(libc)"]), + (""" [package] name = "hello" version = "0.0.0" @@ -199,8 +199,8 @@ def cargo_toml(request): libc = "1.*" """, ["crate(hello) = 0.0.0"], - ["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"])), - pytest.mark.xfail((""" + ["(crate(libc) >= 1.0.0 with crate(libc) < 2.0.0)"]), + (""" [package] name = "hello" version = "0.0.0" @@ -209,7 +209,7 @@ def cargo_toml(request): libc = "1.2.*" """, ["crate(hello) = 0.0.0"], - ["(crate(libc) >= 1.2.0 with crate(libc) < 1.3.0)"])), + ["(crate(libc) >= 1.2.0 with crate(libc) < 1.3.0)"]), # Inequality requirements ("""