mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Cleanup with ruff check (#1182)
* Implement improvements suggested by ruff check. * Add ruff check to CI.
This commit is contained in:
@@ -890,14 +890,15 @@ def _preprocess_mounts(
|
||||
check_collision(container, "volumes")
|
||||
new_vols.append(f"{host}:{container}:{mode}")
|
||||
continue
|
||||
if len(parts) == 2:
|
||||
if not _is_volume_permissions(parts[1]) and re.match(
|
||||
r"[.~]", parts[0]
|
||||
):
|
||||
host = os.path.abspath(os.path.expanduser(parts[0]))
|
||||
check_collision(parts[1], "volumes")
|
||||
new_vols.append(f"{host}:{parts[1]}:rw")
|
||||
continue
|
||||
if (
|
||||
len(parts) == 2
|
||||
and not _is_volume_permissions(parts[1])
|
||||
and re.match(r"[.~]", parts[0])
|
||||
):
|
||||
host = os.path.abspath(os.path.expanduser(parts[0]))
|
||||
check_collision(parts[1], "volumes")
|
||||
new_vols.append(f"{host}:{parts[1]}:rw")
|
||||
continue
|
||||
check_collision(parts[min(1, len(parts) - 1)], "volumes")
|
||||
new_vols.append(vol)
|
||||
values["volumes"] = new_vols
|
||||
|
||||
@@ -219,12 +219,11 @@ class DockerAPIEngineDriver(EngineDriver[AnsibleDockerClient]):
|
||||
return False
|
||||
|
||||
def is_container_running(self, container: dict[str, t.Any]) -> bool:
|
||||
if container.get("State"):
|
||||
if container["State"].get("Running") and not container["State"].get(
|
||||
"Ghost", False
|
||||
):
|
||||
return True
|
||||
return False
|
||||
return bool(
|
||||
container.get("State")
|
||||
and container["State"].get("Running")
|
||||
and not container["State"].get("Ghost", False)
|
||||
)
|
||||
|
||||
def is_container_paused(self, container: dict[str, t.Any]) -> bool:
|
||||
if container.get("State"):
|
||||
@@ -1706,9 +1705,8 @@ def _get_expected_values_mounts(
|
||||
parts = vol.split(":")
|
||||
if len(parts) == 3:
|
||||
continue
|
||||
if len(parts) == 2:
|
||||
if not _is_volume_permissions(parts[1]):
|
||||
continue
|
||||
if len(parts) == 2 and not _is_volume_permissions(parts[1]):
|
||||
continue
|
||||
expected_vols[vol] = {}
|
||||
if expected_vols:
|
||||
expected_values["volumes"] = expected_vols
|
||||
@@ -1805,9 +1803,8 @@ def _set_values_mounts(
|
||||
parts = volume.split(":")
|
||||
if len(parts) == 3:
|
||||
continue
|
||||
if len(parts) == 2:
|
||||
if not _is_volume_permissions(parts[1]):
|
||||
continue
|
||||
if len(parts) == 2 and not _is_volume_permissions(parts[1]):
|
||||
continue
|
||||
volumes[volume] = {}
|
||||
data["Volumes"] = volumes
|
||||
if "volume_binds" in values:
|
||||
|
||||
@@ -217,11 +217,13 @@ class ContainerManager(DockerBaseClass, t.Generic[Client]):
|
||||
"The wildcard can only be used with comparison modes 'strict' and 'ignore'!"
|
||||
)
|
||||
for option in self.all_options.values():
|
||||
if option.name == "networks":
|
||||
# `networks` is special: only update if
|
||||
# some value is actually specified
|
||||
if self.module.params["networks"] is None:
|
||||
continue
|
||||
# `networks` is special: only update if
|
||||
# some value is actually specified
|
||||
if (
|
||||
option.name == "networks"
|
||||
and self.module.params["networks"] is None
|
||||
):
|
||||
continue
|
||||
option.comparison = value
|
||||
# Now process all other comparisons.
|
||||
comp_aliases_used: dict[str, str] = {}
|
||||
@@ -679,13 +681,17 @@ class ContainerManager(DockerBaseClass, t.Generic[Client]):
|
||||
def _image_is_different(
|
||||
self, image: dict[str, t.Any] | None, container: Container
|
||||
) -> bool:
|
||||
if image and image.get("Id"):
|
||||
if container and container.image:
|
||||
if image.get("Id") != container.image:
|
||||
self.diff_tracker.add(
|
||||
"image", parameter=image.get("Id"), active=container.image
|
||||
)
|
||||
return True
|
||||
if (
|
||||
image
|
||||
and image.get("Id")
|
||||
and container
|
||||
and container.image
|
||||
and image.get("Id") != container.image
|
||||
):
|
||||
self.diff_tracker.add(
|
||||
"image", parameter=image.get("Id"), active=container.image
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
def _compose_create_parameters(self, image: str) -> dict[str, t.Any]:
|
||||
@@ -927,14 +933,13 @@ class ContainerManager(DockerBaseClass, t.Generic[Client]):
|
||||
"ipv6_address"
|
||||
] != network_info_ipam.get("IPv6Address"):
|
||||
diff = True
|
||||
if network.get("aliases"):
|
||||
if not compare_generic(
|
||||
network["aliases"],
|
||||
network_info.get("Aliases"),
|
||||
"allow_more_present",
|
||||
"set",
|
||||
):
|
||||
diff = True
|
||||
if network.get("aliases") and not compare_generic(
|
||||
network["aliases"],
|
||||
network_info.get("Aliases"),
|
||||
"allow_more_present",
|
||||
"set",
|
||||
):
|
||||
diff = True
|
||||
if network.get("links"):
|
||||
expected_links = []
|
||||
for link, alias in network["links"]:
|
||||
|
||||
Reference in New Issue
Block a user