Add flake8.

This commit is contained in:
Felix Fontein 2025-10-07 08:40:41 +02:00
parent 9e9a61746a
commit 1dc6ab727a
11 changed files with 36 additions and 18 deletions

13
.flake8 Normal file
View File

@ -0,0 +1,13 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2025 Felix Fontein <felix@fontein.de>
[flake8]
extend-ignore = E203, E402, F401
count = true
# TODO: decrease this to ~10
max-complexity = 60
# black's max-line-length is 89, but it doesn't touch long string literals.
# Since ansible-test's limit is 160, let's use that here.
max-line-length = 160
statistics = true

View File

@ -19,8 +19,8 @@ stable_branches = [ "stable-*" ]
run_isort = true
isort_config = ".isort.cfg"
run_black = true
run_flake8 = false
run_pylint = false
run_flake8 = true
flake8_config = ".flake8"
run_yamllint = true
yamllint_config = ".yamllint"
yamllint_config_plugins = ".yamllint-docs"

View File

@ -387,7 +387,7 @@ class AnsibleDockerClientBase(Client):
result = self.inspect_container(container=container_id)
self.log("Completed container inspection")
return result
except NotFound as dummy:
except NotFound:
return None
except Exception as exc:
self.fail(f"Error inspecting container: {exc}")
@ -461,7 +461,7 @@ class AnsibleDockerClientBase(Client):
self.log(f"Inspecting network Id {network_id}")
result = self.inspect_network(network_id)
self.log("Completed network inspection")
except NotFound as dummy:
except NotFound:
return None
except Exception as exc:
self.fail(f"Error inspecting network: {exc}")

View File

@ -287,7 +287,7 @@ class AnsibleDockerClientBase(Client):
result = self.get_json("/containers/{0}/json", container_id)
self.log("Completed container inspection")
return result
except NotFound as dummy:
except NotFound:
return None
except Exception as exc:
self.fail(f"Error inspecting container: {exc}")
@ -369,7 +369,7 @@ class AnsibleDockerClientBase(Client):
self.log(f"Inspecting network Id {network_id}")
result = self.get_json("/networks/{0}", network_id)
self.log("Completed network inspection")
except NotFound as dummy:
except NotFound:
return None
except Exception as exc:
self.fail(f"Error inspecting network: {exc}")

View File

@ -229,8 +229,6 @@ class AnsibleDockerClientBase(object):
check_rc=True,
)
if tag:
lookup = f"{name}:{tag}"
lookup_digest = f"{name}@{tag}"
response = images
images = []
for image in response:

View File

@ -706,7 +706,7 @@ def _preprocess_mounts(module, values):
if mount_dict["tmpfs_mode"] is not None:
try:
mount_dict["tmpfs_mode"] = int(mount_dict["tmpfs_mode"], 8)
except Exception as dummy:
except Exception:
module.fail_json(
msg=f'tmp_fs mode of mount "{target}" is not an octal string!'
)

View File

@ -419,7 +419,7 @@ class DockerAPIEngineDriver(EngineDriver):
while True:
try:
client.delete_call("/containers/{0}", container_id, params=params)
except NotFound as dummy:
except NotFound:
pass
except APIError as exc:
if (
@ -548,7 +548,6 @@ class DockerAPIEngine(Engine):
return {}
return {options[0].name: value}
get_expected_values_ = None
if get_expected_value:
def get_expected_values_(
@ -566,6 +565,9 @@ class DockerAPIEngine(Engine):
return values
return {options[0].name: value}
else:
get_expected_values_ = None
def set_value(module, data, api_version, options, values):
if len(options) != 1:
raise AssertionError(
@ -578,7 +580,6 @@ class DockerAPIEngine(Engine):
value = preprocess_for_set(module, api_version, value)
data[config_name] = value
update_value = None
if update_parameter:
def update_value(module, data, api_version, options, values):
@ -593,6 +594,9 @@ class DockerAPIEngine(Engine):
value = preprocess_for_set(module, api_version, value)
data[update_parameter] = value
else:
update_value = None
return cls(
get_value=get_value,
preprocess_value=preprocess_value_,
@ -644,7 +648,6 @@ class DockerAPIEngine(Engine):
return {}
return {options[0].name: value}
get_expected_values_ = None
if get_expected_value:
def get_expected_values_(
@ -662,6 +665,9 @@ class DockerAPIEngine(Engine):
return values
return {options[0].name: value}
else:
get_expected_values_ = None
def set_value(module, data, api_version, options, values):
if len(options) != 1:
raise AssertionError(
@ -676,7 +682,6 @@ class DockerAPIEngine(Engine):
value = preprocess_for_set(module, api_version, value)
data["HostConfig"][host_config_name] = value
update_value = None
if update_parameter:
def update_value(module, data, api_version, options, values):
@ -691,6 +696,9 @@ class DockerAPIEngine(Engine):
value = preprocess_for_set(module, api_version, value)
data[update_parameter] = value
else:
update_value = None
return cls(
get_value=get_value,
preprocess_value=preprocess_value_,

View File

@ -484,7 +484,7 @@ class ServicesManager(BaseComposeManager):
self.fail(f"The key {key!r} for `scale` is not a string")
try:
value = check_type_int(value)
except TypeError as exc:
except TypeError:
self.fail(f"The value {value!r} for `scale[{key!r}]` is not an integer")
if value < 0:
self.fail(f"The value {value!r} for `scale[{key!r}]` is negative")

View File

@ -85,7 +85,7 @@ from ansible_collections.community.docker.plugins.module_utils._common_api impor
def get_existing_volume(client, volume_name):
try:
return client.get_json("/volumes/{0}", volume_name)
except NotFound as dummy:
except NotFound:
return None
except Exception as exc:
client.fail(f"Error inspecting volume: {exc}")

View File

@ -68,7 +68,6 @@ class TestDockerConnectionClass(unittest.TestCase):
self, mock_new_docker_version, mock_old_docker_version
):
self.dc._version = None
version = self.dc.docker_version
# old version and new version fail
@mock.patch(

View File

@ -93,7 +93,7 @@ def test_parse_line_success(line, kwargs, result):
@pytest.mark.parametrize("line, kwargs, message", FAILURE_TEST_CASES)
def test_parse_line_success(line, kwargs, message):
def test_parse_line_failure(line, kwargs, message):
with pytest.raises(InvalidLogFmt) as exc:
parse_line(line, **kwargs)