refactor(hass): cleanup and use python3Packages.callPkg

This commit is contained in:
matt1432 2025-04-07 10:36:30 -04:00
parent 7003519e18
commit a4064bf1b1
16 changed files with 57 additions and 121 deletions
packages/coloryou/coloryou
scopedPackages/hass-components
default.nix
extended-ollama-conversation
material-symbols
netdaemon
spotifyplus
tuya-local
yamaha-soundbar

File diff suppressed because one or more lines are too long

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python
"""
The original script:
https://github.com/dharmx/vile/blob/7d486c128c7e553912673755f97b118aaab0193d/src/shell/playerctl.py#L2
"""
import argparse
import json
from material_color_utilities_python import themeFromImage, hexFromArgb, Image
def range_type(value_string):
value = int(value_string)
if value not in range(0, 101):
raise argparse.ArgumentTypeError("%s is out of range, choose in [0-100]" % value)
return value
parser = argparse.ArgumentParser(
prog='coloryou',
description='This program extract Material You colors from an image. It returns them as a JSON object for scripting.')
parser.add_argument("image_path", help="A full path to your image", type=str)
parser.add_argument('-i', '--image', dest='image', default=40, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the main image accent.")
parser.add_argument('-b', '--button', dest='button', default=90, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the button accent.")
parser.add_argument('-t', '--text', dest='text', default=10, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the button text accent.")
parser.add_argument('-o', '--hover', dest='hover', default=80, type=range_type, metavar='i', choices=range(0,101), help="Value should be within [0, 100] (default: %(default)s). Set the tone for the hovering effect accent.")
args = parser.parse_args()
img = Image.open(args.image_path)
basewidth = 64
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize),Image.Resampling.LANCZOS)
theme = themeFromImage(img).get("palettes").get("primary")
parsed_colors = {"imageAccent": hexFromArgb(theme.tone(args.image)),
"buttonAccent": hexFromArgb(theme.tone(args.button)),
"buttonText": hexFromArgb(theme.tone(args.text)),
"hoverAccent": hexFromArgb(theme.tone(args.hover))}
print(json.dumps(parsed_colors))

View file

@ -1,19 +0,0 @@
{python3Packages}:
python3Packages.buildPythonPackage rec {
pname = "coloryou";
version = "0.0.1";
src = ./.;
propagatedBuildInputs = with python3Packages; [utils material-color-utilities];
postInstall = ''
mv -v $out/bin/coloryou.py $out/bin/coloryou
'';
meta = {
description = ''
Get Material You colors from an image.
'';
};
}

View file

@ -1,2 +0,0 @@
material-color-utilities
utils

View file

@ -1,7 +0,0 @@
from distutils.core import setup
setup(
name='coloryou',
version='0.0.1',
scripts=['coloryou.py',],
)

View file

@ -1,7 +0,0 @@
with import <nixpkgs> {};
with pkgs.python311Packages;
buildPythonPackage rec {
name = "coloryou";
src = ./.;
propagatedBuildInputs = [material-color-utilities utils];
}

View file

@ -8,14 +8,14 @@ lib.makeScope pkgs.newScope (hass: let
inherit (self.lib) mergeAttrsList; inherit (self.lib) mergeAttrsList;
python3Packages = pkgs.python313Packages.override { python3Packages = pkgs.python313Packages.override {
overrides = final: prev: (mergeAttrsList (map (x: x python3Packages final prev) [ overrides = final: prev: (mergeAttrsList (map (fn: fn python3Packages final prev) [
(import ./spotifyplus/overrides.nix ({inherit pkgs;} // inputs)) (import ./spotifyplus/overrides.nix ({inherit pkgs;} // inputs))
(import ./tuya-local/overrides.nix {inherit pkgs;}) (import ./tuya-local/overrides.nix {inherit pkgs;})
])); ]));
}; };
buildHassComponent = file: extraArgs: buildHassComponent = file: extraArgs:
hass.callPackage file (inputs // extraArgs // {inherit python3Packages;}); python3Packages.callPackage file (inputs // extraArgs // {});
in { in {
extended-ollama-conversation = buildHassComponent ./extended-ollama-conversation {}; extended-ollama-conversation = buildHassComponent ./extended-ollama-conversation {};

View file

@ -3,30 +3,26 @@
buildHomeAssistantComponent, buildHomeAssistantComponent,
extended-ollama-conversation-src, extended-ollama-conversation-src,
# deps # deps
python3Packages, ollama,
openai,
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${extended-ollama-conversation-src}/custom_components/extended_ollama_conversation/manifest.json"); manifest = fromJSON (readFile "${extended-ollama-conversation-src}/custom_components/extended_ollama_conversation/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {
owner = "TheNimaj"; owner = "TheNimaj";
inherit (manifest) domain version; inherit (manifest) domain version;
src = extended-ollama-conversation-src; src = extended-ollama-conversation-src;
prePatch = '' dependencies = [
substituteInPlace ./custom_components/extended_ollama_conversation/manifest.json \
--replace-warn "ollama~=0.3.0" "ollama>=0.3.0"
'';
propagatedBuildInputs = with python3Packages; [
ollama ollama
openai openai
]; ];
ignoreVersionRequirement = ["ollama"];
meta = { meta = {
homepage = "https://github.com/TheNimaj/extended_ollama_conversation"; homepage = "https://github.com/TheNimaj/extended_ollama_conversation";
description = '' description = ''

View file

@ -6,7 +6,6 @@
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${material-symbols-src}/custom_components/material_symbols/manifest.json"); manifest = fromJSON (readFile "${material-symbols-src}/custom_components/material_symbols/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {

View file

@ -4,21 +4,19 @@
buildHomeAssistantComponent, buildHomeAssistantComponent,
netdaemon-src, netdaemon-src,
# deps # deps
python3Packages, awesomeversion,
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${netdaemon-src}/custom_components/netdaemon/manifest.json"); manifest = fromJSON (readFile "${netdaemon-src}/custom_components/netdaemon/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {
owner = "net-daemon"; owner = "net-daemon";
inherit (manifest) domain version; inherit (manifest) domain version;
src = netdaemon-src; src = netdaemon-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
awesomeversion awesomeversion
]; ];

View file

@ -4,21 +4,27 @@
buildHomeAssistantComponent, buildHomeAssistantComponent,
spotifyplus-src, spotifyplus-src,
# deps # deps
python3Packages, oauthlib,
platformdirs,
requests,
requests_oauthlib,
soco,
urllib3,
zeroconf,
smartinspect, # overridden in python3Packages
spotifywebapi, # overridden in python3Packages
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${spotifyplus-src}/custom_components/spotifyplus/manifest.json"); manifest = fromJSON (readFile "${spotifyplus-src}/custom_components/spotifyplus/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {
owner = "thlucas1"; owner = "thlucas1";
inherit (manifest) domain version; inherit (manifest) domain version;
src = spotifyplus-src; src = spotifyplus-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
oauthlib oauthlib
platformdirs platformdirs
requests requests
@ -26,10 +32,14 @@ in
soco soco
urllib3 urllib3
zeroconf zeroconf
smartinspect # overridden in python3Packages smartinspect
spotifywebapi # overridden in python3Packages spotifywebapi
]; ];
# Upstream sometimes forgets to bump version number.
# Since we're guaranteed to have lastest git, this is safe
ignoreVersionRequirement = ["spotifywebapipython"];
meta = { meta = {
license = lib.licenses.mit; license = lib.licenses.mit;
homepage = "https://github.com/thlucas1/homeassistantcomponent_spotifyplus"; homepage = "https://github.com/thlucas1/homeassistantcomponent_spotifyplus";

View file

@ -4,11 +4,11 @@
pkgs, pkgs,
... ...
}: python3Packages: final: prev: rec { }: python3Packages: final: prev: rec {
smartinspect = pkgs.callPackage ./smartinspect.nix { smartinspect = python3Packages.callPackage ./smartinspect.nix {
inherit python3Packages smartinspect-src; inherit smartinspect-src;
}; };
spotifywebapi = pkgs.callPackage ./spotifywebapi.nix { spotifywebapi = python3Packages.callPackage ./spotifywebapi.nix {
inherit python3Packages smartinspect spotifywebapi-src; inherit smartinspect spotifywebapi-src;
}; };
urllib3 = pkgs.selfPackages.urllib3.override { urllib3 = pkgs.selfPackages.urllib3.override {
inherit python3Packages; inherit python3Packages;

View file

@ -1,21 +1,23 @@
{ {
# nix build inputs # nix build inputs
lib, lib,
buildPythonPackage,
smartinspect-src, smartinspect-src,
# deps # deps
python3Packages, pycryptodome,
watchdog,
... ...
}: let }: let
inherit (builtins) elemAt head readFile split; inherit (builtins) elemAt head readFile split;
tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${smartinspect-src}/smartinspectpython/siconst.py")) 2)); tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${smartinspect-src}/smartinspectpython/siconst.py")) 2));
in in
python3Packages.buildPythonPackage { buildPythonPackage {
pname = "smartinspectPython"; pname = "smartinspectPython";
version = "${tag}+${smartinspect-src.shortRev}"; version = "${tag}+${smartinspect-src.shortRev}";
src = smartinspect-src; src = smartinspect-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
pycryptodome pycryptodome
watchdog watchdog
]; ];

View file

@ -1,22 +1,34 @@
{ {
# nix build inputs # nix build inputs
lib, lib,
buildPythonPackage,
spotifywebapi-src, spotifywebapi-src,
# deps # deps
python3Packages, lxml,
oauthlib,
platformdirs,
pychromecast,
pyotp,
requests,
requests_oauthlib,
setuptools,
soco,
urllib3,
zeroconf,
smartinspect, # overridden in python3Packages
... ...
}: let }: let
inherit (builtins) elemAt head readFile split; inherit (builtins) elemAt head readFile split;
tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${spotifywebapi-src}/spotifywebapipython/const.py")) 2)); tag = head (split "\"" (elemAt (split "VERSION:str = \"" (readFile "${spotifywebapi-src}/spotifywebapipython/const.py")) 2));
in in
python3Packages.buildPythonPackage { buildPythonPackage {
pname = "spotifywebapiPython"; pname = "spotifywebapiPython";
version = "${tag}+${spotifywebapi-src.shortRev}"; version = "${tag}+${spotifywebapi-src.shortRev}";
pyproject = true; pyproject = true;
src = spotifywebapi-src; src = spotifywebapi-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
lxml lxml
oauthlib oauthlib
platformdirs platformdirs
@ -28,7 +40,7 @@ in
soco soco
urllib3 urllib3
zeroconf zeroconf
smartinspect # overridden in python3Packages smartinspect
]; ];
pythonImportsCheck = [ pythonImportsCheck = [

View file

@ -4,21 +4,20 @@
buildHomeAssistantComponent, buildHomeAssistantComponent,
tuya-local-src, tuya-local-src,
# deps # deps
python3Packages, tinytuya,
tuya-device-sharing-sdk,
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${tuya-local-src}/custom_components/tuya_local/manifest.json"); manifest = fromJSON (readFile "${tuya-local-src}/custom_components/tuya_local/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {
owner = "make-all"; owner = "make-all";
inherit (manifest) domain version; inherit (manifest) domain version;
src = tuya-local-src; src = tuya-local-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
tinytuya tinytuya
tuya-device-sharing-sdk tuya-device-sharing-sdk
]; ];

View file

@ -3,11 +3,12 @@
buildHomeAssistantComponent, buildHomeAssistantComponent,
yamaha-soundbar-src, yamaha-soundbar-src,
# deps # deps
python3Packages, async-upnp-client,
chardet,
validators,
... ...
}: let }: let
inherit (builtins) fromJSON readFile; inherit (builtins) fromJSON readFile;
manifest = fromJSON (readFile "${yamaha-soundbar-src}/custom_components/yamaha_soundbar/manifest.json"); manifest = fromJSON (readFile "${yamaha-soundbar-src}/custom_components/yamaha_soundbar/manifest.json");
in in
buildHomeAssistantComponent { buildHomeAssistantComponent {
@ -16,7 +17,7 @@ in
inherit (manifest) domain version; inherit (manifest) domain version;
src = yamaha-soundbar-src; src = yamaha-soundbar-src;
propagatedBuildInputs = with python3Packages; [ dependencies = [
async-upnp-client async-upnp-client
chardet chardet
validators validators