Skip to content

Commit

Permalink
fix: implement --interactive flag to MultipleReader
Browse files Browse the repository at this point in the history
Also fix CHAP/runner.py to allow the interactive flag set as either
    a command line argument or a processor keyword in the pipeline
  • Loading branch information
rolfverberg committed Apr 17, 2023
1 parent 4fea487 commit 1303e43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 6 additions & 2 deletions CHAP/common/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# system modules
import argparse
import inspect
import json
import logging
import sys
Expand All @@ -28,7 +29,7 @@ def _read(self, filename):
return(data)

class MultipleReader(Reader):
def read(self, readers):
def read(self, readers, **_read_kwargs):
'''Return resuts from multiple `Reader`s.
:param readers: a dictionary where the keys are specific names that are
Expand All @@ -50,7 +51,10 @@ def read(self, readers):
reader = reader_class()
reader_kwargs = reader_config[reader_name]

data.extend(reader.read(**reader_kwargs))
# Combine keyword arguments to MultipleReader.read with those to the reader
# giving precedence to those in the latter
combined_kwargs = {**_read_kwargs, **reader_kwargs}
data.extend(reader.read(**combined_kwargs))

self.logger.info(f'Finished "read" in {time()-t0:.3f} seconds\n')

Expand Down
10 changes: 4 additions & 6 deletions CHAP/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#pylint: disable=
"""
File : runner.py
Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
Expand Down Expand Up @@ -57,13 +54,14 @@ def runner(opts):
kwds = []
for item in pipeline_config:
# load individual object with given name from its module
kwargs = {'interactive': opts.interactive}
if isinstance(item, dict):
name = list(item.keys())[0]
kwargs = item[name]
# Combine the "interactive" command line argument with the object's keywords
# giving precedence of "interactive" in the latter
kwargs = {**kwargs, **item[name]}
else:
name = item
kwargs = {}
kwargs['interactive'] = opts.interactive
modName, clsName = name.split('.')
module = __import__(f'CHAP.{modName}', fromlist=[clsName])
obj = getattr(module, clsName)()
Expand Down

0 comments on commit 1303e43

Please sign in to comment.