From aa9c066b8d67f0536f43920cbbd44c7208d40113 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 21 Dec 2023 10:28:46 +0200 Subject: [PATCH] Correct Ruff target version, enable UP, autofix Signed-off-by: Aarni Koskela --- docker/utils/socket.py | 4 ++-- docker/utils/utils.py | 2 +- pyproject.toml | 4 +++- tests/integration/api_build_test.py | 4 +--- tests/ssh/api_build_test.py | 4 +--- tests/unit/api_test.py | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docker/utils/socket.py b/docker/utils/socket.py index 2306ed073..c7cb584d4 100644 --- a/docker/utils/socket.py +++ b/docker/utils/socket.py @@ -64,7 +64,7 @@ def read_exactly(socket, n): Reads exactly n bytes from socket Raises SocketError if there isn't enough data """ - data = bytes() + data = b"" while len(data) < n: next_data = read(socket, n - len(data)) if not next_data: @@ -152,7 +152,7 @@ def consume_socket_output(frames, demux=False): if demux is False: # If the streams are multiplexed, the generator returns strings, that # we just need to concatenate. - return bytes().join(frames) + return b"".join(frames) # If the streams are demultiplexed, the generator yields tuples # (stdout, stderr) diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 759ddd2f1..4b3fb7cff 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -152,7 +152,7 @@ def convert_volume_binds(binds): ] if 'propagation' in v and v['propagation'] in propagation_modes: if mode: - mode = ','.join([mode, v['propagation']]) + mode = f"{mode},{v['propagation']}" else: mode = v['propagation'] diff --git a/pyproject.toml b/pyproject.toml index 0a6727966..a64e120ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,14 +5,16 @@ requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] write_to = 'docker/_version.py' [tool.ruff] -target-version = "py37" +target-version = "py38" extend-select = [ "B", "C", "F", + "UP", "W", ] ignore = [ + "UP012", # unnecessary `UTF-8` argument (we want to be explicit) "C901", # too complex (there's a whole bunch of these) ] diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index 2add2d87a..540ef2b0f 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -389,9 +389,7 @@ def test_build_stderr_data(self): lines = [] for chunk in stream: lines.append(chunk.get('stream')) - expected = '{0}{2}\n{1}'.format( - control_chars[0], control_chars[1], snippet - ) + expected = f'{control_chars[0]}{snippet}\n{control_chars[1]}' assert any(line == expected for line in lines) def test_build_gzip_encoding(self): diff --git a/tests/ssh/api_build_test.py b/tests/ssh/api_build_test.py index d060f465f..3b542994f 100644 --- a/tests/ssh/api_build_test.py +++ b/tests/ssh/api_build_test.py @@ -380,9 +380,7 @@ def test_build_stderr_data(self): lines = [] for chunk in stream: lines.append(chunk.get('stream')) - expected = '{0}{2}\n{1}'.format( - control_chars[0], control_chars[1], snippet - ) + expected = f'{control_chars[0]}{snippet}\n{control_chars[1]}' assert any(line == expected for line in lines) def test_build_gzip_encoding(self): diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py index 7bc2ea8cd..0ca9bbb95 100644 --- a/tests/unit/api_test.py +++ b/tests/unit/api_test.py @@ -82,7 +82,7 @@ def fake_delete(self, url, *args, **kwargs): def fake_read_from_socket(self, response, stream, tty=False, demux=False): - return bytes() + return b'' url_base = f'{fake_api.prefix}/'