From e94717b7a9044ac7e96322bb94882980a2366276 Mon Sep 17 00:00:00 2001 From: Julien Maupetit Date: Mon, 4 Oct 2021 15:01:44 +0200 Subject: [PATCH] =?UTF-8?q?fixup!=20=E2=AC=86=EF=B8=8F(dependencies)=20upd?= =?UTF-8?q?ate=20python=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filter_plugins/deploy.py | 38 +++++++++++------------ lookup_plugins/apps.py | 6 +++- tests/units/plugins/filter/test_deploy.py | 4 +-- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/filter_plugins/deploy.py b/filter_plugins/deploy.py index d3d9e8dcb..004393c90 100644 --- a/filter_plugins/deploy.py +++ b/filter_plugins/deploy.py @@ -8,19 +8,19 @@ def blue_green_host(host, prefix=None): """ - Add next/previous prefix to the base host, if prefix is empty or equals - to 'current', the host is left unchanged. + Add next/previous prefix to the base host, if prefix is empty or equals + to 'current', the host is left unchanged. - Example usage: + Example usage: - {{ "foo.bar.com" | blue_green_host("previous") }} - # Should return: previous.foo.bar.com + {{ "foo.bar.com" | blue_green_host("previous") }} + # Should return: previous.foo.bar.com - {{ "foo.bar.com" | blue_green_host() }} - # Should return: foo.bar.com + {{ "foo.bar.com" | blue_green_host() }} + # Should return: foo.bar.com - {{ "foo.bar.com" | blue_green_host("current") }} - # Should return: foo.bar.com + {{ "foo.bar.com" | blue_green_host("current") }} + # Should return: foo.bar.com """ if prefix is None or not prefix: @@ -28,23 +28,21 @@ def blue_green_host(host, prefix=None): if prefix not in BLUE_GREEN_PREFIXES: raise AnsibleFilterError( - "prefix '{}' is not allowed (must be in {})".format( - prefix, BLUE_GREEN_PREFIXES - ) + f"prefix '{prefix}' is not allowed (must be in {BLUE_GREEN_PREFIXES})" ) - return "{}.{}".format(prefix, host) if prefix != "current" else host + return f"{prefix}.{host}" if prefix != "current" else host def blue_green_hosts(host): """ - Add next/current/previous prefix to the base host, and return that list - of possible hosts. + Add next/current/previous prefix to the base host, and return that list + of possible hosts. - Example usage: + Example usage: - {{ "foo.bar.com" | blue_green_hosts }} - # Should return: previous.foo.bar.com, foo.bar.com, next.foo.bar.com + {{ "foo.bar.com" | blue_green_hosts }} + # Should return: previous.foo.bar.com, foo.bar.com, next.foo.bar.com """ if not host: @@ -52,14 +50,14 @@ def blue_green_hosts(host): return ",".join( [ - "{}.{}".format(prefix, host) if prefix != "current" else host + f"{prefix}.{host}" if prefix != "current" else host for prefix in BLUE_GREEN_PREFIXES ] ) # pylint: disable=no-self-use,too-few-public-methods -class FilterModule(): +class FilterModule: """Filters used for deployments""" def filters(self): diff --git a/lookup_plugins/apps.py b/lookup_plugins/apps.py index 58e06a12b..44c511116 100644 --- a/lookup_plugins/apps.py +++ b/lookup_plugins/apps.py @@ -4,6 +4,7 @@ """ from __future__ import absolute_import, division, print_function +from locale import getpreferredencoding from pathlib import Path import yaml @@ -162,7 +163,10 @@ def __init__(self, loader=None, templar=None, **kwargs): def _yaml_load(file_path): """Syntactic sugar to get yaml content with a simpler line of code""" - return yaml.load(Path(file_path).read_text(), Loader=yaml.FullLoader) + return yaml.load( + Path(file_path).read_text(encoding=getpreferredencoding()), + Loader=yaml.FullLoader, + ) def _get_app_service(self, service_path): """Explore an application service""" diff --git a/tests/units/plugins/filter/test_deploy.py b/tests/units/plugins/filter/test_deploy.py index a713cca18..bcd0cf4ec 100644 --- a/tests/units/plugins/filter/test_deploy.py +++ b/tests/units/plugins/filter/test_deploy.py @@ -44,8 +44,8 @@ def test_with_next_previous_prefix(self): host = "foo.com" - self.assertEqual(blue_green_host(host, "previous"), "previous.{}".format(host)) - self.assertEqual(blue_green_host(host, "next"), "next.{}".format(host)) + self.assertEqual(blue_green_host(host, "previous"), f"previous.{host}") + self.assertEqual(blue_green_host(host, "next"), f"next.{host}") class TestBlueGreenHostsFilter(unittest.TestCase):