From 08956b5fbc1adc76681fea308526a9c77065c22b Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 3 Jan 2024 20:49:07 +0200 Subject: [PATCH] ci: update Ruff & fix some minor issues (#3206) Signed-off-by: Aarni Koskela --- .github/workflows/ci.yml | 2 +- docker/models/containers.py | 6 +++--- docker/utils/socket.py | 4 ++-- docker/utils/utils.py | 2 +- pyproject.toml | 4 +++- test-requirements.txt | 2 +- tests/integration/api_build_test.py | 4 +--- tests/ssh/api_build_test.py | 4 +--- tests/unit/api_test.py | 2 +- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 127d5b68..628c5350 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.x' - - run: pip install -U ruff==0.0.284 + - run: pip install -U ruff==0.1.8 - name: Run ruff run: ruff docker tests diff --git a/docker/models/containers.py b/docker/models/containers.py index 4725d6f6..32676bb8 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -903,9 +903,9 @@ class ContainerCollection(Collection): container, exit_status, command, image, out ) - return out if stream or out is None else b''.join( - [line for line in out] - ) + if stream or out is None: + return out + return b''.join(out) def create(self, image, command=None, **kwargs): """ diff --git a/docker/utils/socket.py b/docker/utils/socket.py index 2306ed07..c7cb584d 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 dbd51303..efe9f9a3 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 0a672796..a64e120e 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/test-requirements.txt b/test-requirements.txt index 031d0acf..2c0e3622 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,6 @@ setuptools==65.5.1 coverage==7.2.7 -ruff==0.0.284 +ruff==0.1.8 pytest==7.4.2 pytest-cov==4.1.0 pytest-timeout==2.1.0 diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index 2add2d87..540ef2b0 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -389,9 +389,7 @@ class BuildTest(BaseAPIIntegrationTest): 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 d060f465..3b542994 100644 --- a/tests/ssh/api_build_test.py +++ b/tests/ssh/api_build_test.py @@ -380,9 +380,7 @@ class BuildTest(BaseAPIIntegrationTest): 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 7bc2ea8c..0ca9bbb9 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}/'