From 4d3112e9e8eae96791769ec427df5b23db3fad62 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 12:43:55 +0200 Subject: [PATCH 01/10] Mod: remove unneded else statement --- src/leek/mod.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/leek/mod.py b/src/leek/mod.py index 73d7db0..ca06c2a 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -61,8 +61,7 @@ class Mod: if "enabled" not in self.__config: raise InvalidModError("config.toml does not contain the enabled key") - else: - self.__enabled = self.__config.get("enabled", bool) + self.__enabled = self.__config.get("enabled", bool) except FileNotFoundError: raise InvalidModError("config.toml does not exist") From 4d22e68a9b8dd24e601968d7c94d58ff6f9bf002 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 17:21:54 +0200 Subject: [PATCH 02/10] Mod: parse meta.json if it exists --- src/leek/mod.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index ca06c2a..84d0ddc 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -1,10 +1,16 @@ import tomlkit +import json from pathlib import Path from tomlkit import TOMLDocument +from typing import Any class Mod: __config: TOMLDocument + + __has_meta_json: bool + __meta: dict[str, Any] + __path: Path __name: str __description: str @@ -53,6 +59,7 @@ class Mod: def __init__(self, path: Path) -> None: self.__path = path + self.__meta = {} try: config_toml = Path(self.__path, "config.toml") @@ -65,6 +72,17 @@ class Mod: except FileNotFoundError: raise InvalidModError("config.toml does not exist") + meta_json: Path = Path(self.__path, "meta.json") + if meta_json.exists(): + self.__has_meta_json = True + try: + with meta_json.open() as file: + self.__meta = json.load(file) + except json.JSONDecodeError as e: + print("Failed to parse meta.json!: ", e.msg) + else: + self.__has_meta_json = False + def __str__(self) -> str: return f"Mod({self.__path})" From 902227a8bd36a783675c8a84fcc2708621b02668 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 18:50:01 +0200 Subject: [PATCH 03/10] Mod: read name, description and authors from json if available --- src/leek/mod.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index 84d0ddc..bbe2cab 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -24,12 +24,18 @@ class Mod: # Mod metadata @property def name(self) -> str | None: + if self.__has_meta_json: + if "name" in self.__meta: + return self.__meta.get("name", str) if "name" not in self.__config: return None return self.__config.get("name", str) @property def description(self) -> str | None: + if self.__has_meta_json: + if "description" in self.__meta: + return self.__meta.get("description", str) if "description" not in self.__config.keys(): return None else: @@ -37,6 +43,11 @@ class Mod: @property def author(self) -> str | None: + # TODO: return list with authors + if self.__has_meta_json: + if "authors" in self.__meta: + authors: list[str] = self.__meta.get("authors", list[str]) + return ", ".join(authors) if "author" not in self.__config: return None return self.__config.get("author", str) From 8a3661729823a6c101b5f8f5e6e7eedf04702781 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 19:08:59 +0200 Subject: [PATCH 04/10] Mod, QMod: add long description property --- src/leek/mod.py | 6 ++++++ src/leek/qmod.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index bbe2cab..3e0809b 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -41,6 +41,12 @@ class Mod: else: return self.__config.get("description", str) + @property + def long_description(self) -> str | None: + if "descriptionLong" in self.__meta: + return self.__meta.get("descriptionLong", str) + return None + @property def author(self) -> str | None: # TODO: return list with authors diff --git a/src/leek/qmod.py b/src/leek/qmod.py index 74db253..a67c1dc 100644 --- a/src/leek/qmod.py +++ b/src/leek/qmod.py @@ -9,6 +9,8 @@ QML_IMPORT_NAME = "Leek" QML_IMPORT_MAJOR_VERSION = 1 +# Qt follows C++ naming conventions +# ruff: noqa: N802 @QmlElement @QmlUncreatable("QMod is intended to be returned by a QModListModel") class QMod(QObject): @@ -34,6 +36,10 @@ class QMod(QObject): def description(self) -> str | None: return self.__mod.description + @Property(str, constant=True) + def longDescription(self) -> str | None: + return self.__mod.long_description + mod_enabled = Signal(name="enabled") @Property(bool, notify=mod_enabled) From f07bd103067892f4789ab42253475d2ba898dc83 Mon Sep 17 00:00:00 2001 From: Toast Date: Fri, 30 May 2025 12:13:33 +0200 Subject: [PATCH 05/10] Qml/main: add a not implemented dialog to the delete button --- src/leek/qml/Main.qml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/leek/qml/Main.qml b/src/leek/qml/Main.qml index 576034c..a06690e 100644 --- a/src/leek/qml/Main.qml +++ b/src/leek/qml/Main.qml @@ -83,6 +83,16 @@ Kirigami.ApplicationWindow { } Controls.Button { text: "Delete" + onClicked: notImplementedDialog.open() + Kirigami.Dialog { + id: notImplementedDialog + title: "Not implemented!" + standardButtons: Kirigami.Dialog.Ok + padding: Kirigami.Units.largeSpacing + Controls.Label { + text: "Deleting is not implemented yet" + } + } } } } From bd6068d2635fda327dc3948f4eed0ce963e60a89 Mon Sep 17 00:00:00 2001 From: Toast Date: Fri, 30 May 2025 12:44:04 +0200 Subject: [PATCH 06/10] Nix: set package version to git rev --- flake.nix | 6 ++++-- package.nix | 14 +++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index 6de1c94..4676780 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - outputs = { nixpkgs, ... }: + outputs = { nixpkgs, self, ... }: let pkgs = nixpkgs.legacyPackages.x86_64-linux; lib = nixpkgs.lib; @@ -27,7 +27,9 @@ }; packages.x86_64-linux = rec { default = leek; - leek = pkgs.callPackage ./package.nix { }; + leek = pkgs.callPackage ./package.nix { + gitRev = self.sourceInfo.shortRev or self.sourceInfo.dirtyShortRev; + }; }; }; } diff --git a/package.nix b/package.nix index 95fca94..fa4b5e3 100644 --- a/package.nix +++ b/package.nix @@ -1,10 +1,10 @@ -{ - kdePackages, - python3Packages, - qt6 +{ kdePackages +, python3Packages +, qt6 +, gitRev ? "dirty" }: python3Packages.buildPythonApplication rec { pname = "leek"; - version = "0.0.1"; + version = gitRev; pyproject = true; src = ./.; @@ -13,7 +13,7 @@ python3Packages.setuptools ]; - + dependencies = with python3Packages; [ pyside6 tomlkit @@ -25,7 +25,7 @@ propagatedBuildInputs = [ kdePackages.kirigami - ]; + ]; makeWrapperArgs = [ "\${qtWrapperArgs[@]}" From 56165d0cef45dfbe99ec1dcce812529b61026f1c Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 12:43:55 +0200 Subject: [PATCH 07/10] Mod: remove unneded else statement --- src/leek/mod.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/leek/mod.py b/src/leek/mod.py index 73d7db0..ca06c2a 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -61,8 +61,7 @@ class Mod: if "enabled" not in self.__config: raise InvalidModError("config.toml does not contain the enabled key") - else: - self.__enabled = self.__config.get("enabled", bool) + self.__enabled = self.__config.get("enabled", bool) except FileNotFoundError: raise InvalidModError("config.toml does not exist") From bfefcd757e01f170a905ce67b1f7239fbe3998ce Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 17:21:54 +0200 Subject: [PATCH 08/10] Mod: parse meta.json if it exists --- src/leek/mod.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index ca06c2a..84d0ddc 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -1,10 +1,16 @@ import tomlkit +import json from pathlib import Path from tomlkit import TOMLDocument +from typing import Any class Mod: __config: TOMLDocument + + __has_meta_json: bool + __meta: dict[str, Any] + __path: Path __name: str __description: str @@ -53,6 +59,7 @@ class Mod: def __init__(self, path: Path) -> None: self.__path = path + self.__meta = {} try: config_toml = Path(self.__path, "config.toml") @@ -65,6 +72,17 @@ class Mod: except FileNotFoundError: raise InvalidModError("config.toml does not exist") + meta_json: Path = Path(self.__path, "meta.json") + if meta_json.exists(): + self.__has_meta_json = True + try: + with meta_json.open() as file: + self.__meta = json.load(file) + except json.JSONDecodeError as e: + print("Failed to parse meta.json!: ", e.msg) + else: + self.__has_meta_json = False + def __str__(self) -> str: return f"Mod({self.__path})" From da8749e1a79dd94578e0fd79bf1f38fdbba869bf Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 18:50:01 +0200 Subject: [PATCH 09/10] Mod: read name, description and authors from json if available --- src/leek/mod.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index 84d0ddc..bbe2cab 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -24,12 +24,18 @@ class Mod: # Mod metadata @property def name(self) -> str | None: + if self.__has_meta_json: + if "name" in self.__meta: + return self.__meta.get("name", str) if "name" not in self.__config: return None return self.__config.get("name", str) @property def description(self) -> str | None: + if self.__has_meta_json: + if "description" in self.__meta: + return self.__meta.get("description", str) if "description" not in self.__config.keys(): return None else: @@ -37,6 +43,11 @@ class Mod: @property def author(self) -> str | None: + # TODO: return list with authors + if self.__has_meta_json: + if "authors" in self.__meta: + authors: list[str] = self.__meta.get("authors", list[str]) + return ", ".join(authors) if "author" not in self.__config: return None return self.__config.get("author", str) From bb858ef2614d6c9370212108491e32b5e3f830c5 Mon Sep 17 00:00:00 2001 From: Toast Date: Thu, 29 May 2025 19:08:59 +0200 Subject: [PATCH 10/10] Mod, QMod: add long description property --- src/leek/mod.py | 6 ++++++ src/leek/qmod.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/leek/mod.py b/src/leek/mod.py index bbe2cab..3e0809b 100644 --- a/src/leek/mod.py +++ b/src/leek/mod.py @@ -41,6 +41,12 @@ class Mod: else: return self.__config.get("description", str) + @property + def long_description(self) -> str | None: + if "descriptionLong" in self.__meta: + return self.__meta.get("descriptionLong", str) + return None + @property def author(self) -> str | None: # TODO: return list with authors diff --git a/src/leek/qmod.py b/src/leek/qmod.py index 74db253..a67c1dc 100644 --- a/src/leek/qmod.py +++ b/src/leek/qmod.py @@ -9,6 +9,8 @@ QML_IMPORT_NAME = "Leek" QML_IMPORT_MAJOR_VERSION = 1 +# Qt follows C++ naming conventions +# ruff: noqa: N802 @QmlElement @QmlUncreatable("QMod is intended to be returned by a QModListModel") class QMod(QObject): @@ -34,6 +36,10 @@ class QMod(QObject): def description(self) -> str | None: return self.__mod.description + @Property(str, constant=True) + def longDescription(self) -> str | None: + return self.__mod.long_description + mod_enabled = Signal(name="enabled") @Property(bool, notify=mod_enabled)