fix issue with specifying ports via env vars
make sure tcp and udp port for dht are int type
This commit is contained in:
parent
26964ecf0f
commit
e49fcea6e3
2 changed files with 17 additions and 3 deletions
15
lbry/conf.py
15
lbry/conf.py
|
@ -277,8 +277,17 @@ class Strings(ListSetting):
|
|||
class EnvironmentAccess:
|
||||
PREFIX = 'LBRY_'
|
||||
|
||||
def __init__(self, environ: dict):
|
||||
self.environ = environ
|
||||
def __init__(self, config: 'BaseConfig', environ: dict):
|
||||
self.configuration = config
|
||||
self.environ = {}
|
||||
if environ:
|
||||
self.load(environ)
|
||||
|
||||
def load(self, environ):
|
||||
for setting in self.configuration.get_settings():
|
||||
value = environ.get(f'{self.PREFIX}{setting.name.upper()}', NOT_SET)
|
||||
if value != NOT_SET and not (isinstance(setting, ListSetting) and value is None):
|
||||
self.environ[f'{self.PREFIX}{setting.name.upper()}'] = setting.deserialize(value)
|
||||
|
||||
def __contains__(self, item: str):
|
||||
return f'{self.PREFIX}{item.upper()}' in self.environ
|
||||
|
@ -443,7 +452,7 @@ class BaseConfig:
|
|||
self.arguments = ArgumentAccess(self, args)
|
||||
|
||||
def set_environment(self, environ=None):
|
||||
self.environment = EnvironmentAccess(environ or os.environ)
|
||||
self.environment = EnvironmentAccess(self, dict(environ or os.environ))
|
||||
|
||||
def set_persisted(self, config_file_path=None):
|
||||
if config_file_path is None:
|
||||
|
|
|
@ -93,6 +93,11 @@ class ConfigurationTests(unittest.TestCase):
|
|||
self.assertEqual(c.test_str, 'the default')
|
||||
c.set_environment({'LBRY_TEST_STR': 'from environ'})
|
||||
self.assertEqual(c.test_str, 'from environ')
|
||||
|
||||
c = TestConfig()
|
||||
self.assertEqual(c.test_int, 9)
|
||||
c.set_environment({'LBRY_TEST_INT': '1'})
|
||||
self.assertEqual(c.test_int, 1)
|
||||
|
||||
def test_persisted(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
|
|
Loading…
Reference in a new issue