Felix Fontein
14e6eb471b
Update formatting.
2026-01-18 11:39:59 +01:00
Felix Fontein
712d920941
Re-sort imports.
2025-12-25 23:27:25 +01:00
Felix Fontein
dbc7b0ec18
Cleanup with ruff check ( #1182 )
...
* Implement improvements suggested by ruff check.
* Add ruff check to CI.
2025-10-28 06:58:15 +01:00
Felix Fontein
be000755fc
Python code modernization, 8/n ( #1179 )
...
* Use to_text instead of to_native.
* Remove no longer needed pylint ignores.
* Remove another pylint ignore.
* Remove no longer needed ignore.
* Address redefined-outer-name.
* Address consider-using-with.
2025-10-25 00:36:04 +00:00
Felix Fontein
6ad4bfcd40
Add typing information, 2/n ( #1178 )
...
* Add typing to Docker Stack modules. Clean modules up.
* Add typing to Docker Swarm modules.
* Add typing to unit tests.
* Add more typing.
* Add ignore.txt entries.
2025-10-25 01:16:04 +02:00
Felix Fontein
3350283bcc
Add typing information, 1/2 ( #1176 )
...
* Re-enable typing and improve config.
* Make mypy pass.
* Improve settings.
* First batch of types.
* Add more type hints.
* Fixes.
* Format.
* Fix split_port() without returning to previous type chaos.
* Continue with type hints (and ignores).
2025-10-23 07:05:42 +02:00
Felix Fontein
c75aa5dd64
Python code modernization, 5/n ( #1165 )
...
* Address raise-missing-from.
* Address simplifiable-if-expression.
* Address unnecessary-dunder-call.
* Address unnecessary-pass.
* Address use-list-literal.
* Address unused-variable.
* Address use-dict-literal.
2025-10-12 16:02:27 +02:00
Felix Fontein
cad22de628
Python code modernization, 4/n ( #1162 )
...
* Address attribute-defined-outside-init.
* Address broad-exception-raised.
* Address broad-exception-caught.
* Address consider-iterating-dictionary.
* Address consider-using-dict-comprehension.
* Address consider-using-f-string.
* Address consider-using-in.
* Address consider-using-max-builtin.
* Address some consider-using-with.
* Address invalid-name.
* Address keyword-arg-before-vararg.
* Address line-too-long.
* Address no-else-continue.
* Address no-else-raise.
* Address no-else-return.
* Remove broken dead code.
* Make consider-using-f-string changes compatible with older Python versions.
* Python 3.11 and earlier apparently do not like multi-line f-strings.
2025-10-11 23:06:50 +02:00
Felix Fontein
e8ec22d3b1
Python code modernization, 3/n ( #1157 )
...
* Remove __metaclass__ = type.
for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do
sed -e '/^__metaclass__ = type/d' -i $i;
done
* Remove super arguments, and stop inheriting from object.
2025-10-10 08:11:58 +02:00
Felix Fontein
741c318b1d
Python code modernization, 2/n ( #1156 )
...
* Adjust all __future__ imports:
for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do
sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i;
done
* Remove all UTF-8 encoding specifications for Python source files:
for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do
sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i;
done
* Reformat.
2025-10-09 20:46:48 +02:00
Felix Fontein
a3efa26e2e
Address some pylint issues ( #1155 )
...
* Address cyclic-import.
* Address redefined-builtin.
* Address redefined-argument-from-local.
* Address many redefined-outer-name.
* Address pointless-string-statement.
* No longer needed due to separate bugfix.
* Address useless-return.
* Address possibly-used-before-assignment.
* Add TODOs.
* Address super-init-not-called.
* Address function-redefined.
* Address unspecified-encoding.
* Clean up more imports.
2025-10-09 20:11:36 +02:00
Felix Fontein
117271579e
Make all doc fragments, module utils, and plugin utils private ( #1144 )
...
* Make all doc fragments, module utils, and plugin utils private.
* Remove some unused and no longer needed imports.
This hopefully also fixes the CI issues, which do not happen locally for me...
* Fix formatting.
* Try to make CI happy, again.
* Fix imports.
* Lint.
2025-10-07 07:32:33 +02:00
Felix Fontein
d65d37e9e9
Reformat code with black and isort.
2025-10-06 18:34:59 +02:00
Felix Fontein
f45232635c
Python code modernization, 1/n ( #1141 )
...
* Remove unicode text prefixes.
* Replace str.format() uses with f-strings.
* Replace % with f-strings, and do some cleanup.
* Fix wrong variable.
* Avoid unnecessary string conversion.
2025-10-06 18:30:54 +02:00
Felix Fontein
1f2817fa20
Prepare 5.0.0 ( #1123 )
...
* Bump version to 5.0.0-a1.
* Drop support for ansible-core 2.15 and 2.16.
* Remove Python 2 and early Python 3 compatibility.
2025-10-05 20:22:50 +02:00
Felix Fontein
ebe42308cc
Replace ansible.module_utils.six with own module utils in some cases ( #1138 )
...
* Replace ansible.module_utils.six with own module utils in some cases.
* Add ignore.txt entires.
2025-10-04 23:45:27 +02:00
Felix Fontein
3b6068e44b
Add docker_context_info module ( #1039 )
...
* Vendor parts of the Docker SDK for Python
This is a combination of the latest git version
(https://github.com/docker/docker-py/tree/db7f8b8bb67e485a7192846906f600a52e0aa623 )
with some fixes to make it compatible with Python 2.7
and adjusting some imports.
* Polishing.
* Fix bug that prevents contexts to be found when no Docker config file is present.
Ref: https://github.com/docker/docker-py/issues/3190
* Linting.
* Fix typos.
* Adjust more to behavior of Docker CLI.
* Add first iteration of docker_context_info module.
* Improvements.
* Add basic CI.
* Add caveat on contexts[].config result.
2025-02-10 21:59:05 +01:00
Felix Fontein
f69536ef3b
Improve language.
2024-12-28 14:30:49 +01:00
Felix Fontein
8ad45286a3
Remove unused code that relies on functionality deprecated in Python 3.12. ( #834 )
2024-04-15 11:21:46 +00:00
Felix Fontein
4d9b85c975
Update vendored Docker SDK for Python code ( #694 )
...
* vendored Docker SDK for Python code: volume: added support for bind propagation
https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation
Cherry-picked from https://github.com/docker/docker-py/commit/bea63224e028226085c85caecace6480fe0aa6b0
Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de >
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* vendored Docker SDK for Python code: fix: eventlet compatibility
Check if poll attribute exists on select module instead of win32 platform check
The implementation done in #2865 is breaking usage of docker-py library within eventlet.
As per the Python `select.poll` documentation (https://docs.python.org/3/library/select.html#select.poll ) and eventlet select removal advice (eventlet/eventlet#608 (comment)), it is preferable to use an implementation based on the availability of the `poll()` method that trying to check if the platform is `win32`.
Fixes https://github.com/docker/docker-py/issues/3131
Cherry-picked from https://github.com/docker/docker-py/commit/78439ebbe1aae77ff0fd9b666894d80807182e28
Co-authored-by: Mathieu Virbel <mat@meltingrocks.com >
* vendored Docker SDK for Python code: fix: use response.text to get string rather than bytes
Adjusted from https://github.com/docker/docker-py/commit/0618951093bf3116af482c6dfb983219c5684343
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com >
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* vendored Docker SDK for Python code: Fix missing asserts or assignments
Cherry-picked from https://github.com/docker/docker-py/commit/0566f1260cd6f89588df2128ec4e86e8266e5d74
Co-authored-by: Aarni Koskela <akx@iki.fi >
---------
Co-authored-by: Janne Jakob Fleischer <janne.fleischer@ils-forschung.de >
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
Co-authored-by: Mathieu Virbel <mat@meltingrocks.com >
Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com >
Co-authored-by: Aarni Koskela <akx@iki.fi >
2023-10-08 18:16:27 +02:00
Felix Fontein
1660bf4104
vendored Docker SDK for Python code: update to latest version ( #619 )
...
* socket: fix for errors on pipe close in Windows (https://github.com/docker/docker-py/pull/3099 )
Need to return data, not size. By returning an empty
string, EOF will be detected properly since `len()`
will be `0`.
Fixes https://github.com/docker/docker-py/issues/3098 .
Cherry-picked from https://github.com/docker/docker-py/commit/f84623225e0227adde48ffd8f2e1cafb1f9aa38d
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* socket: use poll() instead of select() except on Windows (https://github.com/docker/docker-py/pull/2865 )
Fixes https://github.com/docker/docker-py/issues/2278 , which was originally addressed in https://github.com/docker/docker-py/pull/2279 , but was not
properly merged. Additionally it did not address the problem
of poll not existing on Windows. This patch falls back on the
more limited select method if host system is Windows.
Cherry-picked from https://github.com/docker/docker-py/commit/a02ba743338c27fd9348af2cf7767b140501734d
Co-authored-by: Tyler Westland <tylerofthewest@gmail.com >
* api: respect timeouts on Windows named pipes (https://github.com/docker/docker-py/pull/3112 )
Cherry-picked from https://github.com/docker/docker-py/commit/9cadad009e6aa78e15d752e2011705d7d91b8d2e
Co-authored-by: Imogen <59090860+ImogenBits@users.noreply.github.com >
* Add URL to changelog.
* api: avoid socket timeouts when executing commands (https://github.com/docker/docker-py/pull/3125 )
Only listen to read events when polling a socket in order
to avoid incorrectly trying to read from a socket that is
not actually ready.
Cherry-picked from https://github.com/docker/docker-py/commit/c5e582c413a4a3a9eff6ee8208d195f657ffda94
Co-authored-by: Loïc Leyendecker <loic.leyendecker@gmail.com >
---------
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
Co-authored-by: Tyler Westland <tylerofthewest@gmail.com >
Co-authored-by: Imogen <59090860+ImogenBits@users.noreply.github.com >
Co-authored-by: Loïc Leyendecker <loic.leyendecker@gmail.com >
2023-05-20 19:35:56 +02:00
Felix Fontein
2957138153
latest docker-py bugfix (npipe) ( #513 )
...
* socket: handle npipe close on Windows (https://github.com/docker/docker-py/pull/3056 )
Fixes https://github.com/docker/docker-py/issues/3045
Cherry-picked from https://github.com/docker/docker-py/commit/30022984f6445fbc322cbe97bb99aab1ddb1e4fd
Co-authored-by: Nick Santos <nick.santos@docker.com >
* Add changelog fragment.
Co-authored-by: Nick Santos <nick.santos@docker.com >
2022-12-01 06:59:05 +01:00
Felix Fontein
ae708a7333
Vendored Docker SDK for Python updates ( #434 )
...
* utils: fix IPv6 address w/ port parsing
This was using a deprecated function (`urllib.splitnport`),
ostensibly to work around issues with brackets on IPv6 addresses.
Ironically, its usage was broken, and would result in mangled IPv6
addresses if they had a port specified in some instances.
Usage of the deprecated function has been eliminated and extra test
cases added where missing. All existing cases pass as-is. (The only
other change to the test was to improve assertion messages.)
Cherry-picked from
https://github.com/docker/docker-py/commit/f16c4e1147c81afd822fe72191f0f720cb0ba637
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* client: fix exception semantics in _raise_for_status
We want "The above exception was the direct cause of the following exception:" instead of "During handling of the above exception, another exception occurred:"
Cherry-picked from
https://github.com/docker/docker-py/commit/bb11197ee3407798a53c50e43aa994fe8cd9c8e7
Co-authored-by: Maor Kleinberger <kmaork@gmail.com >
* tls: use auto-negotiated highest version
Specific TLS versions are deprecated in latest Python, which
causes test failures due to treating deprecation errors as
warnings.
Luckily, the fix here is straightforward: we can eliminate some
custom version selection logic by using `PROTOCOL_TLS_CLIENT`,
which is the recommended method and will select the highest TLS
version supported by both client and server.
Cherry-picked from
https://github.com/docker/docker-py/commit/56dd6de7dfad9bedc7c8af99308707ecc3fad78e
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* transport: fix ProxyCommand for SSH conn
Cherry-picked from
https://github.com/docker/docker-py/commit/4e19cc48dfd88d0a9a8bdbbe4df4357322619d02
Co-authored-by: Guy Lichtman <glicht@users.noreply.github.com >
* ssh: do not create unnecessary subshell on exec
Cherry-picked from
https://github.com/docker/docker-py/commit/bb40ba051fc67605d5c9e7fd1eb5f9aa3e0fb501
Co-authored-by: liubo <liubo@uniontech.com >
* ssh: reject unknown host keys when using Python SSH impl
In the Secure Shell (SSH) protocol, host keys are used to verify the identity of remote hosts. Accepting unknown host keys may leave the connection open to man-in-the-middle attacks.
Do not accept unknown host keys. In particular, do not set the default missing host key policy for the Paramiko library to either AutoAddPolicy or WarningPolicy. Both of these policies continue even when the host key is unknown. The default setting of RejectPolicy is secure because it throws an exception when it encounters an unknown host key.
Reference: https://cwe.mitre.org/data/definitions/295.html
NOTE: This only affects SSH connections using the native Python SSH implementation (Paramiko), when `use_ssh_client=False` (default). If using the system SSH client (`use_ssh_client=True`), the host configuration
(e.g. `~/.ssh/config`) will apply.
Cherry-picked from
https://github.com/docker/docker-py/commit/d9298647d91c52e1ee9ac448e43a7fea1c69bdbe
Co-authored-by: Audun Nes <audun.nes@gmail.com >
* lint: fix deprecation warnings from threading package
Set `daemon` attribute instead of using `setDaemon` method that
was deprecated in Python 3.10.
Cherry-picked from
https://github.com/docker/docker-py/commit/adf5a97b1203623ae47bf7aa1367b6bb7c261980
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com >
* api: preserve cause when re-raising error
Use `from e` to ensure that the error context is propagated
correctly.
Cherry-picked from
https://github.com/docker/docker-py/commit/05e143429e892fb838bbff058391456ba3d0a19c
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
* build: trim trailing whitespace from dockerignore entries
Cherry-picked from
https://github.com/docker/docker-py/commit/3ee3a2486fe75ed858f8a3defe0fc79b2743d5df
Co-authored-by: Clément Loiselet <clement.loiselet@capgemini.com >
* Improve formulation, also mention the security change as a breaking change.
Co-authored-by: Milas Bowman <milas.bowman@docker.com >
Co-authored-by: Maor Kleinberger <kmaork@gmail.com >
Co-authored-by: Guy Lichtman <glicht@users.noreply.github.com >
Co-authored-by: liubo <liubo@uniontech.com >
Co-authored-by: Audun Nes <audun.nes@gmail.com >
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com >
Co-authored-by: Clément Loiselet <clement.loiselet@capgemini.com >
2022-07-31 17:09:18 +02:00
Felix Fontein
a4539a309e
Move licenses to LICENSES/, use SPDX-License-Identifier, mention all licenses in galaxy.yml ( #430 )
...
* Move licenses to LICENSES/, use SPDX-License-Identifier, mention all licenses in galaxy.yml.
* ignore.txt lines cannot be empty or contain only a comment.
* Cleanup.
* This particular __init__.py seems to be crucial.
* Try extra newline.
* Markdown comments are a real mess. I hope this won't break Galaxy...
* More licenses.
* Add sanity test.
* Skip some files, lint.
* Make sure there is a copyright line everywhere.
* Also check for copyright line in sanity tests.
* Remove colon after 'Copyright'.
* Normalize lint script.
* Avoid colon after 'Copyright' in lint script.
* Improve license checker.
* Update README.md
Co-authored-by: Maxwell G <9920591+gotmax23@users.noreply.github.com >
* Remove superfluous space.
* Referencing target instead of symlink
Co-authored-by: Maxwell G <9920591+gotmax23@users.noreply.github.com >
2022-07-20 07:45:33 +02:00
Felix Fontein
4d508b4c37
Vendor API connection code from Docker SDK for Python ( #398 )
...
* Vendor parts of the Docker SDK for Python
This is a combination of the latest git version
(https://github.com/docker/docker-py/tree/a48a5a9647761406d66e8271f19fab7fa0c5f582 )
and the version before Python 2.7 support was removed
(https://github.com/docker/docker-py/tree/650aad3a5fb84059b392ad450f760ed08143ae3f ),
including some modifications to work with Ansible module_utils's
system (i.e. third-party imports are guarded, and errors are
reported during runtime through a new exception
MissingRequirementException).
* Create module_utils and plugin_utils for working with the vendored code.
The delete call cannot be called delete() since that method already exists from requests.
* Vendor more code from Docker SDK for Python.
* Adjust code from common module_utils.
* Add unit tests from Docker SDK for Python.
* Make test compile with Python 2.6, but skip them on Python 2.6.
* Skip test that requires a network server.
* Add changelog.
* Update changelogs/fragments/398-docker-api.yml
Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com >
* Minimum API version is 1.25.
Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com >
2022-07-02 16:40:44 +02:00