Skip to content

Commit

Permalink
allow overwriting default paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nihlaeth committed Feb 12, 2017
1 parent da1e458 commit 2a119f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=too-few-public-methods,no-member
disable=too-few-public-methods,no-member,superfluous-parens


[REPORTS]
Expand Down
22 changes: 16 additions & 6 deletions user_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ class Config(with_metaclass(ConfigMeta, MappingMixin)):
"""
Base class for application configuration.
Keyword Arguments
-----------------
global_path: pathlib.Path, optional
overwrite system global configuration path, defaults to None
user_path: pathlib.Path, optional
overwrite system user configuration path, defaults to None
Raises
------
AttributeError:
Expand Down Expand Up @@ -570,7 +577,7 @@ class Config(with_metaclass(ConfigMeta, MappingMixin)):
version = None
_data = None

def __init__(self):
def __init__(self, global_path=None, user_path=None):
if self.application is None:
raise AttributeError(
'application not set, please provide an application name')
Expand All @@ -587,14 +594,17 @@ def __init__(self):
else:
self._data[element] = None
# read global config
paths = AppDirs(self.application, self.author, self.version)
global_path = Path(paths.site_config_dir).joinpath(
"config.{}".format(self._extension))
if global_path is None or user_path is None:
paths = AppDirs(self.application, self.author, self.version)
if global_path is None:
global_path = Path(paths.site_config_dir).joinpath(
"config.{}".format(self._extension))
if global_path.is_file():
self._read(global_path, self._elements, self._data)
# read user config
user_path = Path(paths.user_config_dir).joinpath(
"config.{}".format(self._extension))
if user_path is None:
user_path = Path(paths.user_config_dir).joinpath(
"config.{}".format(self._extension))
if user_path.is_file():
self._read(user_path, self._elements, self._data)
# construct a commandline parser
Expand Down

0 comments on commit 2a119f0

Please sign in to comment.