Skip to content

Commit

Permalink
support arbitrary configuration file names
Browse files Browse the repository at this point in the history
  • Loading branch information
nihlaeth committed Feb 12, 2017
1 parent 2a119f0 commit 44a5281
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Documentation
Planned features
================
* support for multi file configuration
* multi matching sections / wildcard sections
* yaml config format
* json config format
Expand Down
18 changes: 13 additions & 5 deletions user_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ class Config(with_metaclass(ConfigMeta, MappingMixin)):
Keyword Arguments
-----------------
file_name: str, optional
name of the configuration file, defaults to config
global_path: pathlib.Path, optional
overwrite system global configuration path, defaults to None
user_path: pathlib.Path, optional
Expand Down Expand Up @@ -577,7 +579,11 @@ class Config(with_metaclass(ConfigMeta, MappingMixin)):
version = None
_data = None

def __init__(self, global_path=None, user_path=None):
def __init__(
self,
file_name="config",
global_path=None,
user_path=None):
if self.application is None:
raise AttributeError(
'application not set, please provide an application name')
Expand All @@ -597,14 +603,16 @@ def __init__(self, global_path=None, user_path=None):
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))
global_path = Path(paths.site_config_dir)
global_path = global_path.joinpath(
"{}.{}".format(file_name, self._extension))
if global_path.is_file():
self._read(global_path, self._elements, self._data)
# read user config
if user_path is None:
user_path = Path(paths.user_config_dir).joinpath(
"config.{}".format(self._extension))
user_path = Path(paths.user_config_dir)
user_path = user_path.joinpath(
"{}.{}".format(file_name, 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 44a5281

Please sign in to comment.