From c48c76e9d34bae09dc4eac1f3b33f7cb72355c25 Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Jan 10 2023 09:11:45 +0000 Subject: pylint: Fix cyclic-import Most of `cyclic-import` issues reported by Pylint are false-positive and they are already handled in the code, but several ones are the actual errors. Fixes: https://pagure.io/freeipa/issue/9232 Fixes: https://pagure.io/freeipa/issue/9278 Signed-off-by: Stanislav Levin Reviewed-By: Stanislav Levin --- diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 742c0ed..ef4839c 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -949,7 +949,7 @@ class API(plugable.API): ipaserver.plugins, ) else: - import ipaclient.remote_plugins + import ipaclient.remote_plugins # pylint: disable=cyclic-import import ipaclient.plugins result = ( ipaclient.remote_plugins.get_package(self), diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 9a6b35a..eea3c19 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -449,7 +449,7 @@ class Command(HasParam): # special, rare case: user calls help() on a plugin class instead of # an instance if obj is None: - from ipalib import api + from ipalib import api # pylint: disable=cyclic-import obj = cls(api=api) cls._signature = signature = create_signature(obj) return signature diff --git a/ipaplatform/osinfo.py b/ipaplatform/osinfo.py index fa614c7..955bc08 100644 --- a/ipaplatform/osinfo.py +++ b/ipaplatform/osinfo.py @@ -218,7 +218,7 @@ class OSInfo(Mapping): def container(self): if self._container is not None: return self._container - from ipaplatform.tasks import tasks + from ipaplatform.tasks import tasks # pylint: disable=cyclic-import try: self._container = tasks.detect_container() except NotImplementedError: diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index aaa6fd1..dd28936 100644 --- a/ipaserver/install/installutils.py +++ b/ipaserver/install/installutils.py @@ -56,7 +56,7 @@ from ipalib import api, errors, x509 from ipalib.install import dnsforwarders from ipapython.dn import DN from ipapython.dnsutil import DNSName, resolve -from ipaserver.install import certs, service, sysupgrade +from ipaserver.install import certs, sysupgrade from ipaplatform import services from ipaplatform.paths import paths from ipaplatform.tasks import tasks @@ -1012,6 +1012,7 @@ def check_entropy(): """ Checks if the system has enough entropy, if not, displays warning message """ + from . import service # pylint: disable=cyclic-import try: with open(paths.ENTROPY_AVAIL, 'r') as efname: if int(efname.read()) < 200: diff --git a/ipatests/pytest_ipa/integration/config.py b/ipatests/pytest_ipa/integration/config.py index 6254ee2..67a3fcb 100644 --- a/ipatests/pytest_ipa/integration/config.py +++ b/ipatests/pytest_ipa/integration/config.py @@ -100,11 +100,11 @@ class Config(pytest_multihost.config.Config): @classmethod def from_env(cls, env): - from ipatests.pytest_ipa.integration.env_config import config_from_env + from .env_config import config_from_env # pylint: disable=cyclic-import return config_from_env(env) def to_env(self, **kwargs): - from ipatests.pytest_ipa.integration.env_config import config_to_env + from .env_config import config_to_env # pylint: disable=cyclic-import return config_to_env(self, **kwargs) def filter(self, descriptions): @@ -156,7 +156,7 @@ class Domain(pytest_multihost.config.Domain): raise LookupError(self.type) def get_host_class(self, host_dict): - from ipatests.pytest_ipa.integration.host import Host, WinHost + from .host import Host, WinHost # pylint: disable=cyclic-import if self.is_ipa_type: return Host diff --git a/ipatests/pytest_ipa/integration/firewall.py b/ipatests/pytest_ipa/integration/firewall.py index 0a30cfe..1a5af5c 100644 --- a/ipatests/pytest_ipa/integration/firewall.py +++ b/ipatests/pytest_ipa/integration/firewall.py @@ -231,7 +231,7 @@ class Firewall(FirewallBase): def __init__(self, host): """Initialize with host where firewall changes should be applied""" # break circular dependency - from .tasks import get_platform + from .tasks import get_platform # pylint: disable=cyclic-import self.host = host platform = get_platform(host) diff --git a/ipatests/pytest_ipa/integration/resolver.py b/ipatests/pytest_ipa/integration/resolver.py index 348438e..d433169 100644 --- a/ipatests/pytest_ipa/integration/resolver.py +++ b/ipatests/pytest_ipa/integration/resolver.py @@ -6,7 +6,6 @@ import textwrap import time from ipaplatform.paths import paths -from . import tasks logger = logging.getLogger(__name__) @@ -175,6 +174,7 @@ class ResolvedResolver(Resolver): # scenarios) can exceed the threshold configured in systemd option # StartLimitIntervalSec. In that case restart fails, but we can simply # continue trying until it succeeds + from . import tasks # pylint: disable=cyclic-import tasks.run_repeatedly( self.host, ['systemctl', 'restart', 'systemd-resolved.service'], timeout=15) @@ -293,6 +293,7 @@ class NetworkManagerResolver(Resolver): # scenarios) can exceed the threshold configured in systemd option # StartLimitIntervalSec. In that case restart fails, but we can simply # continue trying until it succeeds + from . import tasks # pylint: disable=cyclic-import tasks.run_repeatedly( self.host, ['systemctl', 'restart', 'NetworkManager.service'], timeout=15)