use f-strings in module utils (#10901)
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run

* use f-strings in module utils

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* remove unused imports

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Alexei Znamensky 2025-10-11 22:43:43 +13:00 committed by GitHub
commit b85e263466
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 270 additions and 382 deletions

View file

@ -12,32 +12,28 @@ import re
def _create_regex_group_complement(s):
lines = (line.strip() for line in s.split("\n") if line.strip())
chars = filter(None, (line.split("#")[0].strip() for line in lines))
group = r"[^" + r"".join(chars) + r"]"
group = rf"[^{''.join(chars)}]"
return re.compile(group)
class HomebrewValidate(object):
# class regexes ------------------------------------------------ {{{
VALID_PATH_CHARS = r"""
VALID_PATH_CHARS = rf"""
\w # alphanumeric characters (i.e., [a-zA-Z0-9_])
\s # spaces
: # colons
{sep} # the OS-specific path separator
{os.path.sep} # the OS-specific path separator
. # dots
\- # dashes
""".format(
sep=os.path.sep
)
"""
VALID_BREW_PATH_CHARS = r"""
VALID_BREW_PATH_CHARS = rf"""
\w # alphanumeric characters (i.e., [a-zA-Z0-9_])
\s # spaces
{sep} # the OS-specific path separator
{os.path.sep} # the OS-specific path separator
. # dots
\- # dashes
""".format(
sep=os.path.sep
)
"""
VALID_PACKAGE_CHARS = r"""
\w # alphanumeric characters (i.e., [a-zA-Z0-9_])
@ -123,17 +119,17 @@ def parse_brew_path(module):
"""
path = module.params["path"]
if not HomebrewValidate.valid_path(path):
module.fail_json(msg="Invalid path: {0}".format(path))
module.fail_json(msg=f"Invalid path: {path}")
if isinstance(path, str):
paths = path.split(":")
elif isinstance(path, list):
paths = path
else:
module.fail_json(msg="Invalid path: {0}".format(path))
module.fail_json(msg=f"Invalid path: {path}")
brew_path = module.get_bin_path("brew", required=True, opt_dirs=paths)
if not HomebrewValidate.valid_brew_path(brew_path):
module.fail_json(msg="Invalid brew path: {0}".format(brew_path))
module.fail_json(msg=f"Invalid brew path: {brew_path}")
return brew_path