From 0bc70eee07b1832d5e3e1e75f531d394523e107e Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 7 Feb 2019 17:10:44 +0000 Subject: [PATCH] Allow mentioning tools paths in bindep yum/dnf package managers do allow mentioning full path to executable instead of rpm name for installing it. This allows users to install needed tool regardless what package name may provide it (which may depend on what repos they have installed or enabled). This allows 'package' names to start with slash as this is a requirement for triggering this feature in yum/rpm. Practice use-case scenario: user wants docker to be installed but docker could be installed from docker rpm or from docker-ce rpm if user added upstream repositories. Both of them provide the same executable, but the package manager will pick one based on its priorities. Command line example: yum install -y /usr/bin/docker Change-Id: I7e47ee956e9496d9f47a98f9595790797c8d1789 --- bindep/depends.py | 2 +- bindep/tests/test_depends.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindep/depends.py b/bindep/depends.py index 3ccd9c4..cf6304c 100644 --- a/bindep/depends.py +++ b/bindep/depends.py @@ -47,7 +47,7 @@ rule = :name selector?:selector version?:version ('\n'|comment) -> ( name, selector or [], version or []) lowercase = ('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p' |'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z') -name = letterOrDigit:start (letterOrDigit|'.'|'+'|'-'|'_'|'/')+:rest +name = (letterOrDigit|'/'):start (letterOrDigit|'.'|'+'|'-'|'_'|'/')+:rest ws = ' '+ profile = ('!'?:neg <(lowercase|digit|':'|'-'|'.')+>:name) -> (neg!='!', name) profiles = '(' (ws? profile)*:p ws? ')' -> p diff --git a/bindep/tests/test_depends.py b/bindep/tests/test_depends.py index da9b732..31f227f 100644 --- a/bindep/tests/test_depends.py +++ b/bindep/tests/test_depends.py @@ -448,6 +448,15 @@ class TestDepends(TestCase): """)) self.assertEqual(len(depends.active_rules(['default'])), 3) + def test_parser_accepts_full_path_to_tools(self): + # at least yum/dnf allow these instead of mentioning rpm names + depends = Depends(dedent("""\ + /usr/bin/bash + """)) + self.assertEqual( + [("/usr/bin/bash", [], [])], + depends.active_rules(["default"])) + def test_parser_invalid(self): self.assertRaises(ometa.runtime.ParseError, lambda: Depends("foo [platform:bar@baz]\n"))