Commit 438ed34c authored by Benjamin Schubert's avatar Benjamin Schubert

lint: Fix or silence 'cyclic-import' errors and enable pylint for it

Cyclic imports can be confusing because the order in which we import
dependencies can make the import fail or not. We should not rely on
ordering of imports for our code. This fixes everywhere possible the
imports and silence explicitely some which are not convenient or would
require big refactors
parent b8cb5832
Pipeline #54574371 passed with stages
in 57 minutes and 46 seconds
......@@ -105,11 +105,6 @@ disable=#####################################
unused-argument,
###########################################################
# Messages that report warnings which should be addressed #
###########################################################
cyclic-import,
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
......
......@@ -32,9 +32,8 @@ import os
import shutil
from . import _yaml
from . import Scope
from ._exceptions import ArtifactError
from .types import _KeyStrength
from .types import Scope, _KeyStrength
from .storage._casbaseddirectory import CasBasedDirectory
......
......@@ -41,7 +41,9 @@ from .. import _yaml
from .._scheduler import ElementJob, JobStatus
# Import frontend assets
from . import Profile, LogLine, Status
from .profile import Profile
from .status import Status
from .widget import LogLine
# Intendation for all logging
INDENT = 4
......@@ -127,7 +129,7 @@ class App():
def create(cls, *args, **kwargs):
if sys.platform.startswith('linux'):
# Use an App with linux specific features
from .linuxapp import LinuxApp
from .linuxapp import LinuxApp # pylint: disable=cyclic-import
return LinuxApp(*args, **kwargs)
else:
# The base App() class is default
......
......@@ -26,7 +26,7 @@ import textwrap
from ruamel import yaml
import click
from . import Profile
from .profile import Profile
from .. import Element, Consistency, Scope
from .. import _yaml
from .. import __version__ as bst_version
......
......@@ -30,9 +30,10 @@ from tempfile import TemporaryFile
from configparser import RawConfigParser
from buildstream import Source, SourceError, Consistency, SourceFetcher, CoreWarnings
from buildstream import utils
from buildstream.utils import move_atomic, DirectoryExistsError
from .source import Source, SourceError, SourceFetcher
from .types import Consistency, CoreWarnings
from . import utils
from .utils import move_atomic, DirectoryExistsError
GIT_MODULES = '.gitmodules'
......
......@@ -30,8 +30,8 @@ from .._includes import Includes
from .types import Symbol
from .loadelement import LoadElement, _extract_depends_from_node
from . import MetaElement
from . import MetaSource
from .metaelement import MetaElement
from .metasource import MetaSource
from ..types import CoreWarnings
from .._message import Message, MessageType
......@@ -562,7 +562,7 @@ class Loader():
# Load the project
project_dir = os.path.join(basedir, element.path)
try:
from .._project import Project
from .._project import Project # pylint: disable=cyclic-import
project = Project(project_dir, self._context, junction=element,
parent_loader=self, search_for_project=False)
except LoadError as e:
......
......@@ -19,7 +19,7 @@ import os
from ..sandbox import SandboxDummy
from . import Platform
from .platform import Platform
class Darwin(Platform):
......
......@@ -24,7 +24,7 @@ from .. import _site
from .. import utils
from ..sandbox import SandboxDummy
from . import Platform
from .platform import Platform
from .._exceptions import PlatformError
......
......@@ -50,11 +50,11 @@ class Platform():
backend = 'unix'
if backend == 'linux':
from .linux import Linux as PlatformImpl
from .linux import Linux as PlatformImpl # pylint: disable=cyclic-import
elif backend == 'darwin':
from .darwin import Darwin as PlatformImpl
from .darwin import Darwin as PlatformImpl # pylint: disable=cyclic-import
elif backend == 'unix':
from .unix import Unix as PlatformImpl
from .unix import Unix as PlatformImpl # pylint: disable=cyclic-import
else:
raise PlatformError("No such platform: '{}'".format(backend))
......
......@@ -21,7 +21,7 @@ import os
from .._exceptions import PlatformError
from . import Platform
from .platform import Platform
class Unix(Platform):
......
......@@ -135,8 +135,10 @@ artifact collection purposes.
"""
import os
from . import Element, Scope
from . import SandboxFlags
from .element import Element
from .sandbox import SandboxFlags
from .types import Scope
# This list is preserved because of an unfortunate situation, we
......
......@@ -93,16 +93,16 @@ from ._versions import BST_CORE_ARTIFACT_VERSION
from ._exceptions import BstError, LoadError, LoadErrorReason, ImplError, \
ErrorDomain, SourceCacheError
from .utils import UtilError
from . import Plugin, Consistency, Scope
from . import SandboxFlags, SandboxCommandError
from . import utils
from . import _cachekey
from . import _signals
from . import _site
from ._platform import Platform
from .plugin import Plugin
from .sandbox import SandboxFlags, SandboxCommandError
from .sandbox._config import SandboxConfig
from .sandbox._sandboxremote import SandboxRemote
from .types import _KeyStrength, CoreWarnings, _UniquePriorityQueue
from .types import Consistency, CoreWarnings, Scope, _KeyStrength, _UniquePriorityQueue
from ._artifact import Artifact
from .storage.directory import Directory
......
......@@ -17,7 +17,7 @@
# Authors:
from .._exceptions import SandboxError
from . import Sandbox
from .sandbox import Sandbox
class SandboxDummy(Sandbox):
......
......@@ -28,8 +28,7 @@ import grpc
from .. import utils
from .._message import Message, MessageType
from . import Sandbox, SandboxCommandError
from .sandbox import _SandboxBatch
from .sandbox import Sandbox, SandboxCommandError, _SandboxBatch
from ..storage._casbaseddirectory import CasBasedDirectory
from .. import _signals
from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2, remote_execution_pb2_grpc
......
......@@ -35,7 +35,9 @@ implementations.
import os
from collections import OrderedDict
from . import Element, ElementError, Scope, SandboxFlags
from .element import Element, ElementError
from .sandbox import SandboxFlags
from .types import Scope
class ScriptElement(Element):
......
......@@ -165,8 +165,9 @@ import os
from collections.abc import Mapping
from contextlib import contextmanager
from . import Plugin, Consistency
from . import _yaml, utils
from .plugin import Plugin
from .types import Consistency
from ._exceptions import BstError, ImplError, ErrorDomain
from ._loader.metasource import MetaSource
from ._projectrefs import ProjectRefStorage
......
......@@ -79,7 +79,7 @@ class FileBasedDirectory(Directory):
can_link=False):
""" See superclass Directory for arguments """
from ._casbaseddirectory import CasBasedDirectory
from ._casbaseddirectory import CasBasedDirectory # pylint: disable=cyclic-import
if isinstance(external_pathspec, CasBasedDirectory):
if can_link and not update_mtime:
......
......@@ -485,7 +485,7 @@ def get_bst_version():
(int): The minor version
"""
# Import this only conditionally, it's not resolved at bash complete time
from . import __version__
from . import __version__ # pylint: disable=cyclic-import
versions = __version__.split('.')[:2]
if versions[0] == '0+untagged':
......
......@@ -3,7 +3,7 @@ import os
from buildstream import _yaml
from buildstream import utils
from . import create_repo
from .repo import create_repo
# create_element_size()
......
from tests.testutils import create_repo
from buildstream import _yaml
from .repo import create_repo
# generate_junction()
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment