Skip to content

Commit

Permalink
Revert "Add pyright type checking to pylint GH action. (#115)" (#125)
Browse files Browse the repository at this point in the history
This reverts commit 9ea503d.
  • Loading branch information
huchenlei authored Jul 17, 2024
1 parent d0ecad2 commit 7313679
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 78 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint & Type Check
name: Lint

on:
push:
Expand All @@ -17,14 +17,10 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Lint with Pylint
run: pylint --disable=R **/*.py
- uses: jakebailey/pyright-action@v2
with:
pylance-version: latest-release
28 changes: 4 additions & 24 deletions DEV_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ This guide provides an overview of how to develop in this repository.

1. Clone the repo, create and activate a conda env. Minimum Python version is 3.9.

1. Install the package to local
2. Install the package to local

`pip install -e .`

1. Set ENVIRONMENT variable to DEV.

1. Install Dev Requirements

`pip install -r requirements-dev.txt`
3. Set ENVIRONMENT variable to DEV.

`export ENVIRONMENT=dev`

1. Test script running
4. Test script running

`comfy --help`

1. Use pre commit hook
5. Use pre commit hook

`pre-commit install`

Expand All @@ -41,22 +37,6 @@ You can add following config to your VSCode `launch.json` to launch debugger.
}
```

## Linting and Type Checking

Here is the recommended VScode settings. We use Black to format python code. We use Pylance's to do some basic type checking.

```
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic"
}
```

## Make changes to the code base

There is a potential need for you to reinstall the package. You can do this by
Expand Down
45 changes: 12 additions & 33 deletions comfy_cli/command/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@


def get_workspace() -> pathlib.Path:
if workspace_manager.workspace_path is None:
print("[bold red]Error: Workspace not set.")
raise typer.Exit(code=1)
return pathlib.Path(workspace_manager.workspace_path)


Expand All @@ -46,7 +43,7 @@ def check_huggingface_url(url: str) -> bool:
return "huggingface.co" in url


def check_civitai_url(url: str) -> Tuple[bool, bool, Optional[int], Optional[int]]:
def check_civitai_url(url: str) -> Tuple[bool, bool, int, int]:
"""
Returns:
is_civitai_model_url: True if the url is a civitai model url
Expand Down Expand Up @@ -81,9 +78,7 @@ def check_civitai_url(url: str) -> Tuple[bool, bool, Optional[int], Optional[int
return False, False, None, None


def request_civitai_model_version_api(
version_id: int, headers: Optional[dict] = None
) -> Optional[Tuple[str, str, str, str]]:
def request_civitai_model_version_api(version_id: int, headers: Optional[dict] = None):
# Make a request to the Civitai API to get the model information
response = requests.get(
f"https://civitai.com/api/v1/model-versions/{version_id}",
Expand All @@ -100,12 +95,11 @@ def request_civitai_model_version_api(
model_type = model_data["model"]["type"].lower()
basemodel = model_data["baseModel"].replace(" ", "")
return model_name, download_url, model_type, basemodel
return None


def request_civitai_model_api(
model_id: int, version_id: Optional[int] = None, headers: Optional[dict] = None
) -> Tuple[str, str, str, str]:
model_id: int, version_id: int = None, headers: Optional[dict] = None
):
# Make a request to the Civitai API to get the model information
response = requests.get(
f"https://civitai.com/api/v1/models/{model_id}", headers=headers, timeout=10
Expand Down Expand Up @@ -185,8 +179,6 @@ def download(
)

if is_civitai_model_url:
if model_id is None:
raise ValueError("Model ID is required for Civitai model URL")
local_filename, url, model_type, basemodel = request_civitai_model_api(
model_id, version_id, headers
)
Expand All @@ -198,17 +190,14 @@ def download(
model_path = ui.prompt_input(
"Enter model type path (e.g. loras, checkpoints, ...)", default=""
)
if model_path is None:
raise ValueError("Model type path is required")

relative_path = os.path.join(
DEFAULT_COMFY_MODEL_PATH, model_path, basemodel
)
elif is_civitai_api_url and version_id is not None:
result = request_civitai_model_version_api(version_id, headers)
if result is None:
raise ValueError("Model information not found")
local_filename, url, model_type, basemodel = result
elif is_civitai_api_url:
local_filename, url, model_type, basemodel = request_civitai_model_version_api(
version_id, headers
)

model_path = model_path_map.get(model_type)

Expand All @@ -217,8 +206,6 @@ def download(
model_path = ui.prompt_input(
"Enter model type path (e.g. loras, checkpoints, ...)", default=""
)
if model_path is None:
raise ValueError("Model type path is required")

relative_path = os.path.join(
DEFAULT_COMFY_MODEL_PATH, model_path, basemodel
Expand All @@ -230,26 +217,18 @@ def download(
model_path = ui.prompt_input(
"Enter model type path (e.g. loras, checkpoints, ...)", default=""
)
if model_path is None:
raise ValueError("Model type path is required")
basemodel = ui.prompt_input(
"Enter base model (e.g. SD1.5, SDXL, ...)", default=""
)
if basemodel is None:
raise ValueError("Mode name is required")

relative_path = os.path.join(
DEFAULT_COMFY_MODEL_PATH, model_path, basemodel
)
else:
print("Model source is unknown")

if local_filename is None:
local_filename = ui.prompt_input("Enter filename to save model as")
else:
local_filename = ui.prompt_input(
"Enter filename to save model as", default=local_filename
)
local_filename = ui.prompt_input(
"Enter filename to save model as", default=local_filename
)

if relative_path is None:
relative_path = DEFAULT_COMFY_MODEL_PATH
Expand Down Expand Up @@ -359,6 +338,6 @@ def list(
ui.display_table(data, column_names)


def list_models(path: pathlib.Path) -> List[pathlib.Path]:
def list_models(path: pathlib.Path) -> list:
"""List all models in the specified directory."""
return [file for file in path.iterdir() if file.is_file()]
13 changes: 4 additions & 9 deletions comfy_cli/tracking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import logging as logginglib
import uuid
from typing import Any, Optional

import typer
from mixpanel import Mixpanel

Expand Down Expand Up @@ -41,7 +41,7 @@ def disable():
typer.echo(f"Tracking is now {'disabled'}.")


def track_event(event_name: str, properties: Any = None):
def track_event(event_name: str, properties: any = None):
if properties is None:
properties = {}
logging.debug(
Expand All @@ -54,17 +54,12 @@ def track_event(event_name: str, properties: Any = None):
try:
properties["cli_version"] = cli_version
properties["tracing_id"] = tracing_id
if mp:
mp.track(distinct_id=user_id, event_name=event_name, properties=properties)
else:
logging.debug(
f"Mixpanel token not found. Skipping tracking event: {event_name}"
)
mp.track(distinct_id=user_id, event_name=event_name, properties=properties)
except Exception as e:
logging.warning(f"Failed to track event: {e}") # Log the error but do not raise


def track_command(sub_command: Optional[str] = None):
def track_command(sub_command: str = None):
"""
A decorator factory that logs the command function name and selected arguments when it's called.
"""
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt

This file was deleted.

6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ typer>=0.9.0
rich
GitPython
requests
types-requests
pyyaml
types-PyYAML
typing-extensions>=4.7.0
questionary
mixpanel
Expand All @@ -14,6 +12,4 @@ httpx
packaging
charset-normalizer>=3.0.0
websocket-client
psutil
types-psutil

psutil

0 comments on commit 7313679

Please sign in to comment.