From cef0350b61ec7fad850eb3727faa6563aa471d46 Mon Sep 17 00:00:00 2001 From: Guilhem Lettron Date: Fri, 23 Mar 2018 12:17:33 +0100 Subject: [PATCH 01/15] Add ability to specify a custom configuration file This is useful when bootstraping a new workstation. --- mackup/mackup.py | 4 ++-- mackup/main.py | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mackup/mackup.py b/mackup/mackup.py index f0d5c1040..5f2cc3299 100644 --- a/mackup/mackup.py +++ b/mackup/mackup.py @@ -19,9 +19,9 @@ class Mackup(object): """Main Mackup class.""" - def __init__(self): + def __init__(self, filename=None): """Mackup Constructor.""" - self._config = config.Config() + self._config = config.Config(filename) self.mackup_folder = self._config.fullpath self.temp_folder = tempfile.mkdtemp(prefix="mackup_tmp_") diff --git a/mackup/main.py b/mackup/main.py index c5e2b57e1..c564ecb9b 100644 --- a/mackup/main.py +++ b/mackup/main.py @@ -12,11 +12,12 @@ mackup --version Options: - -h --help Show this screen. - -f --force Force every question asked to be answered with "Yes". - -n --dry-run Show steps without executing. - -v --verbose Show additional details. - --version Show version. + -h --help Show this screen. + -c FILE --config=FILE Configuration file to use. + -f --force Force every question asked to be answered with "Yes". + -n --dry-run Show steps without executing. + -v --verbose Show additional details. + --version Show version. Modes of action: 1. list: display a list of all supported applications. @@ -61,7 +62,7 @@ def main(): # Get the command line arg args = docopt(__doc__, version="Mackup {}".format(VERSION)) - mckp = Mackup() + mckp = Mackup(args['--config']) app_db = ApplicationsDatabase() def printAppHeader(app_name): From e4605922fd09c09b8889b9a0256318d0cf07b5a8 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Wed, 7 Nov 2018 15:54:55 -0800 Subject: [PATCH 02/15] factor out existing validation logic into stand-alone function This removes some minor assertion duplication, and should be easier to test. --- mackup/config.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 0c448544a..6e05e6676 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -36,9 +36,9 @@ def __init__(self, filename=None): filename (str): Optional filename of the config file. If empty, defaults to MACKUP_CONFIG_FILE """ - assert isinstance(filename, str) or filename is None # Initialize the parser + filename = self._validate_config_path(filename) self._parser = self._setup_parser(filename) # Do we have an old config file ? @@ -128,7 +128,18 @@ def apps_to_sync(self): """ return set(self._apps_to_sync) - def _setup_parser(self, filename=None): + def _validate_config_path(self, filename): + """ + Validate the (optional) user-supplied path to a Mackup config file. If + none supplied, defaults to returning MACKUP_CONFIG_FILE. + """ + if filename is None: + return MACKUP_CONFIG_FILE + + assert isinstance(filename, str) + return filename + + def _setup_parser(self, filename): """ Configure the ConfigParser instance the way we want it. @@ -138,12 +149,6 @@ def _setup_parser(self, filename=None): Returns: SafeConfigParser """ - assert isinstance(filename, str) or filename is None - - # If we are not overriding the config filename - if not filename: - filename = MACKUP_CONFIG_FILE - parser = configparser.SafeConfigParser(allow_no_value=True) parser.read(os.path.join(os.path.join(os.environ['HOME'], filename))) From e0377d0b7c372c8ddc2364a86c86cdb7d1db32e0 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 10:24:19 -0800 Subject: [PATCH 03/15] automatically handle likely common cases of relative paths Also, try to use slighty more explicit arg, function names. --- mackup/config.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 6e05e6676..f3466d836 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -38,8 +38,8 @@ def __init__(self, filename=None): """ # Initialize the parser - filename = self._validate_config_path(filename) - self._parser = self._setup_parser(filename) + config_path = self._resolve_config_path(filename) + self._parser = self._setup_parser(config_path) # Do we have an old config file ? self._warn_on_old_config() @@ -128,29 +128,36 @@ def apps_to_sync(self): """ return set(self._apps_to_sync) - def _validate_config_path(self, filename): + @classmethod + def _resolve_config_path(cls, filename): """ - Validate the (optional) user-supplied path to a Mackup config file. If + Resolve the optional, user-supplied path to a Mackup config file. If none supplied, defaults to returning MACKUP_CONFIG_FILE. """ if filename is None: - return MACKUP_CONFIG_FILE + return os.path.join(os.environ["HOME"], MACKUP_CONFIG_FILE) - assert isinstance(filename, str) - return filename + base_dirs = (os.environ["HOME"], os.getcwd(), "/") + for base_dir in base_dirs: + config_path = os.path.join(base_dir, filename) + if os.path.exists(config_path): + return config_path - def _setup_parser(self, filename): + message = "Couldn't find Mackup config {filename} in {base_dirs}" + raise RuntimeError(message.format_map(locals())) + + def _setup_parser(self, config_path): """ Configure the ConfigParser instance the way we want it. Args: - filename (str) or None + config_path (str) Returns: SafeConfigParser """ parser = configparser.SafeConfigParser(allow_no_value=True) - parser.read(os.path.join(os.path.join(os.environ['HOME'], filename))) + parser.read(config_path) return parser From 1978f4178674143d6208505adfc7570f16f1cc57 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 10:41:13 -0800 Subject: [PATCH 04/15] add test confirming existing default behavior preserved And stub the rest for now. --- tests/config_tests.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/config_tests.py b/tests/config_tests.py index dd363c27e..20ec7d5e7 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -6,7 +6,8 @@ ENGINE_COPY, ENGINE_ICLOUD, ENGINE_BOX, - ENGINE_FS) + ENGINE_FS, + MACKUP_CONFIG_FILE) from mackup.config import Config, ConfigError @@ -263,3 +264,20 @@ def test_config_apps_to_ignore_and_sync(self): def test_config_old_config(self): self.assertRaises(SystemExit, Config, 'mackup-old-config.cfg') + + def test_default_config_path_returned_if_none_supplied(self): + default_config_path = os.path.join(os.environ['HOME'], + MACKUP_CONFIG_FILE) + resolved_config_path = Config._resolve_config_path(None) + + assert resolved_config_path == default_config_path + + def test_resolves_config_path_relative_to_home_dir(self): + pass + + def test_resolves_config_path_relative_to_cwd(self): + pass + + def test_resolves_absolute_config_path(self): + pass + From 5781d5a4920dcfe2d88f5dc26e4ae282379c375c Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 12:00:22 -0800 Subject: [PATCH 05/15] fill out remaining test cases --- tests/config_tests.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/config_tests.py b/tests/config_tests.py index 20ec7d5e7..9e1bc4207 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -1,5 +1,6 @@ import unittest import os.path +import tempfile from mackup.constants import (ENGINE_DROPBOX, ENGINE_GDRIVE, @@ -268,16 +269,31 @@ def test_config_old_config(self): def test_default_config_path_returned_if_none_supplied(self): default_config_path = os.path.join(os.environ['HOME'], MACKUP_CONFIG_FILE) - resolved_config_path = Config._resolve_config_path(None) + resolved_path = Config._resolve_config_path(None) - assert resolved_config_path == default_config_path + assert resolved_path == default_config_path def test_resolves_config_path_relative_to_home_dir(self): - pass + base_dir = os.environ['HOME'] + + with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: + relative_path = os.path.basename(config_file.name) + resolved_path = Config._resolve_config_path(relative_path) + + assert resolved_path == config_file.name def test_resolves_config_path_relative_to_cwd(self): - pass + base_dir = os.getcwd() + + with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: + relative_path = os.path.basename(config_file.name) + resolved_path = Config._resolve_config_path(relative_path) + + assert resolved_path == config_file.name def test_resolves_absolute_config_path(self): - pass + with tempfile.TemporaryDirectory(dir=os.getcwd()) as tmp_dir: + with tempfile.NamedTemporaryFile(dir=tmp_dir) as config_file: + resolved_path = Config._resolve_config_path(config_file.name) + assert resolved_path == config_file.name From 2d0a2f13a404a98260a82c1a7a772efae6755868 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 12:07:37 -0800 Subject: [PATCH 06/15] add test confirming behavior on failure --- mackup/config.py | 4 ++-- tests/config_tests.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index f3466d836..49d489e7c 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -143,8 +143,8 @@ def _resolve_config_path(cls, filename): if os.path.exists(config_path): return config_path - message = "Couldn't find Mackup config {filename} in {base_dirs}" - raise RuntimeError(message.format_map(locals())) + message = "Couldn't find {} in {}".format(filename, base_dirs) + raise FileNotFoundError(message) def _setup_parser(self, config_path): """ diff --git a/tests/config_tests.py b/tests/config_tests.py index 9e1bc4207..26c6b873a 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -297,3 +297,6 @@ def test_resolves_absolute_config_path(self): resolved_path = Config._resolve_config_path(config_file.name) assert resolved_path == config_file.name + + def test_raises_file_not_found_for_nonexistent_config_path(self): + self.assertRaises(FileNotFoundError, Config._resolve_config_path, '/foo/bar') From e439ae64c97b9380492896f71d82ef969bf7cbed Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 12:23:32 -0800 Subject: [PATCH 07/15] obey the linting gods --- tests/config_tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/config_tests.py b/tests/config_tests.py index 26c6b873a..5d293b477 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -299,4 +299,6 @@ def test_resolves_absolute_config_path(self): assert resolved_path == config_file.name def test_raises_file_not_found_for_nonexistent_config_path(self): - self.assertRaises(FileNotFoundError, Config._resolve_config_path, '/foo/bar') + self.assertRaises(FileNotFoundError, + Config._resolve_config_path, + '/foo/bar') From 72ce97a9157e2efbafa8a29a528816ad6d4403a2 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 12:26:32 -0800 Subject: [PATCH 08/15] use more generic Exception, for 2.7 compatability --- mackup/config.py | 2 +- tests/config_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 49d489e7c..8eac95470 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -144,7 +144,7 @@ def _resolve_config_path(cls, filename): return config_path message = "Couldn't find {} in {}".format(filename, base_dirs) - raise FileNotFoundError(message) + raise RuntimeError(message) def _setup_parser(self, config_path): """ diff --git a/tests/config_tests.py b/tests/config_tests.py index 5d293b477..d76619550 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -299,6 +299,6 @@ def test_resolves_absolute_config_path(self): assert resolved_path == config_file.name def test_raises_file_not_found_for_nonexistent_config_path(self): - self.assertRaises(FileNotFoundError, + self.assertRaises(RuntimeError, Config._resolve_config_path, '/foo/bar') From c527d617de01a363a2ab8161da3bff6c64b55420 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Thu, 8 Nov 2018 12:33:15 -0800 Subject: [PATCH 09/15] more 2.7 compatability changes --- tests/config_tests.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/config_tests.py b/tests/config_tests.py index d76619550..2854d1468 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -292,11 +292,12 @@ def test_resolves_config_path_relative_to_cwd(self): assert resolved_path == config_file.name def test_resolves_absolute_config_path(self): - with tempfile.TemporaryDirectory(dir=os.getcwd()) as tmp_dir: - with tempfile.NamedTemporaryFile(dir=tmp_dir) as config_file: - resolved_path = Config._resolve_config_path(config_file.name) + base_dir = os.getcwd() + + with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: + resolved_path = Config._resolve_config_path(config_file.name) - assert resolved_path == config_file.name + assert resolved_path == config_file.name def test_raises_file_not_found_for_nonexistent_config_path(self): self.assertRaises(RuntimeError, From f2fad2219ad67d79eef6efa1237fc63689f59a84 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Fri, 31 Jul 2020 17:18:49 -0700 Subject: [PATCH 10/15] get new functionality working again, cleaned up --- mackup/config.py | 62 ++++++++++++++++++++++++++++--------------- tests/config_tests.py | 55 +++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index fab8d3fdb..caec967ff 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -1,7 +1,8 @@ """Package used to manage the .mackup.cfg config file.""" -import os +import logging import os.path +import pathlib from .constants import ( CUSTOM_APPS_DIR, @@ -28,21 +29,23 @@ import ConfigParser as configparser + +logger = logging.getLogger(__name__) + + class Config(object): """The Mackup Config class.""" - def __init__(self, filename=None): + def __init__(self, config_path=None): """ Create a Config instance. Args: - filename (str): Optional filename of the config file. If empty, - defaults to MACKUP_CONFIG_FILE + config_path (str): Optional path to a mackup config file. """ # Initialize the parser - config_path = self._resolve_config_path(filename) self._parser = self._setup_parser(config_path) # Do we have an old config file ? @@ -132,35 +135,52 @@ def apps_to_sync(self): return set(self._apps_to_sync) @classmethod - def _resolve_config_path(cls, filename): + def _resolve_config_path(cls, filename=None): """ Resolve the optional, user-supplied path to a Mackup config file. If - none supplied, defaults to returning MACKUP_CONFIG_FILE. - """ - if filename is None: - return os.path.join(os.environ["HOME"], MACKUP_CONFIG_FILE) + none supplied, defaults to looking for MACKUP_CONFIG_FILE in the user's + home directory. - base_dirs = (os.environ["HOME"], os.getcwd(), "/") - for base_dir in base_dirs: - config_path = os.path.join(base_dir, filename) - if os.path.exists(config_path): - return config_path + Returns: + str, or None if filename doesn't exist + """ + file_exists = lambda p: os.path.isfile(p) - message = "Couldn't find {} in {}".format(filename, base_dirs) - raise RuntimeError(message) + if filename is None: + # use $HOME, instead of pathlib.Path.home, to preserve existing behavior + # (some unit tests rely on monkeypatching that value) + path = os.path.join(os.environ["HOME"], MACKUP_CONFIG_FILE) + if file_exists(path): + return os.path.abspath(path) + else: + logger.warning(f"Default config file {path} not found, and no alternative filename given.") + return None + + possible_paths = [ + os.path.expanduser(filename), + os.path.join(os.environ["HOME"], filename), + os.path.join(os.getcwd(), filename) + ] + path = next(filter(file_exists, possible_paths), None) + if path: + return os.path.abspath(path) + else: + logger.warning(f"Config file {filename} not found! Tried paths: {possible_paths}") + return None - def _setup_parser(self, config_path): + def _setup_parser(self, config_path=None): """ Configure the ConfigParser instance the way we want it. Args: - config_path (str) - + config_path (str): Optional path to a mackup config file. Returns: SafeConfigParser """ parser = configparser.SafeConfigParser(allow_no_value=True) - parser.read(config_path) + # call will return None if config_path doesn't exist + path = self._resolve_config_path(config_path) or "" + parser.read(path) return parser diff --git a/tests/config_tests.py b/tests/config_tests.py index a5224569a..661aec130 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -1,5 +1,6 @@ import unittest import os.path +import pathlib import tempfile from mackup.constants import ( @@ -16,7 +17,7 @@ class TestConfig(unittest.TestCase): def setUp(self): realpath = os.path.dirname(os.path.realpath(__file__)) - os.environ["HOME"] = os.path.join(realpath, "fixtures") + self.mock_home = os.environ["HOME"] = os.path.join(realpath, "fixtures") def test_config_no_config(self): cfg = Config() @@ -235,40 +236,34 @@ def test_config_apps_to_ignore_and_sync(self): def test_config_old_config(self): self.assertRaises(SystemExit, Config, "mackup-old-config.cfg") - def test_default_config_path_returned_if_none_supplied(self): - default_config_path = os.path.join(os.environ["HOME"], - MACKUP_CONFIG_FILE) - resolved_path = Config._resolve_config_path(None) + def test_resolve_config_path_returns_default_path_if_file_exists(self): + pass - assert resolved_path == default_config_path + def test_resolve_config_path_returns_none_if_default_config_file_nonexistent(self): + resolved_path = Config._resolve_config_path() - def test_resolves_config_path_relative_to_home_dir(self): - base_dir = os.environ["HOME"] + assert resolved_path is None - with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: - relative_path = os.path.basename(config_file.name) - resolved_path = Config._resolve_config_path(relative_path) + def test_resolve_config_path_performs_tilde_expansion(self): + with tempfile.NamedTemporaryFile(dir=pathlib.Path.home()) as mock_cfg_file: + mock_filename = os.path.basename(mock_cfg_file.name) + filename = os.path.join("~", mock_filename) + resolved_path = Config._resolve_config_path(filename) - assert resolved_path == config_file.name + assert resolved_path == mock_cfg_file.name - def test_resolves_config_path_relative_to_cwd(self): - base_dir = os.getcwd() - - with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: - relative_path = os.path.basename(config_file.name) - resolved_path = Config._resolve_config_path(relative_path) - - assert resolved_path == config_file.name + def test_resolve_config_path_relative_to_home_dir(self): + with tempfile.NamedTemporaryFile(dir=self.mock_home) as mock_cfg_file: + mock_filename = os.path.basename(mock_cfg_file.name) + resolved_path = Config._resolve_config_path(mock_filename) - def test_resolves_absolute_config_path(self): - base_dir = os.getcwd() + assert resolved_path == mock_cfg_file.name - with tempfile.NamedTemporaryFile(dir=base_dir) as config_file: - resolved_path = Config._resolve_config_path(config_file.name) - - assert resolved_path == config_file.name + def test_resolves_config_path_relative_to_cwd(self): + cwd = os.getcwd() + with tempfile.NamedTemporaryFile(dir=cwd) as mock_cfg_file: + mock_path = mock_cfg_file.name + mock_filename = os.path.basename(mock_cfg_file.name) + resolved_path = Config._resolve_config_path(mock_filename) - def test_raises_file_not_found_for_nonexistent_config_path(self): - self.assertRaises(RuntimeError, - Config._resolve_config_path, - "/foo/bar") + assert resolved_path == mock_path From 851115286323b458aca76b7986cf37d848fd6585 Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Fri, 31 Jul 2020 17:26:52 -0700 Subject: [PATCH 11/15] use black formatting --- mackup/config.py | 11 +++++++---- mackup/main.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index caec967ff..0e6fc278a 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -29,7 +29,6 @@ import ConfigParser as configparser - logger = logging.getLogger(__name__) @@ -153,19 +152,23 @@ def _resolve_config_path(cls, filename=None): if file_exists(path): return os.path.abspath(path) else: - logger.warning(f"Default config file {path} not found, and no alternative filename given.") + logger.warning( + f"Default config file {path} not found, and no alternative filename given." + ) return None possible_paths = [ os.path.expanduser(filename), os.path.join(os.environ["HOME"], filename), - os.path.join(os.getcwd(), filename) + os.path.join(os.getcwd(), filename), ] path = next(filter(file_exists, possible_paths), None) if path: return os.path.abspath(path) else: - logger.warning(f"Config file {filename} not found! Tried paths: {possible_paths}") + logger.warning( + f"Config file {filename} not found! Tried paths: {possible_paths}" + ) return None def _setup_parser(self, config_path=None): diff --git a/mackup/main.py b/mackup/main.py index 9a164e8c6..42aa48be7 100644 --- a/mackup/main.py +++ b/mackup/main.py @@ -64,7 +64,7 @@ def main(): # Get the command line arg args = docopt(__doc__, version="Mackup {}".format(VERSION)) - mckp = Mackup(args['--config']) + mckp = Mackup(args["--config"]) app_db = ApplicationsDatabase() def printAppHeader(app_name): From d60a6abd1bcd4104e8057d44f58718a90f19883a Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Fri, 31 Jul 2020 17:28:42 -0700 Subject: [PATCH 12/15] remove unused import --- mackup/config.py | 1 - tests/config_tests.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 0e6fc278a..1cc21700b 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -2,7 +2,6 @@ import logging import os.path -import pathlib from .constants import ( CUSTOM_APPS_DIR, diff --git a/tests/config_tests.py b/tests/config_tests.py index 661aec130..03c8d0f93 100644 --- a/tests/config_tests.py +++ b/tests/config_tests.py @@ -1,6 +1,5 @@ import unittest import os.path -import pathlib import tempfile from mackup.constants import ( @@ -245,7 +244,7 @@ def test_resolve_config_path_returns_none_if_default_config_file_nonexistent(sel assert resolved_path is None def test_resolve_config_path_performs_tilde_expansion(self): - with tempfile.NamedTemporaryFile(dir=pathlib.Path.home()) as mock_cfg_file: + with tempfile.NamedTemporaryFile(dir=os.path.expanduser("~")) as mock_cfg_file: mock_filename = os.path.basename(mock_cfg_file.name) filename = os.path.join("~", mock_filename) resolved_path = Config._resolve_config_path(filename) From c1476dfee04770bd8607ffdaee0b4e8fb69b36fc Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Fri, 31 Jul 2020 17:40:43 -0700 Subject: [PATCH 13/15] remain compatible with Python 2.7 :/ --- mackup/config.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 1cc21700b..44b6058a9 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -147,12 +147,12 @@ def _resolve_config_path(cls, filename=None): if filename is None: # use $HOME, instead of pathlib.Path.home, to preserve existing behavior # (some unit tests rely on monkeypatching that value) - path = os.path.join(os.environ["HOME"], MACKUP_CONFIG_FILE) + path = os.path.abspath(os.path.join(os.environ["HOME"], MACKUP_CONFIG_FILE)) if file_exists(path): - return os.path.abspath(path) + return path else: logger.warning( - f"Default config file {path} not found, and no alternative filename given." + "Default config file {} not found, and no alternative filename given.".format(path) ) return None @@ -161,12 +161,12 @@ def _resolve_config_path(cls, filename=None): os.path.join(os.environ["HOME"], filename), os.path.join(os.getcwd(), filename), ] - path = next(filter(file_exists, possible_paths), None) + path = os.path.abspath(next(filter(file_exists, possible_paths), None)) if path: - return os.path.abspath(path) + return path else: logger.warning( - f"Config file {filename} not found! Tried paths: {possible_paths}" + "Config file {} not found! Tried paths: {}".format(filename, possible_paths) ) return None From 44a67737c77eabb3cd8c1eac2664afcc02cd939d Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Fri, 31 Jul 2020 17:46:04 -0700 Subject: [PATCH 14/15] more formatting fixes --- mackup/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mackup/config.py b/mackup/config.py index 44b6058a9..54c4cbc4e 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -152,7 +152,9 @@ def _resolve_config_path(cls, filename=None): return path else: logger.warning( - "Default config file {} not found, and no alternative filename given.".format(path) + "Default config file {} not found, and no alternative filename given.".format( + path + ) ) return None @@ -166,7 +168,9 @@ def _resolve_config_path(cls, filename=None): return path else: logger.warning( - "Config file {} not found! Tried paths: {}".format(filename, possible_paths) + "Config file {} not found! Tried paths: {}".format( + filename, possible_paths + ) ) return None From 9d8f3152205b2f8ddc33d132a113bedc8c35751c Mon Sep 17 00:00:00 2001 From: Patrick McKenna Date: Tue, 4 Aug 2020 12:00:42 -0700 Subject: [PATCH 15/15] maintain Python2 compatibility --- mackup/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mackup/config.py b/mackup/config.py index 54c4cbc4e..f9c76f02e 100644 --- a/mackup/config.py +++ b/mackup/config.py @@ -163,7 +163,8 @@ def _resolve_config_path(cls, filename=None): os.path.join(os.environ["HOME"], filename), os.path.join(os.getcwd(), filename), ] - path = os.path.abspath(next(filter(file_exists, possible_paths), None)) + # iter() call for Python2 compatibility (filter() returns a list in Python2) + path = os.path.abspath(next(iter(filter(file_exists, possible_paths)), None)) if path: return path else: