Merge pull request #1951 from hroff-1902/pipe-config

allow reading config from stdin
This commit is contained in:
Matthias 2019-06-20 19:29:14 +02:00 committed by GitHub
commit b8fb38b92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -26,7 +26,8 @@ optional arguments:
--version show program's version number and exit
-c PATH, --config PATH
Specify configuration file (default: None). Multiple
--config options may be used.
--config options may be used. Can be set to '-' to
read config from stdin.
-d PATH, --datadir PATH
Path to backtest data.
-s NAME, --strategy NAME

View File

@ -85,8 +85,9 @@ class Arguments(object):
)
self.parser.add_argument(
'-c', '--config',
help='Specify configuration file (default: %(default)s). '
'Multiple --config options may be used.',
help="Specify configuration file (default: %(default)s). "
"Multiple --config options may be used. "
"Can be set to '-' to read config from stdin.",
dest='config',
action='append',
type=str,

View File

@ -79,6 +79,7 @@ class Configuration(object):
# Now expecting a list of config filenames here, not a string
for path in self.args.config:
logger.info('Using config: %s ...', path)
# Merge config options, overwriting old values
config = deep_merge_dicts(self._load_config_file(path), config)
@ -118,7 +119,8 @@ class Configuration(object):
:return: configuration as dictionary
"""
try:
with open(path) as file:
# Read config from stdin if requested in the options
with open(path) if path != '-' else sys.stdin as file:
conf = json.load(file)
except FileNotFoundError:
raise OperationalException(