Skip to content

Commit 6014767

Browse files
committed
Enable Ruff C rules and autofix
Signed-off-by: Aarni Koskela <akx@iki.fi>
1 parent ec58856 commit 6014767

14 files changed

+147
-140
lines changed

docker/api/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def _get_result_tty(self, stream, res, is_tty):
476476
return self._multiplexed_response_stream_helper(res)
477477
else:
478478
return sep.join(
479-
[x for x in self._multiplexed_buffer_helper(res)]
479+
list(self._multiplexed_buffer_helper(res))
480480
)
481481

482482
def _unmount(self, *args):

docker/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def parse_host(addr, is_win32=False, tls=False):
217217

218218
parsed_url = urlparse(addr)
219219
proto = parsed_url.scheme
220-
if not proto or any([x not in f"{string.ascii_letters}+" for x in proto]):
220+
if not proto or any(x not in f"{string.ascii_letters}+" for x in proto):
221221
# https://bugs.python.org/issue754016
222222
parsed_url = urlparse(f"//{addr}", 'tcp')
223223
proto = 'tcp'

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,16 @@ requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
44
[tool.setuptools_scm]
55
write_to = 'docker/_version.py'
66

7+
[tool.ruff]
8+
target-version = "py37"
9+
extend-select = [
10+
"C",
11+
"F",
12+
"W",
13+
]
14+
ignore = [
15+
"C901", # too complex (there's a whole bunch of these)
16+
]
17+
718
[tool.ruff.per-file-ignores]
819
"**/__init__.py" = ["F401"]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
with open('./test-requirements.txt') as test_reqs_txt:
33-
test_requirements = [line for line in test_reqs_txt]
33+
test_requirements = list(test_reqs_txt)
3434

3535

3636
long_description = ''

tests/integration/api_build_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_build_with_dockerignore(self):
142142

143143
logs = logs.decode('utf-8')
144144

145-
assert sorted(list(filter(None, logs.split('\n')))) == sorted([
145+
assert sorted(filter(None, logs.split('\n'))) == sorted([
146146
'/test/#file.txt',
147147
'/test/ignored/subdir/excepted-with-spaces',
148148
'/test/ignored/subdir/excepted-file',
@@ -312,7 +312,7 @@ def test_build_with_network_mode(self):
312312
)
313313

314314
self.tmp_imgs.append('dockerpytest_nonebuild')
315-
logs = [chunk for chunk in stream]
315+
logs = list(stream)
316316
assert 'errorDetail' in logs[-1]
317317
assert logs[-1]['errorDetail']['code'] == 1
318318

@@ -392,7 +392,7 @@ def test_build_stderr_data(self):
392392
expected = '{0}{2}\n{1}'.format(
393393
control_chars[0], control_chars[1], snippet
394394
)
395-
assert any([line == expected for line in lines])
395+
assert any(line == expected for line in lines)
396396

397397
def test_build_gzip_encoding(self):
398398
base_dir = tempfile.mkdtemp()

tests/integration/api_healthcheck_test.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HealthcheckTest(BaseAPIIntegrationTest):
1616
@helpers.requires_api_version('1.24')
1717
def test_healthcheck_shell_command(self):
1818
container = self.client.create_container(
19-
TEST_IMG, 'top', healthcheck=dict(test='echo "hello world"'))
19+
TEST_IMG, 'top', healthcheck={'test': 'echo "hello world"'})
2020
self.tmp_containers.append(container)
2121

2222
res = self.client.inspect_container(container)
@@ -27,40 +27,40 @@ def test_healthcheck_shell_command(self):
2727
@helpers.requires_api_version('1.24')
2828
def test_healthcheck_passes(self):
2929
container = self.client.create_container(
30-
TEST_IMG, 'top', healthcheck=dict(
31-
test="true",
32-
interval=1 * SECOND,
33-
timeout=1 * SECOND,
34-
retries=1,
35-
))
30+
TEST_IMG, 'top', healthcheck={
31+
'test': "true",
32+
'interval': 1 * SECOND,
33+
'timeout': 1 * SECOND,
34+
'retries': 1,
35+
})
3636
self.tmp_containers.append(container)
3737
self.client.start(container)
3838
wait_on_health_status(self.client, container, "healthy")
3939

4040
@helpers.requires_api_version('1.24')
4141
def test_healthcheck_fails(self):
4242
container = self.client.create_container(
43-
TEST_IMG, 'top', healthcheck=dict(
44-
test="false",
45-
interval=1 * SECOND,
46-
timeout=1 * SECOND,
47-
retries=1,
48-
))
43+
TEST_IMG, 'top', healthcheck={
44+
'test': "false",
45+
'interval': 1 * SECOND,
46+
'timeout': 1 * SECOND,
47+
'retries': 1,
48+
})
4949
self.tmp_containers.append(container)
5050
self.client.start(container)
5151
wait_on_health_status(self.client, container, "unhealthy")
5252

5353
@helpers.requires_api_version('1.29')
5454
def test_healthcheck_start_period(self):
5555
container = self.client.create_container(
56-
TEST_IMG, 'top', healthcheck=dict(
57-
test="echo 'x' >> /counter.txt && "
56+
TEST_IMG, 'top', healthcheck={
57+
'test': "echo 'x' >> /counter.txt && "
5858
"test `cat /counter.txt | wc -l` -ge 3",
59-
interval=1 * SECOND,
60-
timeout=1 * SECOND,
61-
retries=1,
62-
start_period=3 * SECOND
63-
)
59+
'interval': 1 * SECOND,
60+
'timeout': 1 * SECOND,
61+
'retries': 1,
62+
'start_period': 3 * SECOND
63+
}
6464
)
6565

6666
self.tmp_containers.append(container)

tests/integration/api_image_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,8 @@ def test_get_load_image(self):
263263
data = self.client.get_image(test_img)
264264
assert data
265265
output = self.client.load_image(data)
266-
assert any([
267-
line for line in output
268-
if f'Loaded image: {test_img}' in line.get('stream', '')
269-
])
266+
assert any(line for line in output
267+
if f'Loaded image: {test_img}' in line.get('stream', ''))
270268

271269
@contextlib.contextmanager
272270
def temporary_http_file_server(self, stream):

tests/integration/api_plugin_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_install_plugin(self):
118118
pass
119119

120120
prv = self.client.plugin_privileges(SSHFS)
121-
logs = [d for d in self.client.pull_plugin(SSHFS, prv)]
121+
logs = list(self.client.pull_plugin(SSHFS, prv))
122122
assert filter(lambda x: x['status'] == 'Download complete', logs)
123123
assert self.client.inspect_plugin(SSHFS)
124124
assert self.client.enable_plugin(SSHFS)
@@ -128,7 +128,7 @@ def test_upgrade_plugin(self):
128128
pl_data = self.ensure_plugin_installed(SSHFS)
129129
assert pl_data['Enabled'] is False
130130
prv = self.client.plugin_privileges(SSHFS)
131-
logs = [d for d in self.client.upgrade_plugin(SSHFS, SSHFS, prv)]
131+
logs = list(self.client.upgrade_plugin(SSHFS, SSHFS, prv))
132132
assert filter(lambda x: x['status'] == 'Download complete', logs)
133133
assert self.client.inspect_plugin(SSHFS)
134134
assert self.client.enable_plugin(SSHFS)

tests/integration/context_api_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_lifecycle(self):
2929
"test", tls_cfg=docker_tls)
3030

3131
# check for a context 'test' in the context store
32-
assert any([ctx.Name == "test" for ctx in ContextAPI.contexts()])
32+
assert any(ctx.Name == "test" for ctx in ContextAPI.contexts())
3333
# retrieve a context object for 'test'
3434
assert ContextAPI.get_context("test")
3535
# remove context

tests/integration/models_containers_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_run_with_none_driver(self):
109109

110110
out = client.containers.run(
111111
"alpine", "echo hello",
112-
log_config=dict(type='none')
112+
log_config={"type": 'none'}
113113
)
114114
assert out is None
115115

@@ -118,7 +118,7 @@ def test_run_with_json_file_driver(self):
118118

119119
out = client.containers.run(
120120
"alpine", "echo hello",
121-
log_config=dict(type='json-file')
121+
log_config={"type": 'json-file'}
122122
)
123123
assert out == b'hello\n'
124124

@@ -150,7 +150,7 @@ def test_run_with_streamed_logs(self):
150150
out = client.containers.run(
151151
'alpine', 'sh -c "echo hello && echo world"', stream=True
152152
)
153-
logs = [line for line in out]
153+
logs = list(out)
154154
assert logs[0] == b'hello\n'
155155
assert logs[1] == b'world\n'
156156

@@ -165,7 +165,7 @@ def test_run_with_streamed_logs_and_cancel(self):
165165

166166
threading.Timer(1, out.close).start()
167167

168-
logs = [line for line in out]
168+
logs = list(out)
169169

170170
assert len(logs) == 2
171171
assert logs[0] == b'hello\n'

0 commit comments

Comments
 (0)