Skip to content

Commit

Permalink
config: introduce config.local
Browse files Browse the repository at this point in the history
Fixes #524

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
  • Loading branch information
efiop committed Apr 13, 2018
1 parent 3748164 commit 48cc9af
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand All @@ -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)


Expand Down
6 changes: 5 additions & 1 deletion dvc/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def supported_url(url):

class Config(object):
CONFIG = 'config'
CONFIG_LOCAL = 'config.local'

SECTION_CORE = 'core'
SECTION_CORE_LOGLEVEL = 'loglevel'
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion dvc/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def init(root_dir=os.curdir):
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])
Expand Down

0 comments on commit 48cc9af

Please sign in to comment.