Skip to content

Commit 8597797

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 81212fe commit 8597797

File tree

7 files changed

+59
-62
lines changed

7 files changed

+59
-62
lines changed

plugins/action/git_publish.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from contextlib import suppress
1414
from dataclasses import asdict, dataclass
1515
from pathlib import Path
16-
from typing import Dict, List, Optional, TypeVar, Union
16+
from typing import TypeVar, Union
1717

1818
from ansible.errors import AnsibleActionFail
1919
from ansible.parsing.dataloader import DataLoader
@@ -38,7 +38,7 @@
3838
# pylint: enable=invalid-name
3939

4040
# mypy disallow you from omitting parameters in generic types
41-
JSONTypes = Union[bool, int, str, Dict, List] # type:ignore
41+
JSONTypes = Union[bool, int, str, dict, list] # type:ignore
4242

4343

4444
@dataclass(frozen=False)
@@ -61,7 +61,7 @@ class ActionModule(GitBase):
6161

6262
# pylint: disable=too-many-arguments
6363
def __init__( # noqa: PLR0913
64-
self: T,
64+
self,
6565
connection: Connection,
6666
loader: DataLoader,
6767
play_context: PlayContext,
@@ -94,10 +94,10 @@ def __init__( # noqa: PLR0913
9494
self._play_name: str = ""
9595
self._supports_async = True
9696
self._result: Result = Result()
97-
self._env: Optional[Dict[str, str]] = None
98-
self._temp_ssh_key_path: Optional[str] = None
97+
self._env: dict[str, str] | None = None
98+
self._temp_ssh_key_path: str | None = None
9999

100-
def _check_argspec(self: T) -> None:
100+
def _check_argspec(self) -> None:
101101
"""Check the argspec for the action plugin.
102102
103103
:raises AnsibleActionFail: If the argspec is invalid
@@ -117,7 +117,7 @@ def _check_argspec(self: T) -> None:
117117
msg = "Parameters `ssh_key_file` and `ssh_key_content` are mutually exclusive."
118118
raise AnsibleActionFail(msg)
119119

120-
def _prepare_ssh_environment(self: T) -> None:
120+
def _prepare_ssh_environment(self) -> None:
121121
"""Prepare the environment for SSH key authentication."""
122122
key_content = self._task.args.get("ssh_key_content")
123123
key_file = self._task.args.get("ssh_key_file")
@@ -137,12 +137,12 @@ def _prepare_ssh_environment(self: T) -> None:
137137
ssh_command = f"ssh -i {key_path} -o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
138138
self._env = {"GIT_SSH_COMMAND": ssh_command}
139139

140-
def _cleanup_ssh_key(self: T) -> None:
140+
def _cleanup_ssh_key(self) -> None:
141141
"""Remove the temporary SSH key file if it was created."""
142142
if self._temp_ssh_key_path:
143143
Path(self._temp_ssh_key_path).unlink()
144144

145-
def _configure_git_user_name(self: T) -> None:
145+
def _configure_git_user_name(self) -> None:
146146
"""Configure the git user name."""
147147
command_parts = list(self._base_command)
148148
command_parts.extend(["config", "--get", "user.name"])
@@ -167,7 +167,7 @@ def _configure_git_user_name(self: T) -> None:
167167
self._run_command(command=command)
168168
self._result.user_name = name
169169

170-
def _configure_git_user_email(self: T) -> None:
170+
def _configure_git_user_email(self) -> None:
171171
"""Configure the git user email."""
172172
command_parts = list(self._base_command)
173173
command_parts.extend(["config", "--get", "user.email"])
@@ -192,7 +192,7 @@ def _configure_git_user_email(self: T) -> None:
192192
self._run_command(command=command)
193193
self._result.user_email = email
194194

195-
def _add(self: T) -> None:
195+
def _add(self) -> None:
196196
"""Add files for the pending commit."""
197197
command_parts = list(self._base_command)
198198
files = " ".join(self._task.args["include"])
@@ -204,7 +204,7 @@ def _add(self: T) -> None:
204204
)
205205
self._run_command(command=command)
206206

207-
def _commit(self: T) -> None:
207+
def _commit(self) -> None:
208208
"""Perform a commit for the pending push."""
209209
command_parts = list(self._base_command)
210210
message = self._task.args["commit"]["message"].format(play_name=self._play_name)
@@ -217,7 +217,7 @@ def _commit(self: T) -> None:
217217
)
218218
self._run_command(command=command)
219219

220-
def _tag(self: T) -> None:
220+
def _tag(self) -> None:
221221
"""Create a tag object."""
222222
command_parts = list(self._base_command)
223223
message = self._task.args["tag"].get("message")
@@ -233,7 +233,7 @@ def _tag(self: T) -> None:
233233
)
234234
self._run_command(command=command)
235235

236-
def _push(self: T) -> None:
236+
def _push(self) -> None:
237237
"""Push the commit to the origin."""
238238
command_parts = list(self._base_command)
239239
command_parts.extend(["remote", "-v"])
@@ -278,7 +278,7 @@ def _push(self: T) -> None:
278278
line for line in command.stderr.split("remote:") if "https" in line
279279
).strip()
280280

281-
def _remove_repo(self: T) -> None:
281+
def _remove_repo(self) -> None:
282282
"""Remove the temporary directory."""
283283
if not self._task.args["remove"]:
284284
return
@@ -290,10 +290,10 @@ def _remove_repo(self: T) -> None:
290290
self._result.msg = "Failed to remove repository"
291291

292292
def run(
293-
self: T,
293+
self,
294294
tmp: None = None,
295-
task_vars: Optional[Dict[str, JSONTypes]] = None,
296-
) -> Dict[str, JSONTypes]:
295+
task_vars: dict[str, JSONTypes] | None = None,
296+
) -> dict[str, JSONTypes]:
297297
"""Run the action plugin.
298298
299299
:param tmp: The temporary directory

plugins/action/git_retrieve.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from dataclasses import asdict, dataclass, field
1414
from pathlib import Path
15-
from typing import Dict, List, Optional, Tuple, TypeVar, Union
15+
from typing import TypeVar, Union
1616

1717
from ansible.errors import AnsibleActionFail
1818
from ansible.parsing.dataloader import DataLoader
@@ -37,15 +37,15 @@
3737
# pylint: enable=invalid-name
3838

3939
# mypy disallow you from omitting parameters in generic types
40-
JSONTypes = Union[bool, int, str, Dict, List] # type:ignore
40+
JSONTypes = Union[bool, int, str, dict, list] # type:ignore
4141

4242

4343
@dataclass(frozen=False)
4444
class Result(ResultBase):
4545
"""Data structure for the task result."""
4646

4747
branch_name: str = ""
48-
branches: List[str] = field(default_factory=list)
48+
branches: list[str] = field(default_factory=list)
4949
name: str = ""
5050
path: str = ""
5151

@@ -62,7 +62,7 @@ class ActionModule(GitBase):
6262
_requires_connection = False
6363

6464
def __init__( # noqa: PLR0913
65-
self: T,
65+
self,
6666
connection: Connection,
6767
loader: DataLoader,
6868
play_context: PlayContext,
@@ -90,18 +90,18 @@ def __init__( # noqa: PLR0913
9090
),
9191
)
9292

93-
self._base_command: Tuple[str, ...]
94-
self._branches: List[str]
93+
self._base_command: tuple[str, ...]
94+
self._branches: list[str]
9595
self._branch_name: str
9696
self._parent_directory: str
9797
self._repo_path: str
9898
self._play_name: str = ""
9999
self._supports_async = True
100100
self._result: Result = Result()
101-
self._temp_ssh_key_path: Optional[str] = None
101+
self._temp_ssh_key_path: str | None = None
102102
self._ssh_command_str: str = "ssh"
103103

104-
def _check_argspec(self: T) -> None:
104+
def _check_argspec(self) -> None:
105105
"""Check the argspec for the action plugin.
106106
107107
:raises AnsibleActionFail: If the argspec is invalid
@@ -129,7 +129,7 @@ def _check_argspec(self: T) -> None:
129129
)
130130
raise AnsibleActionFail(msg)
131131

132-
def _prepare_ssh_environment(self: T) -> None:
132+
def _prepare_ssh_environment(self) -> None:
133133
"""Prepare the environment for SSH key authentication."""
134134
origin_args = self._task.args.get("origin", {})
135135
key_content = origin_args.get("ssh_key_content")
@@ -151,20 +151,20 @@ def _prepare_ssh_environment(self: T) -> None:
151151
f"ssh -i {key_path} -o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
152152
)
153153

154-
def _cleanup_ssh_key(self: T) -> None:
154+
def _cleanup_ssh_key(self) -> None:
155155
"""Remove the temporary SSH key file if it was created."""
156156
if self._temp_ssh_key_path:
157157
Path(self._temp_ssh_key_path).unlink()
158158

159159
@property
160-
def _branch_exists(self: T) -> bool:
160+
def _branch_exists(self) -> bool:
161161
"""Return True if the branch exists.
162162
163163
:returns: True if the branch exists
164164
"""
165165
return self._branch_name in self._branches
166166

167-
def _host_key_checking(self: T) -> None:
167+
def _host_key_checking(self) -> None:
168168
"""Configure host key checking."""
169169
origin = self._task.args["origin"]["url"]
170170
upstream = self._task.args["upstream"].get("url") or ""
@@ -188,7 +188,7 @@ def _host_key_checking(self: T) -> None:
188188
)
189189
self._run_command(command=command)
190190

191-
def _clone(self: T) -> None:
191+
def _clone(self) -> None:
192192
"""Clone the repository, creating a new subdirectory."""
193193
origin = self._task.args["origin"]["url"]
194194
upstream = self._task.args["upstream"].get("url") or ""
@@ -247,7 +247,7 @@ def _clone(self: T) -> None:
247247
self._base_command = ("git", "-C", self._repo_path)
248248
return
249249

250-
def _get_branches(self: T) -> None:
250+
def _get_branches(self) -> None:
251251
"""Get the branches."""
252252
command_parts = list(self._base_command)
253253
command_parts.extend(["branch", "-a"])
@@ -294,14 +294,14 @@ def _get_branches(self: T) -> None:
294294
self._result.branch_name = self._branch_name
295295
return
296296

297-
def _detect_duplicate_branch(self: T) -> None:
297+
def _detect_duplicate_branch(self) -> None:
298298
"""Detect duplicate branch."""
299299
duplicate_detection = self._task.args["branch"]["duplicate_detection"]
300300
if duplicate_detection and self._branch_exists:
301301
self._result.failed = True
302302
self._result.msg = f"Branch '{self._branch_name}' already exists"
303303

304-
def _switch_checkout(self: T) -> None:
304+
def _switch_checkout(self) -> None:
305305
"""Switch to or checkout the branch."""
306306
command_parts = list(self._base_command)
307307
branch = self._branch_name
@@ -321,7 +321,7 @@ def _switch_checkout(self: T) -> None:
321321
)
322322
self._run_command(command=command)
323323

324-
def _add_upstream_remote(self: T) -> None:
324+
def _add_upstream_remote(self) -> None:
325325
"""Add the upstream remote."""
326326
if not self._task.args["upstream"].get("url"):
327327
return
@@ -336,7 +336,7 @@ def _add_upstream_remote(self: T) -> None:
336336
self._run_command(command=command)
337337
return
338338

339-
def _pull_upstream(self: T) -> None:
339+
def _pull_upstream(self) -> None:
340340
"""Pull from upstream."""
341341
if not self._task.args["upstream"].get("url"):
342342
return
@@ -363,10 +363,10 @@ def _pull_upstream(self: T) -> None:
363363
return
364364

365365
def run(
366-
self: T,
366+
self,
367367
tmp: None = None,
368-
task_vars: Optional[Dict[str, JSONTypes]] = None,
369-
) -> Dict[str, JSONTypes]:
368+
task_vars: dict[str, JSONTypes] | None = None,
369+
) -> dict[str, JSONTypes]:
370370
"""Run the action plugin.
371371
372372
:param tmp: The temporary directory

plugins/plugin_utils/command.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
from dataclasses import dataclass, field
14-
from typing import Dict, List, Optional, TypeVar, Union
14+
from typing import TypeVar
1515

1616

1717
T = TypeVar("T", bound="Command") # pylint: disable=invalid-name, useless-suppression
@@ -27,27 +27,27 @@ class Command:
2727

2828
# pylint: disable=too-many-instance-attributes
2929

30-
command_parts: List[str]
30+
command_parts: list[str]
3131
fail_msg: str
3232

33-
env: Optional[Dict[str, str]] = None
34-
no_log: Dict[str, str] = field(default_factory=dict)
33+
env: dict[str, str] | None = None
34+
no_log: dict[str, str] = field(default_factory=dict)
3535
return_code: int = -1
3636
stdout: str = ""
3737
stderr: str = ""
38-
stdout_lines: List[str] = field(default_factory=list)
39-
stderr_lines: List[str] = field(default_factory=list)
38+
stdout_lines: list[str] = field(default_factory=list)
39+
stderr_lines: list[str] = field(default_factory=list)
4040

4141
@property
42-
def command(self: T) -> str:
42+
def command(self) -> str:
4343
"""Return the command as a string.
4444
4545
:return: The command as a string.
4646
"""
4747
return shlex.join(self.command_parts)
4848

4949
@property
50-
def cleaned(self: T) -> Dict[str, Union[int, Dict[str, str], List[str], str]]:
50+
def cleaned(self) -> dict[str, int | dict[str, str] | list[str] | str]:
5151
"""Return the sanitized details of the command for the log.
5252
5353
:return: The sanitized details of the command for the log.

0 commit comments

Comments
 (0)