Skip to content

Import fails if HOME not set #73

@rmwoods

Description

@rmwoods

In cases where HOME is not set (e.g. in our case, when btrdb is imported in a webapp controlled by supervisorctl), importing btrdb fails at utils/credentials.py:30

CREDENTIALS_PATH = os.path.join(os.environ["HOME"], CONFIG_DIR, CREDENTIALS_FILENAME)

This can be reproduced as follows:

# bash
unset HOME

then

# in python
import btrdb

Which produces:

In [1]: import btrdb                                                                                                                                                   
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-36165869e3ee> in <module>
----> 1 import btrdb

~/Preteckt/tools/preteckt_dash/env/lib/python3.6/site-packages/btrdb/__init__.py in <module>
     20 from btrdb.exceptions import ConnectionError
     21 from btrdb.version import get_version
---> 22 from btrdb.utils.credentials import credentials_by_profile, credentials
     23 from btrdb.stream import MINIMUM_TIME, MAXIMUM_TIME
     24 

~/Preteckt/tools/preteckt_dash/env/lib/python3.6/site-packages/btrdb/utils/credentials.py in <module>
     28 CONFIG_DIR = ".predictivegrid"
     29 CREDENTIALS_FILENAME = "credentials.yaml"
---> 30 CREDENTIALS_PATH = os.path.join(os.environ["HOME"], CONFIG_DIR, CREDENTIALS_FILENAME)
     31 
     32 ##########################################################################

/usr/lib/python3.6/os.py in __getitem__(self, key)
    667         except KeyError:
    668             # raise KeyError with the original key value
--> 669             raise KeyError(key) from None
    670         return self.decodevalue(value)
    671 

KeyError: 'HOME'

There is of course a workaround to set the HOME var by hand, but it seems like this shouldn't be a requirement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions