summary refs log tree commit diff
path: root/pkgs/servers/home-assistant/parse-requirements.py
diff options
context:
space:
mode:
authorRobert Schütz <robert.schuetz@stud.uni-heidelberg.de>2018-05-22 14:48:55 +0200
committerRobin Gloster <mail@glob.in>2018-05-22 15:08:46 +0200
commit3807a0d526498482eae7ea8ea805327c29c5edf5 (patch)
tree3be243412d5d819bedae9e2a51e12e8cb7da541e /pkgs/servers/home-assistant/parse-requirements.py
parent7a9bf829990ed1374de8163dd00dc31788e84b32 (diff)
downloadnixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar.gz
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar.bz2
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar.lz
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar.xz
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.tar.zst
nixlib-3807a0d526498482eae7ea8ea805327c29c5edf5.zip
home-assistant: deal with multiple packages matching requirement
Diffstat (limited to 'pkgs/servers/home-assistant/parse-requirements.py')
-rwxr-xr-xpkgs/servers/home-assistant/parse-requirements.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/pkgs/servers/home-assistant/parse-requirements.py b/pkgs/servers/home-assistant/parse-requirements.py
index 46e7acee1782..5beeaccf0881 100755
--- a/pkgs/servers/home-assistant/parse-requirements.py
+++ b/pkgs/servers/home-assistant/parse-requirements.py
@@ -25,6 +25,13 @@ GENERAL_PREFIX = '# homeassistant.'
 COMPONENT_PREFIX = GENERAL_PREFIX + 'components.'
 PKG_SET = 'python3Packages'
 
+# If some requirements are matched by multiple python packages,
+# the following can be used to choose one of them
+PKG_PREFERENCES = {
+    # Use python3Packages.youtube-dl-light instead of python3Packages.youtube-dl
+    'youtube-dl': 'youtube-dl-light'
+}
+
 def get_version():
     with open(os.path.dirname(sys.argv[0]) + '/default.nix') as f:
         m = re.search('hassVersion = "([\\d\\.]+)";', f.read())
@@ -59,7 +66,7 @@ output = subprocess.check_output(['nix-env', '-f', os.path.dirname(sys.argv[0])
 packages = json.loads(output)
 
 def name_to_attr_path(req):
-    attr_paths = []
+    attr_paths = set()
     names = [req]
     # E.g. python-mpd2 is actually called python3.6-mpd2
     # instead of python-3.6-python-mpd2 inside Nixpkgs
@@ -71,11 +78,18 @@ def name_to_attr_path(req):
         pattern = re.compile('^python\\d\\.\\d-{}-\\d'.format(name), re.I)
         for attr_path, package in packages.items():
             if pattern.match(package['name']):
-                attr_paths.append(attr_path)
+                attr_paths.add(attr_path)
+    if len(attr_paths) > 1:
+        for to_replace, replacement in PKG_PREFERENCES.items():
+            try:
+                attr_paths.remove(PKG_SET + '.' + to_replace)
+                attr_paths.add(PKG_SET + '.' + replacement)
+            except KeyError:
+                pass
     # Let's hope there's only one derivation with a matching name
     assert(len(attr_paths) <= 1)
-    if attr_paths:
-        return attr_paths[0]
+    if len(attr_paths) == 1:
+        return attr_paths.pop()
     else:
         return None
 
@@ -86,14 +100,11 @@ build_inputs = {}
 for component, reqs in OrderedDict(sorted(requirements.items())).items():
     attr_paths = []
     for req in reqs:
-        try:
-            name = req.split('==')[0]
-            attr_path = name_to_attr_path(name)
-            if attr_path is not None:
-                # Add attribute path without "python3Packages." prefix
-                attr_paths.append(attr_path[len(PKG_SET + '.'):])
-        except RequirementParseError:
-            continue
+        name = req.split('==')[0]
+        attr_path = name_to_attr_path(name)
+        if attr_path is not None:
+            # Add attribute path without "python3Packages." prefix
+            attr_paths.append(attr_path[len(PKG_SET + '.'):])
     else:
         build_inputs[component] = attr_paths