From aa406aea32b4e36fd70bb90a8ff871ecd2063df8 Mon Sep 17 00:00:00 2001 From: Michael Banck Date: Tue, 8 Oct 2019 10:19:41 +0200 Subject: [PATCH] * debian/patches/avoid_distutils_spawn.patch: New patch, implements find_executable() method and drops import of distutils.spawn. * debian/control (patroni/Depends): Removed python3-distutils. --- debian/changelog | 5 +- debian/control | 3 +- debian/patches/avoid_distutils_spawn.patch | 71 ++++++++++++++++++++++ debian/patches/series | 1 + 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 debian/patches/avoid_distutils_spawn.patch diff --git a/debian/changelog b/debian/changelog index 35bdddc..b722002 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,9 @@ patroni (1.6.0-4) UNRELEASED; urgency=medium - * + [ Michael Banck ] + * debian/patches/avoid_distutils_spawn.patch: New patch, implements + find_executable() method and drops import of distutils.spawn. + * debian/control (patroni/Depends): Removed python3-distutils. -- Debian PostgreSQL Maintainers Mon, 07 Oct 2019 20:41:43 +0200 diff --git a/debian/control b/debian/control index 2a2304e..bdb3e24 100644 --- a/debian/control +++ b/debian/control @@ -46,8 +46,7 @@ Homepage: https://github.com/zalando/patroni Package: patroni Architecture: all Depends: ${misc:Depends}, ${python3:Depends}, lsb-base (>= 3.0-6), python3-psycopg2, - python3-etcd (>= 0.4.3) | python3-consul (>= 0.7.0) | python3-kazoo | python3-kubernetes, - python3-distutils + python3-etcd (>= 0.4.3) | python3-consul (>= 0.7.0) | python3-kazoo | python3-kubernetes Recommends: iproute2 Suggests: postgresql, etcd-server | consul | zookeeperd, haproxy, patroni-doc Description: PostgreSQL High Availability with ZooKeeper, etcd, Consul, or Kubernetes diff --git a/debian/patches/avoid_distutils_spawn.patch b/debian/patches/avoid_distutils_spawn.patch new file mode 100644 index 0000000..30a7016 --- /dev/null +++ b/debian/patches/avoid_distutils_spawn.patch @@ -0,0 +1,71 @@ +commit 0a1d9b0a251b70df7eb4b4004c86e169cddd8ed1 +Author: Alexander Kukushkin +Date: Mon Aug 26 09:38:47 2019 +0200 + + Get rid from distutils module dependency (#1146) + + We are using only one function from there, `find_executable()` and it is better to implement a similar function in Patroni rather than add `distutils` module into requirements.txt + +Index: patroni/patroni/ctl.py +=================================================================== +--- patroni.orig/patroni/ctl.py ++++ patroni/patroni/ctl.py +@@ -25,7 +25,6 @@ import yaml + + from click import ClickException + from contextlib import contextmanager +-from distutils.spawn import find_executable + from patroni.config import Config + from patroni.dcs import get_dcs as _get_dcs + from patroni.exceptions import PatroniException +@@ -1106,6 +1105,24 @@ def apply_yaml_file(data, filename): + return format_config_for_editing(changed_data), changed_data + + ++def find_executable(executable, path=None): ++ _, ext = os.path.splitext(executable) ++ ++ if (sys.platform == 'win32') and (ext != '.exe'): ++ executable = executable + '.exe' ++ ++ if os.path.isfile(executable): ++ return executable ++ ++ if path is None: ++ path = os.environ.get('PATH', os.defpath) ++ ++ for p in path.split(os.pathsep): ++ f = os.path.join(p, executable) ++ if os.path.isfile(f): ++ return f ++ ++ + def invoke_editor(before_editing, cluster_name): + """Starts editor command to edit configuration in human readable format + +Index: patroni/tests/test_ctl.py +=================================================================== +--- patroni.orig/tests/test_ctl.py ++++ patroni/tests/test_ctl.py +@@ -9,7 +9,7 @@ from datetime import datetime, timedelta + from mock import patch, Mock + from patroni.ctl import ctl, store_config, load_config, output_members, request_patroni, get_dcs, parse_dcs, \ + get_all_members, get_any_member, get_cursor, query_member, configure, PatroniCtlException, apply_config_changes, \ +- format_config_for_editing, show_diff, invoke_editor, format_pg_version ++ format_config_for_editing, show_diff, invoke_editor, format_pg_version, find_executable + from patroni.dcs.etcd import Client, Failover + from patroni.utils import tzutc + from psycopg2 import OperationalError +@@ -587,3 +587,12 @@ class TestCtl(unittest.TestCase): + def test_format_pg_version(self): + self.assertEqual(format_pg_version(100001), '10.1') + self.assertEqual(format_pg_version(90605), '9.6.5') ++ ++ @patch('sys.platform', 'win32') ++ def test_find_executable(self): ++ with patch('os.path.isfile', Mock(return_value=True)): ++ self.assertEqual(find_executable('vim'), 'vim.exe') ++ with patch('os.path.isfile', Mock(return_value=False)): ++ self.assertIsNone(find_executable('vim')) ++ with patch('os.path.isfile', Mock(side_effect=[False, True])): ++ self.assertEqual(find_executable('vim', '/'), '/vim.exe') diff --git a/debian/patches/series b/debian/patches/series index 1e4b638..1624c0a 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -4,3 +4,4 @@ check_postmaster.patch acceptance_tests_system_patroni.patch disable_postgresql.conf_chmod.patch acceptance_tests_timeouts.patch +avoid_distutils_spawn.patch