about summary refs log tree commit diff
path: root/pkgs/servers
diff options
context:
space:
mode:
authorMartin Weinelt <hexa@darmstadt.ccc.de>2023-04-13 22:38:51 +0200
committerMartin Weinelt <hexa@darmstadt.ccc.de>2023-04-13 23:04:44 +0200
commitdf4d6e21a1ca5d841b858375844a2f203b260244 (patch)
tree7ad5ff9ac43e0f9d07ff36a8449d8dccebe97e5a /pkgs/servers
parentf929e5fedda7963f56c8c902b6dcafdf87bc1841 (diff)
home-assistant: Handle illegal version specifiers more gracefully
Our own package versions may not be parseable by the packaging package,
so be more forgiving, when it isn't.

Also strip conditions from upstreams version constraints.
Diffstat (limited to 'pkgs/servers')
-rwxr-xr-xpkgs/servers/home-assistant/parse-requirements.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/pkgs/servers/home-assistant/parse-requirements.py b/pkgs/servers/home-assistant/parse-requirements.py
index 43e21dcfd9229..ef65e795ed34c 100755
--- a/pkgs/servers/home-assistant/parse-requirements.py
+++ b/pkgs/servers/home-assistant/parse-requirements.py
@@ -29,6 +29,7 @@ from typing import Any, Dict, List, Optional, Set
 from urllib.request import urlopen
 
 from packaging import version as Version
+from packaging.version import InvalidVersion
 from rich.console import Console
 from rich.table import Table
 
@@ -197,6 +198,8 @@ def main() -> None:
             # Therefore, if there's a "#" in the line, only take the part after it
             req = req[req.find("#") + 1 :]
             name, required_version = req.split("==", maxsplit=1)
+            # Strip conditions off version constraints e.g. "1.0; python<3.11"
+            required_version = required_version.split(";").pop(0)
             # Split package name and extra requires
             extras = []
             if name.endswith("]"):
@@ -206,11 +209,20 @@ def main() -> None:
             if attr_path:
                 if our_version := get_pkg_version(attr_path, packages):
                     attr_name = attr_path.split(".")[-1]
-                    if Version.parse(our_version) < Version.parse(required_version):
-                        outdated[attr_name] = {
-                          'wanted': required_version,
-                          'current': our_version
-                        }
+                    attr_outdated = False
+                    try:
+                        Version.parse(our_version)
+                    except InvalidVersion:
+                        print(f"Attribute {attr_name} has invalid version specifier {our_version}", file=sys.stderr)
+                        attr_outdated = True
+                    else:
+                        attr_outdated = Version.parse(our_version) < Version.parse(required_version)
+                    finally:
+                        if attr_outdated:
+                            outdated[attr_name] = {
+                              'wanted': required_version,
+                              'current': our_version
+                            }
             if attr_path is not None:
                 # Add attribute path without "python3Packages." prefix
                 pname = attr_path[len(PKG_SET + "."):]