Fix pylint issue with hydit, fix absolute versus relative imports

This commit is contained in:
doctorpangloss 2024-08-16 13:06:33 -07:00
parent 653a970088
commit a6a080487f
6 changed files with 51 additions and 8 deletions

View File

@ -52,7 +52,7 @@ ignore=CVS
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\\' represents the directory delimiter on Windows systems,
# it can't be used as an escape character.
ignore-paths=
ignore-paths=^comfy/api/.*$
# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
@ -64,7 +64,7 @@ ignore-patterns=^\.#
# manipulated during runtime and thus existing member attributes cannot be
# deduced by static analysis). It supports qualified module names, as well as
# Unix pattern matching.
ignored-modules=sentencepiece.*
ignored-modules=sentencepiece.*,comfy.api
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
@ -82,7 +82,7 @@ limit-inference-results=100
# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=
load-plugins=tests.absolute_import_checker
# Pickle collected data for later comparisons.
persistent=yes
@ -677,8 +677,7 @@ disable=raw-checker-failed,
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
enable=
enable=absolute-import-used
[METHOD_ARGS]

View File

@ -5,7 +5,7 @@ class _RoutesWrapper:
def _decorator_factory(self, method):
def decorator(path):
def wrapper(func):
from comfy.cmd.server import PromptServer
from ..cmd.server import PromptServer
if PromptServer.instance is not None:
getattr(PromptServer.instance.routes, method)(path)(func)
self.routes.append((method, path, func))

View File

@ -89,7 +89,7 @@ class ModelManageable(Protocol):
return self.model_size()
def memory_required(self, input_shape) -> int:
from comfy.model_base import BaseModel
from .model_base import BaseModel
if isinstance(self.model, BaseModel):
return self.model.memory_required(input_shape=input_shape)

View File

@ -103,7 +103,7 @@ def _import_and_enumerate_nodes_in_module(module: types.ModuleType,
@tracer.start_as_current_span("Import All Nodes In Workspace")
def import_all_nodes_in_workspace(vanilla_custom_nodes=True, raise_on_failure=False) -> ExportedNodes:
# now actually import the nodes, to improve control of node loading order
from comfy_extras import nodes as comfy_extras_nodes
from comfy_extras import nodes as comfy_extras_nodes # pylint: disable=absolute-import-used
from ..cli_args import args
from . import base_nodes
from .vanilla_node_importing import mitigated_import_of_vanilla_custom_nodes

View File

@ -1,3 +1,5 @@
import copy
import torch
from transformers import BertTokenizer

View File

@ -0,0 +1,42 @@
import os
from typing import TYPE_CHECKING, Optional
from astroid import nodes
from pylint.checkers import BaseChecker
if TYPE_CHECKING:
from pylint.lint import PyLinter
class AbsoluteImportChecker(BaseChecker):
"""Checker for detecting absolute imports within the same package."""
name = 'absolute-import'
msgs = {
'W0001': (
'Absolute import from same package used: %s',
'absolute-import-used',
'Use relative imports instead of absolute imports from the same package.'
),
}
def __init__(self, linter: Optional["PyLinter"] = None) -> None:
super().__init__(linter)
def visit_importfrom(self, node: nodes.ImportFrom) -> None:
current_file = node.root().file
if current_file is None:
return
package_path = os.path.dirname(current_file)
package_name = os.path.basename(package_path)
if node.modname.startswith(package_name) and package_name in ['comfy', 'comfy_extras']:
import_parts = node.modname.split('.')
if import_parts[0] == package_name:
self.add_message('absolute-import-used', node=node, args=(node.modname,))
def register(linter: "PyLinter") -> None:
linter.register_checker(AbsoluteImportChecker(linter))