diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 127d5b682..628c53504 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 4725d6f6f..32676bb85 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -903,9 +903,9 @@ def run(self, image, command=None, stdout=True, stderr=False, 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 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/test-requirements.txt b/test-requirements.txt index 031d0acf0..2c0e3622c 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 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}/'