Extract pipx_installed to standalone
MODIFY
plextraktsync/commands/self_update.py
plextraktsync/commands/self_update.py
-import json
-from json import JSONDecodeError
from os import system
import click
-from plextraktsync.util.execx import execx
-
-
-def pipx_installed(package: str):
- try:
- output = execx("pipx list --json")
- except FileNotFoundError:
- return None
- if not output:
- return None
-
- try:
- install_data = json.loads(output)
- except JSONDecodeError:
- return None
- if install_data is None:
- return None
-
- try:
- package = install_data["venvs"][package]["metadata"]["main_package"]
- except KeyError:
- return None
-
- return package
-
def enable_self_update():
+ from plextraktsync.util.packaging import pipx_installed
+
package = pipx_installed("plextraktsync")
return package is not None

MODIFY
plextraktsync/util/packaging.py
plextraktsync/util/packaging.py
+import json
import site
+from json import JSONDecodeError
from os.path import dirname
+from plextraktsync.util.execx import execx
+
def installed():
"""
@@ -10,3 +14,26 @@ def installed():
paths = site.getsitepackages()
return absdir in paths
+
+
+def pipx_installed(package: str):
+ try:
+ output = execx("pipx list --json")
+ except FileNotFoundError:
+ return None
+ if not output:
+ return None
+
+ try:
+ install_data = json.loads(output)
+ except JSONDecodeError:
+ return None
+ if install_data is None:
+ return None
+
+ try:
+ package = install_data["venvs"][package]["metadata"]["main_package"]
+ except KeyError:
+ return None
+
+ return package

Extract pipx_installed to standalone