minor simplifcation
This commit is contained in:
parent
e49fcea6e3
commit
b09eabc478
2 changed files with 7 additions and 7 deletions
10
lbry/conf.py
10
lbry/conf.py
|
@ -279,7 +279,7 @@ class EnvironmentAccess:
|
||||||
|
|
||||||
def __init__(self, config: 'BaseConfig', environ: dict):
|
def __init__(self, config: 'BaseConfig', environ: dict):
|
||||||
self.configuration = config
|
self.configuration = config
|
||||||
self.environ = {}
|
self.data = {}
|
||||||
if environ:
|
if environ:
|
||||||
self.load(environ)
|
self.load(environ)
|
||||||
|
|
||||||
|
@ -287,13 +287,13 @@ class EnvironmentAccess:
|
||||||
for setting in self.configuration.get_settings():
|
for setting in self.configuration.get_settings():
|
||||||
value = environ.get(f'{self.PREFIX}{setting.name.upper()}', NOT_SET)
|
value = environ.get(f'{self.PREFIX}{setting.name.upper()}', NOT_SET)
|
||||||
if value != NOT_SET and not (isinstance(setting, ListSetting) and value is None):
|
if value != NOT_SET and not (isinstance(setting, ListSetting) and value is None):
|
||||||
self.environ[f'{self.PREFIX}{setting.name.upper()}'] = setting.deserialize(value)
|
self.data[setting.name] = setting.deserialize(value)
|
||||||
|
|
||||||
def __contains__(self, item: str):
|
def __contains__(self, item: str):
|
||||||
return f'{self.PREFIX}{item.upper()}' in self.environ
|
return item in self.data
|
||||||
|
|
||||||
def __getitem__(self, item: str):
|
def __getitem__(self, item: str):
|
||||||
return self.environ[f'{self.PREFIX}{item.upper()}']
|
return self.data[item]
|
||||||
|
|
||||||
|
|
||||||
class ArgumentAccess:
|
class ArgumentAccess:
|
||||||
|
@ -452,7 +452,7 @@ class BaseConfig:
|
||||||
self.arguments = ArgumentAccess(self, args)
|
self.arguments = ArgumentAccess(self, args)
|
||||||
|
|
||||||
def set_environment(self, environ=None):
|
def set_environment(self, environ=None):
|
||||||
self.environment = EnvironmentAccess(self, dict(environ or os.environ))
|
self.environment = EnvironmentAccess(self, environ or os.environ)
|
||||||
|
|
||||||
def set_persisted(self, config_file_path=None):
|
def set_persisted(self, config_file_path=None):
|
||||||
if config_file_path is None:
|
if config_file_path is None:
|
||||||
|
|
|
@ -90,11 +90,11 @@ class ConfigurationTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_environment(self):
|
def test_environment(self):
|
||||||
c = TestConfig()
|
c = TestConfig()
|
||||||
|
|
||||||
self.assertEqual(c.test_str, 'the default')
|
self.assertEqual(c.test_str, 'the default')
|
||||||
c.set_environment({'LBRY_TEST_STR': 'from environ'})
|
c.set_environment({'LBRY_TEST_STR': 'from environ'})
|
||||||
self.assertEqual(c.test_str, 'from environ')
|
self.assertEqual(c.test_str, 'from environ')
|
||||||
|
|
||||||
c = TestConfig()
|
|
||||||
self.assertEqual(c.test_int, 9)
|
self.assertEqual(c.test_int, 9)
|
||||||
c.set_environment({'LBRY_TEST_INT': '1'})
|
c.set_environment({'LBRY_TEST_INT': '1'})
|
||||||
self.assertEqual(c.test_int, 1)
|
self.assertEqual(c.test_int, 1)
|
||||||
|
|
Loading…
Reference in a new issue