Debian Codegraph @

ansible_collections/community/docker/plugins/module_utils/_api/credentials/utils.py

raw
1 # This code is part of the Ansible collection community.docker, but is an independent component.
2 # This particular file, and this file only, is based on the Docker SDK for Python (https://github.com/docker/docker-py/)
3 #
4 # Copyright (c) 2016-2022 Docker, Inc.
5 #
6 # It is licensed under the Apache 2.0 license (see LICENSES/Apache-2.0.txt in this collection)
7 # SPDX-License-Identifier: Apache-2.0
8
9 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
10 # Do not use this from other collections or standalone plugins/modules!
11
12 from __future__ import annotations
13
14 import os
15 from shutil import which
16
17
18 def find_executable(executable: str, path: str | None = None) -> str | None:
19 """
20 As distutils.spawn.find_executable, but on Windows, look up
21 every extension declared in PATHEXT instead of just `.exe`
22 """
23 # shutil.which() already uses PATHEXT on Windows, so on
24 # Python 3 we can simply use shutil.which() in all cases.
25 # (https://github.com/docker/docker-py/commit/42789818bed5d86b487a030e2e60b02bf0cfa284)
26 return which(executable, path=path)
27
28
29 def create_environment_dict(overrides: dict[str, str] | None) -> dict[str, str]:
30 """
31 Create and return a copy of os.environ with the specified overrides
32 """
33 result = os.environ.copy()
34 result.update(overrides or {})
35 return result