mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-12 15:28:21 +01:00
config: introduce config.local
Fixes #524 Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+20
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-1
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user