diff --git a/.pylintrc b/.pylintrc index 7ec9280f4..daf8f4d7d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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] diff --git a/comfy/component_model/plugins.py b/comfy/component_model/plugins.py index 1c1e0d853..f9221fe75 100644 --- a/comfy/component_model/plugins.py +++ b/comfy/component_model/plugins.py @@ -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)) diff --git a/comfy/model_management_types.py b/comfy/model_management_types.py index a6e9241c6..9db631a26 100644 --- a/comfy/model_management_types.py +++ b/comfy/model_management_types.py @@ -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) diff --git a/comfy/nodes/package.py b/comfy/nodes/package.py index f724ff995..a5535ccbe 100644 --- a/comfy/nodes/package.py +++ b/comfy/nodes/package.py @@ -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 diff --git a/comfy/text_encoders/hydit.py b/comfy/text_encoders/hydit.py index b4b7db385..5dc6fbebd 100644 --- a/comfy/text_encoders/hydit.py +++ b/comfy/text_encoders/hydit.py @@ -1,3 +1,5 @@ +import copy + import torch from transformers import BertTokenizer diff --git a/tests/absolute_import_checker.py b/tests/absolute_import_checker.py new file mode 100644 index 000000000..13bb644e6 --- /dev/null +++ b/tests/absolute_import_checker.py @@ -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))