Skip to content

Commit

Permalink
remove the cli-version retrieval logic from pyproject.toml (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
james03160927 authored May 8, 2024
1 parent 283e337 commit c3b66a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
28 changes: 4 additions & 24 deletions comfy_cli/config_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import configparser
import os

import tomlkit

from comfy_cli.utils import singleton, get_os, is_running
from comfy_cli import constants, logging
from typing import Optional, Tuple
Expand All @@ -20,11 +18,6 @@ def __init__(self):
def get_config_path():
return constants.DEFAULT_CONFIG[get_os()]

@staticmethod
def get_pyproject_path():
# TODO: check if this works for homebrew and pip installed comfy-cli as well.
return os.path.join(os.path.dirname(__file__), "../pyproject.toml")

def get_config_file_path(self):
return os.path.join(self.get_config_path(), "config.ini")

Expand Down Expand Up @@ -126,26 +119,13 @@ def remove_background(self):
self.background = None

def get_cli_version(self):
# First, try reading from pyproject.toml
try:
with open(self.get_pyproject_path(), "r") as f:
pyproject_toml_content = f.read()
parsed_toml = tomlkit.parse(pyproject_toml_content)
return parsed_toml["project"]["version"]
except FileNotFoundError:
logging.debug("pyproject.toml not found.")
except KeyError:
logging.warning("Version key not found in pyproject.toml.")
except Exception as e:
logging.warning(
f"Error occurred while retrieving CLI version from pyproject.toml: {e}"
)

# If the above fails, fall back to using importlib.metadata
# Note: this approach should work for users installing the CLI via PyPi (e.g., pip install comfy-cli)
try:
return version("comfy-cli")
except Exception as e:
logging.debug(
f"Error occurred while retrieving CLI version using importlib.metadata: {e}"
)
return "unknown"

# TODO: cover the users installing the CLI via homebrew
return "0.0.0"
5 changes: 3 additions & 2 deletions comfy_cli/tracking.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import functools
import logging as logginglib
import os
import uuid
import logging as logginglib
from mixpanel import Mixpanel, MixpanelException

import typer
from mixpanel import Mixpanel

from comfy_cli import logging, ui, constants
from comfy_cli.config_manager import ConfigManager

Expand Down

0 comments on commit c3b66a4

Please sign in to comment.