From 48cc9af6caa9e0b7411e36eb5142259a33eb13ef Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 12 Apr 2018 19:46:31 +0300 Subject: [PATCH] config: introduce config.local Fixes #524 Signed-off-by: Ruslan Kuprieiev --- dvc/cli.py | 20 ++++++++++++++++++++ dvc/command/config.py | 6 +++++- dvc/config.py | 6 ++++++ dvc/project.py | 3 ++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/dvc/cli.py b/dvc/cli.py index 09f5fd5d1..722d01119 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -239,6 +239,11 @@ def parse_args(argv=None): nargs='?', default=None, help='Option value') + config_parser.add_argument( + '--local', + action='store_true', + default=False, + help='Use local config') config_parser.set_defaults(func=CmdConfig) @@ -262,6 +267,11 @@ def parse_args(argv=None): remote_add_parser.add_argument( 'url', help='Url') + remote_add_parser.add_argument( + '--local', + action='store_true', + default=False, + help='Use local config') remote_add_parser.set_defaults(func=CmdRemoteAdd) @@ -272,6 +282,11 @@ def parse_args(argv=None): remote_remove_parser.add_argument( 'name', help='Name') + remote_remove_parser.add_argument( + '--local', + action='store_true', + default=False, + help='Use local config') remote_remove_parser.set_defaults(func=CmdRemoteRemove) @@ -294,6 +309,11 @@ def parse_args(argv=None): default=False, action='store_true', help='Unset option') + remote_modify_parser.add_argument( + '--local', + action='store_true', + default=False, + help='Use local config') remote_modify_parser.set_defaults(func=CmdRemoteModify) diff --git a/dvc/command/config.py b/dvc/command/config.py index 4bb216d80..dc669c657 100644 --- a/dvc/command/config.py +++ b/dvc/command/config.py @@ -11,7 +11,11 @@ class CmdConfig(CmdBase): def __init__(self, args): self.args = args root_dir = self._find_root() - self.config_file = os.path.join(root_dir, Project.DVC_DIR, Config.CONFIG) + if args.local: + config = Config.CONFIG_LOCAL + else: + config = Config.CONFIG + self.config_file = os.path.join(root_dir, Project.DVC_DIR, config) # Using configobj because it doesn't # drop comments like configparser does. self.configobj = configobj.ConfigObj(self.config_file) diff --git a/dvc/config.py b/dvc/config.py index 156c77c30..b1832c0de 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -21,6 +21,7 @@ def supported_url(url): class Config(object): CONFIG = 'config' + CONFIG_LOCAL = 'config.local' SECTION_CORE = 'core' SECTION_CORE_LOGLEVEL = 'loglevel' @@ -95,13 +96,18 @@ class Config(object): def __init__(self, dvc_dir): self.dvc_dir = os.path.abspath(os.path.realpath(dvc_dir)) self.config_file = os.path.join(dvc_dir, self.CONFIG) + self.config_local_file = os.path.join(dvc_dir, self.CONFIG_LOCAL) try: self._config = configobj.ConfigObj(self.config_file) + local = configobj.ConfigObj(self.config_local_file) # NOTE: schema doesn't support ConfigObj.Section validation, so we # need to convert our config to dict before passing it to schema. self._config = self._lower(self._config) + local = self._lower(local) + self._config.update(local) + self._config = schema.Schema(self.SCHEMA).validate(self._config) # NOTE: now converting back to ConfigObj diff --git a/dvc/project.py b/dvc/project.py index 1537a411a..cd1546125 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -69,7 +69,8 @@ class Project(object): scm = SCM(root_dir) scm.ignore_list([cache.cache_dir, state.state_file, - lock.lock_file]) + lock.lock_file, + config.config_local_file]) ignore_file = os.path.join(dvc_dir, scm.ignore_file()) scm.add([config.config_file, ignore_file])