Skip to content

Commit 5abae2d

Browse files
authored
Merge branch 'main' into patch-1
2 parents f0d38fb + c38656d commit 5abae2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+566
-565
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ env:
66
DOCKER_BUILDKIT: '1'
77

88
jobs:
9-
flake8:
9+
lint:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
1313
- uses: actions/setup-python@v4
1414
with:
15-
python-version: '3.x'
16-
- run: pip install -U flake8
17-
- name: Run flake8
18-
run: flake8 docker/ tests/
15+
python-version: '3.11'
16+
- run: pip install -U ruff==0.0.284
17+
- name: Run ruff
18+
run: ruff docker tests
1919

2020
unit-tests:
2121
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ paragraph in the Docker contribution guidelines.
4444
Before we can review your pull request, please ensure that nothing has been
4545
broken by your changes by running the test suite. You can do so simply by
4646
running `make test` in the project root. This also includes coding style using
47-
`flake8`
47+
`ruff`
4848

4949
### 3. Write clear, self-contained commits
5050

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ build-dind-certs:
4646
docker build -t dpy-dind-certs -f tests/Dockerfile-dind-certs .
4747

4848
.PHONY: test
49-
test: flake8 unit-test-py3 integration-dind integration-dind-ssl
49+
test: ruff unit-test-py3 integration-dind integration-dind-ssl
5050

5151
.PHONY: unit-test-py3
5252
unit-test-py3: build-py3
@@ -163,9 +163,9 @@ integration-dind-ssl: build-dind-certs build-py3 setup-network
163163

164164
docker rm -vf dpy-dind-ssl dpy-dind-certs
165165

166-
.PHONY: flake8
167-
flake8: build-py3
168-
docker run -t --rm docker-sdk-python3 flake8 docker tests
166+
.PHONY: ruff
167+
ruff: build-py3
168+
docker run -t --rm docker-sdk-python3 ruff docker tests
169169

170170
.PHONY: docs
171171
docs: build-docs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Docker SDK for Python
22

3-
[![Build Status](https://github.com/docker/docker-py/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/docker/docker-py/actions/workflows/ci.yml/)
3+
[![Build Status](https://github.com/docker/docker-py/actions/workflows/ci.yml/badge.svg)](https://github.com/docker/docker-py/actions/workflows/ci.yml)
44

55
A Python library for the Docker Engine API. It lets you do anything the `docker` command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.
66

docker/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# flake8: noqa
21
from .api import APIClient
32
from .client import DockerClient, from_env
43
from .context import Context

docker/api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# flake8: noqa
21
from .client import APIClient

docker/api/build.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ def _set_auth_headers(self, headers):
314314
auth_data[auth.INDEX_URL] = auth_data.get(auth.INDEX_NAME, {})
315315

316316
log.debug(
317-
'Sending auth config ({})'.format(
318-
', '.join(repr(k) for k in auth_data.keys())
319-
)
317+
"Sending auth config (%s)",
318+
', '.join(repr(k) for k in auth_data),
320319
)
321320

322321
if auth_data:
@@ -336,12 +335,9 @@ def process_dockerfile(dockerfile, path):
336335
abs_dockerfile = os.path.join(path, dockerfile)
337336
if constants.IS_WINDOWS_PLATFORM and path.startswith(
338337
constants.WINDOWS_LONGPATH_PREFIX):
339-
abs_dockerfile = '{}{}'.format(
340-
constants.WINDOWS_LONGPATH_PREFIX,
341-
os.path.normpath(
342-
abs_dockerfile[len(constants.WINDOWS_LONGPATH_PREFIX):]
343-
)
344-
)
338+
normpath = os.path.normpath(
339+
abs_dockerfile[len(constants.WINDOWS_LONGPATH_PREFIX):])
340+
abs_dockerfile = f'{constants.WINDOWS_LONGPATH_PREFIX}{normpath}'
345341
if (os.path.splitdrive(path)[0] != os.path.splitdrive(abs_dockerfile)[0] or
346342
os.path.relpath(abs_dockerfile, path).startswith('..')):
347343
# Dockerfile not in context - read data to insert into tar later

docker/api/client.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ def __init__(self, base_url=None, version=None,
160160
base_url, timeout, pool_connections=num_pools,
161161
max_pool_size=max_pool_size
162162
)
163-
except NameError:
163+
except NameError as err:
164164
raise DockerException(
165165
'Install pypiwin32 package to enable npipe:// support'
166-
)
166+
) from err
167167
self.mount('http+docker://', self._custom_adapter)
168168
self.base_url = 'http+docker://localnpipe'
169169
elif base_url.startswith('ssh://'):
@@ -172,10 +172,10 @@ def __init__(self, base_url=None, version=None,
172172
base_url, timeout, pool_connections=num_pools,
173173
max_pool_size=max_pool_size, shell_out=use_ssh_client
174174
)
175-
except NameError:
175+
except NameError as err:
176176
raise DockerException(
177177
'Install paramiko package to enable ssh:// support'
178-
)
178+
) from err
179179
self.mount('http+docker://ssh', self._custom_adapter)
180180
self._unmount('http://', 'https://')
181181
self.base_url = 'http+docker://ssh'
@@ -199,28 +199,27 @@ def __init__(self, base_url=None, version=None,
199199
self._version = version
200200
if not isinstance(self._version, str):
201201
raise DockerException(
202-
'Version parameter must be a string or None. Found {}'.format(
203-
type(version).__name__
204-
)
202+
'Version parameter must be a string or None. '
203+
f'Found {type(version).__name__}'
205204
)
206205
if utils.version_lt(self._version, MINIMUM_DOCKER_API_VERSION):
207206
raise InvalidVersion(
208-
'API versions below {} are no longer supported by this '
209-
'library.'.format(MINIMUM_DOCKER_API_VERSION)
207+
f'API versions below {MINIMUM_DOCKER_API_VERSION} are '
208+
f'no longer supported by this library.'
210209
)
211210

212211
def _retrieve_server_version(self):
213212
try:
214213
return self.version(api_version=False)["ApiVersion"]
215-
except KeyError:
214+
except KeyError as ke:
216215
raise DockerException(
217216
'Invalid response from docker daemon: key "ApiVersion"'
218217
' is missing.'
219-
)
218+
) from ke
220219
except Exception as e:
221220
raise DockerException(
222221
f'Error while fetching server API version: {e}'
223-
)
222+
) from e
224223

225224
def _set_request_timeout(self, kwargs):
226225
"""Prepare the kwargs for an HTTP request by inserting the timeout
@@ -248,19 +247,17 @@ def _url(self, pathfmt, *args, **kwargs):
248247
for arg in args:
249248
if not isinstance(arg, str):
250249
raise ValueError(
251-
'Expected a string but found {} ({}) '
252-
'instead'.format(arg, type(arg))
250+
f'Expected a string but found {arg} ({type(arg)}) instead'
253251
)
254252

255253
quote_f = partial(urllib.parse.quote, safe="/:")
256254
args = map(quote_f, args)
257255

256+
formatted_path = pathfmt.format(*args)
258257
if kwargs.get('versioned_api', True):
259-
return '{}/v{}{}'.format(
260-
self.base_url, self._version, pathfmt.format(*args)
261-
)
258+
return f'{self.base_url}/v{self._version}{formatted_path}'
262259
else:
263-
return f'{self.base_url}{pathfmt.format(*args)}'
260+
return f'{self.base_url}{formatted_path}'
264261

265262
def _raise_for_status(self, response):
266263
"""Raises stored :class:`APIError`, if one occurred."""
@@ -479,7 +476,7 @@ def _get_result_tty(self, stream, res, is_tty):
479476
return self._multiplexed_response_stream_helper(res)
480477
else:
481478
return sep.join(
482-
[x for x in self._multiplexed_buffer_helper(res)]
479+
list(self._multiplexed_buffer_helper(res))
483480
)
484481

485482
def _unmount(self, *args):

docker/api/container.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def attach_socket(self, container, params=None, ws=False):
112112

113113
@utils.check_resource('container')
114114
def commit(self, container, repository=None, tag=None, message=None,
115-
author=None, changes=None, conf=None):
115+
author=None, pause=True, changes=None, conf=None):
116116
"""
117117
Commit a container to an image. Similar to the ``docker commit``
118118
command.
@@ -123,6 +123,7 @@ def commit(self, container, repository=None, tag=None, message=None,
123123
tag (str): The tag to push
124124
message (str): A commit message
125125
author (str): The name of the author
126+
pause (bool): Whether to pause the container before committing
126127
changes (str): Dockerfile instructions to apply while committing
127128
conf (dict): The configuration for the container. See the
128129
`Engine API documentation
@@ -139,6 +140,7 @@ def commit(self, container, repository=None, tag=None, message=None,
139140
'tag': tag,
140141
'comment': message,
141142
'author': author,
143+
'pause': pause,
142144
'changes': changes
143145
}
144146
u = self._url("/commit")
@@ -317,6 +319,11 @@ def create_container(self, image, command=None, hostname=None, user=None,
317319
'/var/www': {
318320
'bind': '/mnt/vol1',
319321
'mode': 'ro',
322+
},
323+
'/autofs/user1': {
324+
'bind': '/mnt/vol3',
325+
'mode': 'rw',
326+
'propagation': 'shared'
320327
}
321328
})
322329
)
@@ -327,10 +334,11 @@ def create_container(self, image, command=None, hostname=None, user=None,
327334
.. code-block:: python
328335
329336
container_id = client.api.create_container(
330-
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
337+
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2', '/mnt/vol3'],
331338
host_config=client.api.create_host_config(binds=[
332339
'/home/user1/:/mnt/vol2',
333340
'/var/www:/mnt/vol1:ro',
341+
'/autofs/user1:/mnt/vol3:rw,shared',
334342
])
335343
)
336344
@@ -861,8 +869,8 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
861869
params['since'] = since
862870
else:
863871
raise errors.InvalidArgument(
864-
'since value should be datetime or positive int/float, '
865-
'not {}'.format(type(since))
872+
'since value should be datetime or positive int/float,'
873+
f' not {type(since)}'
866874
)
867875

868876
if until is not None:
@@ -878,8 +886,8 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
878886
params['until'] = until
879887
else:
880888
raise errors.InvalidArgument(
881-
'until value should be datetime or positive int/float, '
882-
'not {}'.format(type(until))
889+
f'until value should be datetime or positive int/float, '
890+
f'not {type(until)}'
883891
)
884892

885893
url = self._url("/containers/{0}/logs", container)
@@ -951,7 +959,7 @@ def port(self, container, private_port):
951959
return port_settings.get(private_port)
952960

953961
for protocol in ['tcp', 'udp', 'sctp']:
954-
h_ports = port_settings.get(private_port + '/' + protocol)
962+
h_ports = port_settings.get(f"{private_port}/{protocol}")
955963
if h_ports:
956964
break
957965

docker/api/service.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ def _check_api_features(version, task_template, update_config, endpoint_spec,
77

88
def raise_version_error(param, min_version):
99
raise errors.InvalidVersion(
10-
'{} is not supported in API version < {}'.format(
11-
param, min_version
12-
)
10+
f'{param} is not supported in API version < {min_version}'
1311
)
1412

1513
if update_config is not None:

0 commit comments

Comments
 (0)