Browse Source

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
changes/76/635576/3
Sorin Sbarnea 3 months ago
parent
commit
0bc70eee07
2 changed files with 10 additions and 1 deletions
  1. 1
    1
      bindep/depends.py
  2. 9
    0
      bindep/tests/test_depends.py

+ 1
- 1
bindep/depends.py View File

@@ -47,7 +47,7 @@ rule = <name>:name selector?:selector version?:version ('\n'|comment) -> (
47 47
     name, selector or [], version or [])
48 48
 lowercase = ('a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'|'k'|'l'|'m'|'n'|'o'|'p'
49 49
             |'q'|'r'|'s'|'t'|'u'|'v'|'w'|'x'|'y'|'z')
50
-name = letterOrDigit:start (letterOrDigit|'.'|'+'|'-'|'_'|'/')+:rest
50
+name = (letterOrDigit|'/'):start (letterOrDigit|'.'|'+'|'-'|'_'|'/')+:rest
51 51
 ws = ' '+
52 52
 profile = ('!'?:neg <(lowercase|digit|':'|'-'|'.')+>:name) -> (neg!='!', name)
53 53
 profiles = '(' (ws? profile)*:p ws? ')' -> p

+ 9
- 0
bindep/tests/test_depends.py View File

@@ -448,6 +448,15 @@ class TestDepends(TestCase):
448 448
             """))
449 449
         self.assertEqual(len(depends.active_rules(['default'])), 3)
450 450
 
451
+    def test_parser_accepts_full_path_to_tools(self):
452
+        # at least yum/dnf allow these instead of mentioning rpm names
453
+        depends = Depends(dedent("""\
454
+            /usr/bin/bash
455
+            """))
456
+        self.assertEqual(
457
+            [("/usr/bin/bash", [], [])],
458
+            depends.active_rules(["default"]))
459
+
451 460
     def test_parser_invalid(self):
452 461
         self.assertRaises(ometa.runtime.ParseError,
453 462
                           lambda: Depends("foo [platform:bar@baz]\n"))

Loading…
Cancel
Save