Skip to content

Commit

Permalink
Expand user home and env vars in config_file path
Browse files Browse the repository at this point in the history
Closes #318.
  • Loading branch information
randomir committed Jun 19, 2020
1 parent 7148aa4 commit e3a0be7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions dwave/cloud/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def load_config_from_files(filenames=None):
config = configparser.ConfigParser(default_section="defaults")
for filename in filenames:
try:
filename = os.path.expandvars(os.path.expanduser(filename))
with open(filename, 'r') as f:
config.read_file(f, filename)
except (IOError, OSError):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def test_config_file_detection_nonexisting(self):
def test_config_file_path_expansion(self):
"""Home dir and env vars are expanded when resolving config path."""

env = {"HOME": "/home/user", "var": "val"}
env = {"var": "val"}
config_file = "~/path/${var}/to/$var/my.conf"
expected_path = "/home/user/path/val/to/val/my.conf"
expected_path = os.path.expanduser("~/path/val/to/val/my.conf")
profile = "profile"

conf_content = """
Expand Down

0 comments on commit e3a0be7

Please sign in to comment.