home-assistant/parse-requirements: write missing deps to component-packages.nix

This commit is contained in:
Jörg Thalheim 2020-02-26 15:22:48 +00:00
parent 0cf1e8ee05
commit de1119f5fb
No known key found for this signature in database
GPG Key ID: 003F2096411B5F92

View File

@ -24,6 +24,7 @@ import sys
import tarfile import tarfile
import tempfile import tempfile
from io import BytesIO from io import BytesIO
from typing import Dict, Optional
from urllib.request import urlopen from urllib.request import urlopen
COMPONENT_PREFIX = "homeassistant.components" COMPONENT_PREFIX = "homeassistant.components"
@ -78,6 +79,7 @@ def get_reqs(components, component):
return requirements return requirements
def dump_packages() -> Dict[str, Dict[str, str]]:
# Store a JSON dump of Nixpkgs' python3Packages # Store a JSON dump of Nixpkgs' python3Packages
output = subprocess.check_output( output = subprocess.check_output(
[ [
@ -90,10 +92,10 @@ output = subprocess.check_output(
"--json", "--json",
] ]
) )
packages = json.loads(output) return json.loads(output)
def name_to_attr_path(req): def name_to_attr_path(req: str, packages: Dict[str, Dict[str, str]]) -> Optional[str]:
attr_paths = set() attr_paths = set()
names = [req] names = [req]
# E.g. python-mpd2 is actually called python3.6-mpd2 # E.g. python-mpd2 is actually called python3.6-mpd2
@ -124,6 +126,8 @@ def name_to_attr_path(req):
return None return None
def main() -> None:
packages = dump_packages()
version = get_version() version = get_version()
print("Generating component-packages.nix for version {}".format(version)) print("Generating component-packages.nix for version {}".format(version))
components = parse_components(version=version) components = parse_components(version=version)
@ -137,14 +141,14 @@ for component in sorted(components.keys()):
# Therefore, if there's a "#" in the line, only take the part after it # Therefore, if there's a "#" in the line, only take the part after it
req = req[req.find("#") + 1 :] req = req[req.find("#") + 1 :]
name = req.split("==")[0] name = req.split("==")[0]
attr_path = name_to_attr_path(name) attr_path = name_to_attr_path(name, packages)
if attr_path is not None: if attr_path is not None:
# Add attribute path without "python3Packages." prefix # Add attribute path without "python3Packages." prefix
attr_paths.append(attr_path[len(PKG_SET + ".") :]) attr_paths.append(attr_path[len(PKG_SET + ".") :])
else: else:
missing_reqs.append(name) missing_reqs.append(name)
else: else:
build_inputs[component] = attr_paths build_inputs[component] = (attr_paths, missing_reqs)
n_diff = len(reqs) > len(build_inputs[component]) n_diff = len(reqs) > len(build_inputs[component])
if n_diff > 0: if n_diff > 0:
print("Component {} is missing {} dependencies".format(component, n_diff)) print("Component {} is missing {} dependencies".format(component, n_diff))
@ -156,9 +160,16 @@ with open(os.path.dirname(sys.argv[0]) + "/component-packages.nix", "w") as f:
f.write("{\n") f.write("{\n")
f.write(f' version = "{version}";\n') f.write(f' version = "{version}";\n')
f.write(" components = {\n") f.write(" components = {\n")
for component, attr_paths in build_inputs.items(): for component, deps in build_inputs.items():
f.write(' "{component}" = ps: with ps; [ ') available, missing = deps
f.write(" ".join(attr_paths)) f.write(f" \"{component}\" = ps: with ps; [ ")
f.write(" ];\n") f.write(" ".join(available))
f.write("];")
if len(missing) > 0:
f.write(f" # missing inputs: {' '.join(missing)}")
f.write("\n")
f.write(" };\n") f.write(" };\n")
f.write("}\n") f.write("}\n")
if __name__ == '__main__':
main()