Skip to content

Commit

Permalink
[pylint] Re-enable unused-{variable, argument}
Browse files Browse the repository at this point in the history
Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Jul 29, 2024
1 parent f836107 commit 9578727
Show file tree
Hide file tree
Showing 26 changed files with 53 additions and 36 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
import sos


# -- General configuration ------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ disable=
W0201, # attribute-defined-outside-init
W0511, # fixme
###################### VV things we should fix VV
W0613, # unused-argument
W0612, # unused-variable
W0719, # broad-exception-raised
W1203, # logging-fstring-interpolation
W1406, # redundant-u-string-prefix
Expand Down
4 changes: 2 additions & 2 deletions sos/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def _encrypt(self, archive):
msg = f"gpg exited with code {r['status']}"
raise Exception(msg)

def _build_archive(self, method):
def _build_archive(self, method): # pylint: disable=unused-argument
return self.name()


Expand Down Expand Up @@ -719,7 +719,7 @@ def copy_permissions_filter(self, tarinfo):

def get_selinux_context(self, path):
try:
(rc, c) = selinux.getfilecon(path)
(_, c) = selinux.getfilecon(path)
return c
except Exception:
return None
Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def rebuild_nested_archive(self):
if checksum is not None:
dname = f"checksums/{arc_dest}.{self.hash_name}"
self.archive.add_string(checksum, dest=dname)
for dirn, dirs, files in os.walk(self.nested_archive.extracted_path):
for dirn, _, files in os.walk(self.nested_archive.extracted_path):
for filename in files:
fname = os.path.join(dirn, filename)
dname = fname.split(self.nested_archive.extracted_path)[-1]
Expand Down
22 changes: 11 additions & 11 deletions sos/cleaner/archives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, archive_path, tmpdir):
@classmethod
def check_is_type(cls, arc_path):
"""Check if the archive is a well-known type we directly support"""
return False
raise NotImplementedError

@property
def is_sos(self):
Expand Down Expand Up @@ -282,15 +282,15 @@ def remove_extracted_path(self):
so that we don't take up that duplicate space any longer during
execution
"""
def force_delete_file(action, name, exc):
os.chmod(name, stat.S_IWUSR)
if os.path.isfile(name):
os.remove(name)
try:
self.log_debug(f"Removing {self.extracted_path}")
shutil.rmtree(self.extracted_path)
except OSError:
os.chmod(self.extracted_path, stat.S_IWUSR)
if os.path.isfile(self.extracted_path):
os.remove(self.extracted_path)
else:
shutil.rmtree(name)
self.log_debug(f"Removing {self.extracted_path}")
# pylint: disable-next=deprecated-argument
shutil.rmtree(self.extracted_path, onerror=force_delete_file)
shutil.rmtree(self.extracted_path)

def extract_self(self):
"""Extract an archive into our tmpdir so that we may inspect it or
Expand Down Expand Up @@ -321,7 +321,7 @@ def get_file_list(self):
Will not include symlinks, as those are handled separately
"""
for dirname, dirs, files in os.walk(self.extracted_path):
for dirname, _, files in os.walk(self.extracted_path):
for filename in files:
_fname = os.path.join(dirname, filename.lstrip('/'))
if os.path.islink(_fname):
Expand All @@ -332,7 +332,7 @@ def get_file_list(self):
def get_directory_list(self):
"""Return a list of all directories within the archive"""
dir_list = []
for dirname, dirs, files in os.walk(self.extracted_path):
for dirname, _, _ in os.walk(self.extracted_path):
dir_list.append(dirname)
return dir_list

Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/mappings/ip_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def sanitize_ipaddr(self, addr):
def _new_obfuscated_single_address(self):
def _gen_address():
_octets = []
for i in range(0, 4):
for _ in range(0, 4):
_octets.append(random.randint(11, 99))
return f"{_octets[0]}.{_octets[1]}.{_octets[2]}.{_octets[3]}"

Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/mappings/mac_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def sanitize_item(self, item):
"""
hexdigits = "0123456789abdcef"
hextets = []
for i in range(0, 3):
for _ in range(0, 3):
hextets.append(''.join(random.choice(hexdigits) for x in range(2)))

hextets = tuple(hextets)
Expand Down
1 change: 1 addition & 0 deletions sos/cleaner/preppers/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class KeywordPrepper(SoSPrepper):

name = 'keyword'

# pylint: disable=unused-argument
def _get_items_for_keyword(self, archive):
items = []
for kw in self.opts.keywords:
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _find_modules_in_path(cls, path, modulename):
continue
if '__' in pyfile:
continue
fname, ext = os.path.splitext(pyfile)
fname, _ = os.path.splitext(pyfile)
modname = f'sos.collector.{modulename}.{fname}'
modules.extend(cls._import_modules(modname))
return modules
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def get_node_label(self, node):
node.manifest.add_field('label', label)
return label

def set_node_label(self, node):
def set_node_label(self, node): # pylint: disable=unused-argument
"""This may be overridden by clusters profiles subclassing this class
If there is a distinction between primaries and nodes, or types of
Expand Down
4 changes: 2 additions & 2 deletions sos/collector/clusters/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def add_subordinates(self, juju_status):
continue

units = juju_status["applications"][parent]["units"]
for unit, unit_info in units.items():
for _, unit_info in units.items():
node = f"{self.model_name}:{unit_info['machine']}"
for sub_key, sub_value in unit_info.get(
for sub_key, _ in unit_info.get(
"subordinates", {}
).items():
if sub_key.startswith(app + "/"):
Expand Down
2 changes: 1 addition & 1 deletion sos/collector/transports/control_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _check_for_control_persist(self):
ssh_cmd = ['ssh', '-o', 'ControlPersist']
cmd = subprocess.Popen(ssh_cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = cmd.communicate()
_, err = cmd.communicate()
err = err.decode('utf-8')
if 'Bad configuration option' in err or 'Usage:' in err:
raise ControlPersistUnsupportedException
Expand Down
1 change: 1 addition & 0 deletions sos/collector/transports/saltstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def connected(self):
up = self.run_command("echo Connected", timeout=10)
return up['status'] == 0

# pylint: disable=unused-argument
def _check_for_saltstack(self, password=None):
"""Checks to see if the local system supported SaltStack Master.
Expand Down
2 changes: 1 addition & 1 deletion sos/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def execute(self):
raise NotImplementedError

def get_exit_handler(self):
def exit_handler(signum, frame):
def exit_handler(signum, frame): # pylint: disable=unused-argument
self.exit_process = True
self._exit()
return exit_handler
Expand Down
4 changes: 2 additions & 2 deletions sos/policies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, sysroot=None, probe_runtime=True, remote_exec=None):
self.sysroot = sysroot
self.register_presets(GENERIC_PRESETS)

def check(self, remote=''):
def check(self, remote=''): # pylint: disable=unused-argument
"""
This function is responsible for determining if the underlying system
is supported by this policy.
Expand Down Expand Up @@ -328,7 +328,7 @@ def pkg_by_name(self, pkg):

def _parse_uname(self):
(system, node, release,
version, machine, processor) = platform.uname()
version, machine, _) = platform.uname()
self.system = system
self.hostname = node
self.release = release
Expand Down
3 changes: 2 additions & 1 deletion sos/policies/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def _determine_upload_type(self):
return prots[self.commons['cmdlineopts'].upload_protocol]
if '://' not in self.upload_url:
raise Exception("Must provide protocol in upload URL")
prot, url = self.upload_url.split('://')
prot, _ = self.upload_url.split('://')
if prot not in prots.keys():
raise Exception(f"Unsupported or unrecognized protocol: {prot}")
return prots[prot]
Expand Down Expand Up @@ -1006,6 +1006,7 @@ def set_cleanup_cmd(self):
"""
return ''

# pylint: disable=unused-argument
def create_sos_container(self, image=None, auth=None, force_pull=False):
"""Returns the command that will create the container that will be
used for running commands inside a container on hosts that require it.
Expand Down
2 changes: 1 addition & 1 deletion sos/policies/distros/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def check(cls, remote=''):
with open(OS_RELEASE, "r") as f:
for line in f:
if line.startswith("NAME"):
(name, value) = line.split("=")
(_, value) = line.split("=")
value = value.strip("\"'")
if value.startswith(cls.distro):
return True
Expand Down
1 change: 1 addition & 0 deletions sos/policies/init_systems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def is_service(self, name):
"""
return name in self.services

# pylint: disable=unused-argument
def is_running(self, name, default=True):
"""Checks if the given service name is in a running state.
Expand Down
8 changes: 4 additions & 4 deletions sos/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def load_plugins(self):

# validate and load plugins
for plug in plugins:
plugbase, ext = os.path.splitext(plug)
plugbase, __ = os.path.splitext(plug)
try:
plugin_classes = import_plugin(plugbase, valid_plugin_classes)
if not len(plugin_classes):
Expand Down Expand Up @@ -899,7 +899,7 @@ def load_plugins(self):

def _set_all_options(self):
if self.opts.alloptions:
for plugname, plug in self.loaded_plugins:
for __, plug in self.loaded_plugins:
for opt in plug.options.values():
if bool in opt.val_type:
opt.value = True
Expand Down Expand Up @@ -979,7 +979,7 @@ def _check_for_unknown_plugins(self):
)

def _set_plugin_options(self):
for plugin_name, plugin in self.loaded_plugins:
for __, plugin in self.loaded_plugins:
for opt in plugin.options:
self.all_options.append(plugin.options[opt])

Expand Down Expand Up @@ -1450,7 +1450,7 @@ def generate_reports(self):
cmd['file']
)))

for content, f, tags in plug.copy_strings:
for __, f, __ in plug.copy_strings:
section.add(CreatedFile(name=f,
href=os.path.join("..", f)))

Expand Down
1 change: 1 addition & 0 deletions sos/report/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Node(object):
def __str__(self):
return json.dumps(self.data)

# pylint: disable=unused-argument
def can_add(self, node):
return False

Expand Down
2 changes: 1 addition & 1 deletion sos/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def __init__(self, package):
def _plugin_name(self, path):
"Returns the plugin module name given the path"
base = os.path.basename(path)
name, ext = os.path.splitext(base)
name, _ = os.path.splitext(base)
return name

def _get_plugins_from_list(self, list_):
Expand Down
2 changes: 1 addition & 1 deletion tests/report_tests/plugin_tests/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def pre_sos_setup(self):
# allowing for any compression or de-dupe systemd does
sosfd = journal.stream('sos-testing')
rsize = 10 * 1048576
for i in range(2):
for _ in range(2):
# generate 10MB, write it, then write it in reverse.
# Spend less time generating new strings
rand = ''.join(
Expand Down
3 changes: 3 additions & 0 deletions tests/sos_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


def skipIf(cond, message=None):
# pylint: disable=unused-argument
def decorator(function):
def wrapper(self, *args, **kwargs):
if callable(cond):
Expand All @@ -47,13 +48,15 @@ def wrapper(self, *args, **kwargs):
return decorator


# pylint: disable=unused-argument
def redhat_only(tst):
def wrapper(func):
if distro.detect().name not in RH_DIST:
raise TestSkipError('Not running on a Red Hat distro')
return wrapper


# pylint: disable=unused-argument
def ubuntu_only(tst):
def wrapper(func):
if distro.detect().name not in UBUNTU_DIST:
Expand Down
8 changes: 8 additions & 0 deletions tests/unittests/juju/juju_cluster_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class JujuTest(unittest.TestCase):
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_no_filter(self, mock_exec_primary_cmd):
"""No filter."""
mock_opts = MockOptions()
Expand All @@ -79,6 +80,7 @@ def test_get_nodes_no_filter(self, mock_exec_primary_cmd):
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_app_filter(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -113,6 +115,7 @@ def test_get_nodes_app_filter(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_app_regex_filter(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -147,6 +150,7 @@ def test_get_nodes_app_regex_filter(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_model_filter_multiple_models(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -198,6 +202,7 @@ def test_get_nodes_model_filter_multiple_models(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_model_filter(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -246,6 +251,7 @@ def test_get_nodes_model_filter(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_unit_filter(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -277,6 +283,7 @@ def test_get_nodes_unit_filter(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_get_nodes_machine_filter(
self, mock_exec_primary_cmd, mock_get_juju_version
):
Expand Down Expand Up @@ -309,6 +316,7 @@ def test_get_nodes_machine_filter(
"sos.collector.clusters.juju.juju.exec_primary_cmd",
side_effect=get_juju_status,
)
# pylint: disable=unused-argument
def test_subordinates(self, mock_exec_primary_cmd, mock_get_juju_version):
"""Subordinate filter."""
mock_opts = MockOptions()
Expand Down
Loading

0 comments on commit 9578727

Please sign in to comment.