Skip to content

Commit

Permalink
Merge 3f4dc54 into 221134c
Browse files Browse the repository at this point in the history
  • Loading branch information
mellesies committed Jan 16, 2023
2 parents 221134c + 3f4dc54 commit f42f75b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions vantage6-client/vantage6/tools/docker_wrapper.py
Expand Up @@ -26,9 +26,9 @@
_SPARQL_RETURN_FORMAT = CSV


def docker_wrapper(module: str):
def docker_wrapper(module: str, load_data=True):
wrapper = DockerWrapper()
wrapper.wrap_algorithm(module)
wrapper.wrap_algorithm(module, load_data)


def sparql_wrapper(module: str):
Expand All @@ -48,7 +48,7 @@ def multidb_wrapper(module: str):

class WrapperBase(ABC):

def wrap_algorithm(self, module):
def wrap_algorithm(self, module, load_data=True):
"""
Wrap an algorithm module to provide input and output handling for the
vantage6 infrastructure.
Expand Down Expand Up @@ -85,6 +85,7 @@ def wrap_algorithm(self, module):
- pandas DataFrames
:param module: module that contains the vantage6 algorithms
:param load_data: attempt to load the data or execute the query
:return:
"""
info(f"wrapper for {module}")
Expand All @@ -107,14 +108,18 @@ def wrap_algorithm(self, module):
# default one
database_uri = os.environ["DATABASE_URI"]
info(f"Using '{database_uri}' as database")
data = self.load_data(database_uri, input_data)

if load_data:
data = self.load_data(database_uri, input_data)
else:
data = None

# make the actual call to the method/function
info("Dispatching ...")
output = dispatch_rpc(data, input_data, module, token)

# write output from the method to mounted output file. Which will be
# transfered back to the server by the node-instance.
# transferred back to the server by the node-instance.
output_file = os.environ["OUTPUT_FILE"]
info(f"Writing output to {output_file}")

Expand All @@ -133,6 +138,9 @@ def load_data(database_uri, input_data):
return pandas.read_csv(database_uri)


CsvWrapper = DockerWrapper


class SparqlDockerWrapper(WrapperBase):
@staticmethod
def load_data(database_uri, input_data):
Expand Down Expand Up @@ -170,7 +178,8 @@ def write_output(output_format, output, output_file):
"""
Write output to output_file using the format from output_format.
If output_format == None, write output as pickle without indicating format (legacy method)
If output_format == None, write output as pickle without indicating format
(legacy method)
:param output_format:
:param output:
Expand Down

0 comments on commit f42f75b

Please sign in to comment.