Skip to content

Commit a63b602

Browse files
committed
💅🤖 Auto-format entire repository with Ruff
1 parent cdec701 commit a63b602

File tree

13 files changed

+119
-69
lines changed

13 files changed

+119
-69
lines changed

build-scripts/manylinux-container-image/manylinux_mapping.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
def to_modern_manylinux_tag(legacy_manylinux_tag):
2222
"""Return a modern alias for the tag if it exists."""
2323
try:
24-
return '_'.join((
25-
ML_LEGACY_TO_MODERN_MAP[legacy_manylinux_tag],
26-
ARCH,
27-
))
24+
return '_'.join(
25+
(
26+
ML_LEGACY_TO_MODERN_MAP[legacy_manylinux_tag],
27+
ARCH,
28+
),
29+
)
2830
except KeyError:
2931
return legacy_manylinux_tag
3032

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,13 @@
176176
r'http://localhost:\d+/', # local URLs
177177
r'https://codecov\.io/gh/ansible/pylibssh/branch/devel/graph/badge\.svg',
178178
r'https://github\.com/ansible/pylibssh/actions', # 404 if no auth
179-
180179
# Too many links to GitHub so they cause "429 Client Error:
181180
# too many requests for url"
182181
# Ref: https://github.com/sphinx-doc/sphinx/issues/7388
183182
r'https://github\.com/ansible/pylibssh/issues',
184183
r'https://github\.com/ansible/pylibssh/pull',
185184
r'https://github\.com/ansible/ansible/issues',
186185
r'https://github\.com/ansible/ansible/pull',
187-
188186
# Requires a more liberal 'Accept: ' HTTP request header:
189187
# Ref: https://github.com/sphinx-doc/sphinx/issues/7247
190188
r'https://github\.com/ansible/pylibssh/workflows/[^/]+/badge\.svg',
@@ -199,7 +197,9 @@
199197

200198
# -- Options for towncrier_draft extension -----------------------------------
201199

202-
towncrier_draft_autoversion_mode = 'draft' # or: 'sphinx-version', 'sphinx-release'
200+
towncrier_draft_autoversion_mode = (
201+
'draft' # or: 'sphinx-version', 'sphinx-release'
202+
)
203203
towncrier_draft_include_empty = True
204204
towncrier_draft_working_directory = PROJECT_ROOT_DIR
205205
towncrier_draft_config_path = 'pyproject.toml' # relative to cwd

packaging/pep517_backend/_backend.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
'get_requires_for_build_wheel',
7070
'prepare_metadata_for_build_wheel',
7171
*(
72-
() if _setuptools_build_editable is None
72+
()
73+
if _setuptools_build_editable is None
7374
else (
7475
'build_editable',
7576
'get_requires_for_build_editable',
@@ -96,11 +97,11 @@ def _is_truthy_setting_value(setting_value: str) -> bool:
9697

9798

9899
def _get_setting_value(
99-
config_settings: 'dict[str, str] | None' = None,
100-
config_setting_name: 'str | None' = None,
101-
env_var_name: 'str | None' = None,
102-
*,
103-
default: bool = False,
100+
config_settings: 'dict[str, str] | None' = None,
101+
config_setting_name: 'str | None' = None,
102+
env_var_name: 'str | None' = None,
103+
*,
104+
default: bool = False,
104105
) -> bool:
105106
user_provided_setting_sources = (
106107
(config_settings, config_setting_name, (KeyError, TypeError)),
@@ -117,9 +118,9 @@ def _get_setting_value(
117118

118119

119120
def _include_cython_line_tracing(
120-
config_settings: 'dict[str, str] | None' = None,
121-
*,
122-
default=False,
121+
config_settings: 'dict[str, str] | None' = None,
122+
*,
123+
default=False,
123124
) -> bool:
124125
return _get_setting_value(
125126
config_settings,
@@ -202,7 +203,7 @@ def _exclude_dir_path(
202203
]
203204
if visited_directory_subdirs_to_ignore:
204205
print( # noqa: WPS421
205-
f'Preventing `{excluded_dir_path !s}` from being '
206+
f'Preventing `{excluded_dir_path!s}` from being '
206207
'copied into itself recursively...',
207208
file=_standard_error_stream,
208209
)
@@ -230,9 +231,9 @@ def _in_temporary_directory(src_dir: Path) -> t.Iterator[None]:
230231

231232
@contextmanager
232233
def _prebuild_c_extensions(
233-
line_trace_cython_when_unset: bool = False,
234-
build_inplace: bool = False,
235-
config_settings: 'dict[str, str] | None' = None,
234+
line_trace_cython_when_unset: bool = False,
235+
build_inplace: bool = False,
236+
config_settings: 'dict[str, str] | None' = None,
236237
) -> t.Generator[None, t.Any, t.Any]:
237238
"""Pre-build C-extensions in a temporary directory, when needed.
238239
@@ -248,7 +249,8 @@ def _prebuild_c_extensions(
248249
)
249250

250251
build_dir_ctx = (
251-
nullcontext_cm() if build_inplace
252+
nullcontext_cm()
253+
if build_inplace
252254
else _in_temporary_directory(src_dir=Path.cwd().resolve())
253255
)
254256
with build_dir_ctx:
@@ -264,9 +266,9 @@ def _prebuild_c_extensions(
264266

265267
@patched_dist_get_long_description()
266268
def build_wheel(
267-
wheel_directory: str,
268-
config_settings: 'dict[str, str] | None' = None,
269-
metadata_directory: 'str | None' = None,
269+
wheel_directory: str,
270+
config_settings: 'dict[str, str] | None' = None,
271+
metadata_directory: 'str | None' = None,
270272
) -> str:
271273
"""Produce a built wheel.
272274
@@ -278,9 +280,9 @@ def build_wheel(
278280
279281
"""
280282
with _prebuild_c_extensions(
281-
line_trace_cython_when_unset=False,
282-
build_inplace=False,
283-
config_settings=config_settings,
283+
line_trace_cython_when_unset=False,
284+
build_inplace=False,
285+
config_settings=config_settings,
284286
):
285287
return _setuptools_build_wheel(
286288
wheel_directory=wheel_directory,
@@ -291,9 +293,9 @@ def build_wheel(
291293

292294
@patched_dist_get_long_description()
293295
def build_editable(
294-
wheel_directory: str,
295-
config_settings: 'dict[str, str] | None' = None,
296-
metadata_directory: 'str | None' = None,
296+
wheel_directory: str,
297+
config_settings: 'dict[str, str] | None' = None,
298+
metadata_directory: 'str | None' = None,
297299
) -> str:
298300
"""Produce a built wheel for editable installs.
299301
@@ -305,9 +307,9 @@ def build_editable(
305307
306308
"""
307309
with _prebuild_c_extensions(
308-
line_trace_cython_when_unset=True,
309-
build_inplace=True,
310-
config_settings=config_settings,
310+
line_trace_cython_when_unset=True,
311+
build_inplace=True,
312+
config_settings=config_settings,
311313
):
312314
return _setuptools_build_editable(
313315
wheel_directory=wheel_directory,
@@ -317,7 +319,7 @@ def build_editable(
317319

318320

319321
def get_requires_for_build_wheel(
320-
config_settings: 'dict[str, str] | None' = None,
322+
config_settings: 'dict[str, str] | None' = None,
321323
) -> 'list[str]':
322324
"""Determine additional requirements for building wheels.
323325
@@ -330,9 +332,12 @@ def get_requires_for_build_wheel(
330332
'Cython; python_version < "3.12"',
331333
]
332334

333-
return _setuptools_get_requires_for_build_wheel(
334-
config_settings=config_settings,
335-
) + c_ext_build_deps
335+
return (
336+
_setuptools_get_requires_for_build_wheel(
337+
config_settings=config_settings,
338+
)
339+
+ c_ext_build_deps
340+
)
336341

337342

338343
build_sdist = patched_dist_get_long_description()(_setuptools_build_sdist)

packaging/pep517_backend/_transformers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def sanitize_rst_roles(rst_source_text: str) -> str: # noqa: WPS210
7676
gh_role_regex = r"""(?x)
7777
:gh:`(?P<gh_slug>[^`<]+)(?:\s+([^`]*))?`
7878
"""
79-
gh_substitution_pattern = (
80-
r'GitHub: ``\g<gh_slug>``'
81-
)
79+
gh_substitution_pattern = r'GitHub: ``\g<gh_slug>``'
8280

8381
meth_role_regex = r"""(?x)
8482
(?::py)?:meth:`~?(?P<rendered_text>[^`<]+)(?:\s+([^`]*))?`

packaging/pep517_backend/hooks.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010

1111
# Re-exporting PEP 517 hooks
1212
from ._backend import ( # type: ignore[assignment]
13-
build_sdist, build_wheel, get_requires_for_build_wheel,
13+
build_sdist,
14+
build_wheel,
15+
get_requires_for_build_wheel,
1416
prepare_metadata_for_build_wheel,
1517
)
1618

1719

18-
with _suppress(ImportError): # Only succeeds w/ setuptools implementing PEP 660
20+
with _suppress(
21+
ImportError,
22+
): # Only succeeds w/ setuptools implementing PEP 660
1923
# Re-exporting PEP 660 hooks
2024
from ._backend import ( # type: ignore[assignment]
21-
build_editable, get_requires_for_build_editable,
25+
build_editable,
26+
get_requires_for_build_editable,
2227
prepare_metadata_for_build_editable,
2328
)

src/pylibsshext/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"""Python bindings for libssh."""
44

55
from ._version import ( # noqa: F401, WPS300
6-
__full_version__, __libssh_version__, __version__, __version_info__,
6+
__full_version__,
7+
__libssh_version__,
8+
__version__,
9+
__version_info__,
710
)

src/pylibsshext/_version.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
from ._scm_version import version as __version__ # noqa: WPS300
1212
except ImportError:
1313
from pkg_resources import get_distribution as _get_dist
14+
1415
__version__ = _get_dist('ansible-pylibssh').version
1516

1617

1718
__full_version__ = (
18-
'<pylibsshext v{wrapper_ver!s} with libssh v{backend_ver!s}>'.
19-
format(wrapper_ver=__version__, backend_ver=__libssh_version__)
19+
'<pylibsshext v{wrapper_ver!s} with libssh v{backend_ver!s}>'.format(
20+
wrapper_ver=__version__,
21+
backend_ver=__libssh_version__,
22+
)
2023
)
2124
__version_info__ = tuple(
2225
(int(chunk) if chunk.isdigit() else chunk)

tests/_service_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def wait_for_svc_ready_state(
5252
'-oUserKnownHostsFile=/dev/null',
5353
'-oStrictHostKeyChecking=no',
5454
host,
55-
'--', 'exit 0',
55+
'--',
56+
'exit 0',
5657
]
5758

5859
attempts = 0
@@ -68,8 +69,10 @@ def wait_for_svc_ready_state(
6869

6970

7071
def ensure_ssh_session_connected(
71-
ssh_session, sshd_addr, ssh_clientkey_path,
72-
ssh_session_retries=0,
72+
ssh_session,
73+
sshd_addr,
74+
ssh_clientkey_path,
75+
ssh_session_retries=0,
7376
):
7477
"""Attempt connecting to the SSH server until successful.
7578

tests/conftest.py

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

1212
import pytest
1313
from _service_utils import (
14-
ensure_ssh_session_connected, wait_for_svc_ready_state,
14+
ensure_ssh_session_connected,
15+
wait_for_svc_ready_state,
1516
)
1617

1718
from pylibsshext.session import Session
@@ -98,7 +99,8 @@ def ssh_clientkey_path(sshd_path):
9899
'-tecdsa',
99100
'-b256',
100101
'-Cansible-pylibssh integration tests key',
101-
'-N', '', # empty string for no password
102+
'-N',
103+
'', # empty string for no password
102104
f'-f{path!s}',
103105
)
104106
subprocess.check_call(keygen_cmd)
@@ -179,7 +181,13 @@ def ssh_authorized_keys_path(sshd_path, ssh_clientkey_path):
179181

180182

181183
@pytest.fixture
182-
def sshd_addr(free_port_num, ssh_authorized_keys_path, sshd_hostkey_path, sshd_path, ssh_clientkey_path):
184+
def sshd_addr(
185+
free_port_num,
186+
ssh_authorized_keys_path,
187+
sshd_hostkey_path,
188+
sshd_path,
189+
ssh_clientkey_path,
190+
):
183191
"""Spawn an instance of sshd on a free port.
184192
185193
:raises RuntimeError: If spawning SSHD failed.
@@ -198,14 +206,12 @@ def sshd_addr(free_port_num, ssh_authorized_keys_path, sshd_hostkey_path, sshd_p
198206
'-oLogLevel=DEBUG3',
199207
f'-oHostKey={sshd_hostkey_path!s}',
200208
'-oPidFile={pid!s}'.format(pid=sshd_path / 'sshd.pid'),
201-
202209
# NOTE: 'UsePAM no' is not supported on Fedora.
203210
# Ref: https://bugzilla.redhat.com/show_bug.cgi?id=770756#c1
204211
'-oUsePAM=yes',
205212
'-oPasswordAuthentication=no',
206213
'-oChallengeResponseAuthentication=no',
207214
'-oGSSAPIAuthentication=no',
208-
209215
'-oStrictModes=no',
210216
'-oPermitEmptyPasswords=yes',
211217
'-oPermitRootLogin=yes',

tests/unit/channel_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ def exec_second_command(ssh_channel):
7979
u_cmd = ssh_channel.exec_command('echo -n Hello Again')
8080
assert u_cmd.returncode == 0
8181
assert u_cmd.stderr.decode() == ''
82-
assert u_cmd.stdout.decode() == u'Hello Again'
82+
assert u_cmd.stdout.decode() == 'Hello Again'
8383

8484

8585
def test_exec_command(ssh_channel):
8686
"""Test getting the output of a remotely executed command."""
8787
u_cmd = ssh_channel.exec_command('echo -n Hello World')
8888
assert u_cmd.returncode == 0
8989
assert u_cmd.stderr.decode() == ''
90-
assert u_cmd.stdout.decode() == u'Hello World'
90+
assert u_cmd.stdout.decode() == 'Hello World'
9191
# Test that repeated calls to exec_command do not segfault.
9292

9393
# NOTE: Call `exec_command()` once again from another function to
@@ -102,7 +102,7 @@ def test_exec_command_stderr(ssh_channel):
102102
"""Test getting the stderr of a remotely executed command."""
103103
u_cmd = ssh_channel.exec_command('echo -n Hello World 1>&2')
104104
assert u_cmd.returncode == 0
105-
assert u_cmd.stderr.decode() == u'Hello World'
105+
assert u_cmd.stderr.decode() == 'Hello World'
106106
assert u_cmd.stdout.decode() == ''
107107

108108

@@ -159,7 +159,9 @@ def test_send_eof(ssh_channel):
159159

160160
def test_send_signal(ssh_channel):
161161
"""Test send_signal correctly forwards signal to the process."""
162-
ssh_channel.request_exec('bash -c \'trap "exit 1" SIGUSR1; echo ready; sleep 5; exit 0\'')
162+
ssh_channel.request_exec(
163+
'bash -c \'trap "exit 1" SIGUSR1; echo ready; sleep 5; exit 0\'',
164+
)
163165

164166
# Wait until the process is ready to receive signal
165167
output = ''
@@ -203,6 +205,7 @@ def test_destructor(ssh_session_connect):
203205
204206
Test that this event does not cause a segfault in channels destructor.
205207
"""
208+
206209
def _do_not_crash(): # noqa: WPS430 # required to create a garbage-collection scope
207210
ssh_session = Session()
208211
ssh_session_connect(ssh_session)

0 commit comments

Comments
 (0)