From 8a353bac1a4cefddef92aa7d758b39d572ec3d5a Mon Sep 17 00:00:00 2001 From: David Caplan Date: Wed, 11 May 2016 11:38:29 -0400 Subject: [PATCH] use expanduser instead of looking for $HOME manually (fixes #97) --- solvebio/cli/credentials.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/solvebio/cli/credentials.py b/solvebio/cli/credentials.py index b3cf83c2..88bf5ede 100644 --- a/solvebio/cli/credentials.py +++ b/solvebio/cli/credentials.py @@ -20,11 +20,21 @@ class netrc(_netrc): """ @staticmethod def path(): + if os.name == 'nt': + # Windows + path = '~\\_solvebio\\credentials' + else: + # *nix + path = '~/.solvebio/credentials' try: - path = os.path.join(os.environ['HOME'], '.solvebio', 'credentials') + path = os.path.expanduser(path) except KeyError: - raise IOError("Could not find credentials file: $HOME is not set") + # os.path.expanduser can fail when $HOME is undefined and + # getpwuid fails. See http://bugs.python.org/issue20164 + raise IOError( + "Could not find any home directory for '{0}'" + .format(path)) if not os.path.isdir(os.path.dirname(path)): os.makedirs(os.path.dirname(path))