Skip to content

Commit 42f7986

Browse files
authored
fix: version check failure (#43)
* use metadata instead of reading pyproject.toml #42 * version compare based on packaging.version
1 parent b2b0dea commit 42f7986

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

comfy_cli/update.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import tomlkit.exceptions
55
from rich.console import Console
66
from rich.panel import Panel
7+
from importlib.metadata import metadata
8+
from packaging import version
9+
710

811
console = Console()
912

@@ -14,7 +17,11 @@ def check_for_newer_pypi_version(package_name, current_version):
1417
response = requests.get(url)
1518
response.raise_for_status() # Raises stored HTTPError, if one occurred
1619
latest_version = response.json()["info"]["version"]
17-
return latest_version != current_version, latest_version
20+
21+
if version.parse(latest_version) > version.parse(current_version):
22+
return True, latest_version
23+
24+
return False, current_version
1825
except requests.RequestException as e:
1926
# print(f"Error checking latest version: {e}")
2027
return False, current_version
@@ -30,25 +37,9 @@ def check_for_updates():
3037
notify_update(current_version, newer_version)
3138

3239

33-
def get_version_from_pyproject(file_path="pyproject.toml"):
34-
try:
35-
with open(file_path, "r", encoding="utf-8") as file:
36-
toml_content = file.read()
37-
parsed_toml = tomlkit.parse(toml_content)
38-
# Accessing the project version under [project]
39-
if "project" in parsed_toml:
40-
version = parsed_toml["project"]["version"]
41-
else:
42-
raise KeyError(
43-
"Version key not found under [project] in pyproject.toml"
44-
)
45-
return version
46-
except FileNotFoundError:
47-
print(f"Error: The file '{file_path}' does not exist.")
48-
except tomlkit.exceptions.TOMLKitError as e:
49-
print(f"Error parsing TOML: {e}")
50-
except KeyError as e:
51-
print(f"Error accessing version in TOML: {e}")
40+
def get_version_from_pyproject():
41+
package_metadata = metadata("comfy-cli")
42+
return package_metadata["Version"]
5243

5344

5445
def notify_update(current_version: str, newer_version: str):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies = [
3131
"tomlkit",
3232
"pathspec",
3333
"httpx",
34+
"packaging",
3435
]
3536

3637
classifiers = [

0 commit comments

Comments
 (0)