Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted capturer log level and added arguments. #136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions biosimulators_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
:License: MIT
"""

from .log.data_model import StandardOutputErrorCapturerLevel
from .omex_meta.data_model import OmexMetadataInputFormat, OmexMetadataOutputFormat, OmexMetadataSchema
from .report.data_model import ReportFormat # noqa: F401
from .viz.data_model import VizFormat # noqa: F401
from kisao import AlgorithmSubstitutionPolicy # noqa: F401
import appdirs
import enum
import os
from typing import List

__all__ = ['Config', 'get_config', 'Colors', 'get_app_dirs']

DEFAULT_STDOUT_CAPTURE_LEVEL = StandardOutputErrorCapturerLevel.python
DEFAULT_OMEX_METADATA_INPUT_FORMAT = OmexMetadataInputFormat.rdfxml
DEFAULT_OMEX_METADATA_OUTPUT_FORMAT = OmexMetadataOutputFormat.rdfxml_abbrev
DEFAULT_OMEX_METADATA_SCHEMA = OmexMetadataSchema.biosimulations
DEFAULT_ALGORITHM_SUBSTITUTION_POLICY = AlgorithmSubstitutionPolicy.SIMILAR_VARIABLES
DEFAULT_H5_REPORTS_PATH = 'reports.h5'
DEFAULT_CSV_REPORTS_PATH = 'reports.csv'
DEFAULT_REPORTS_PATH = 'reports.zip'
DEFAULT_PLOTS_PATH = 'plots.zip'
DEFAULT_LOG_PATH = 'log.yml'
Expand All @@ -30,6 +34,7 @@
DEFAULT_BIOSIMULATIONS_API_AUDIENCE = 'api.biosimulations.org'



class Config(object):
""" Configuration

Expand Down Expand Up @@ -82,7 +87,7 @@ def __init__(self,
COLLECT_COMBINE_ARCHIVE_RESULTS=False,
COLLECT_SED_DOCUMENT_RESULTS=False,
SAVE_PLOT_DATA=True,
REPORT_FORMATS=[ReportFormat.h5],
REPORT_FORMATS=[ReportFormat.csv],
VIZ_FORMATS=[VizFormat.pdf],
H5_REPORTS_PATH=DEFAULT_H5_REPORTS_PATH,
REPORTS_PATH=DEFAULT_REPORTS_PATH,
Expand All @@ -96,7 +101,8 @@ def __init__(self,
BIOSIMULATIONS_API_AUTH_ENDPOINT=DEFAULT_BIOSIMULATIONS_API_AUTH_ENDPOINT,
BIOSIMULATIONS_API_AUDIENCE=DEFAULT_BIOSIMULATIONS_API_AUDIENCE,
VERBOSE=False,
DEBUG=False):
DEBUG=False,
STDOUT_CAPTURE_LEVEL=DEFAULT_STDOUT_CAPTURE_LEVEL):
"""
Args:
OMEX_METADATA_INPUT_FORMAT (:obj:`OmexMetadataInputFormat`, optional): format to validate OMEX Metadata files against
Expand Down Expand Up @@ -162,21 +168,23 @@ def __init__(self,
self.BIOSIMULATIONS_API_AUDIENCE = BIOSIMULATIONS_API_AUDIENCE
self.VERBOSE = VERBOSE
self.DEBUG = DEBUG
self.STDOUT_CAPTURE_LEVEL = STDOUT_CAPTURE_LEVEL



def get_config():
def get_config(report_format: str = 'csv', viz_format: str = 'pdf'):
""" Get the configuration

Returns:
:obj:`Config`: configuration
"""
report_formats = os.environ.get('REPORT_FORMATS', 'h5').strip()
report_formats = os.environ.get('REPORT_FORMATS', report_format).strip()
if report_formats:
report_formats = [ReportFormat(format.strip().lower()) for format in report_formats.split(',')]
else:
report_formats = []

viz_formats = os.environ.get('VIZ_FORMATS', 'pdf').strip()
viz_formats = os.environ.get('VIZ_FORMATS', viz_format).strip()
if viz_formats:
viz_formats = [VizFormat(format.strip().lower()) for format in viz_formats.split(',')]
else:
Expand Down Expand Up @@ -216,6 +224,7 @@ def get_config():
BIOSIMULATIONS_API_AUDIENCE=os.environ.get('BIOSIMULATIONS_API_AUDIENCE', DEFAULT_BIOSIMULATIONS_API_AUDIENCE),
VERBOSE=os.environ.get('VERBOSE', '1').lower() in ['1', 'true'],
DEBUG=os.environ.get('DEBUG', '0').lower() in ['1', 'true'],
STDOUT_CAPTURE_LEVEL=os.environ.get('STDOUT_CAPTURE_LEVEL', DEFAULT_STDOUT_CAPTURE_LEVEL),
)


Expand Down
15 changes: 10 additions & 5 deletions biosimulators_utils/sedml/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tempfile
import termcolor
import types # noqa: F401
from typing import Union, Tuple


__all__ = [
Expand All @@ -47,11 +48,12 @@
]


def exec_sed_doc(task_executer, doc, working_dir, base_out_path, rel_out_path=None,
apply_xml_model_changes=False,
log=None, indent=0, pretty_print_modified_xml_models=False,
log_level=StandardOutputErrorCapturerLevel.c,
config=None):
def exec_sed_doc(task_executer: types.FunctionType, doc: Union[SedDocument, str],
working_dir: str, base_out_path: str, rel_out_path: str = None,
apply_xml_model_changes: bool = False, log: SedDocumentLog = None,
indent: int = 0, pretty_print_modified_xml_models: bool = False,
log_level: StandardOutputErrorCapturerLevel = None,
config: Config = None) -> Tuple[ReportResults, SedDocumentLog]:
""" Execute the tasks specified in a SED document and generate the specified outputs

Args:
Expand Down Expand Up @@ -103,6 +105,9 @@ def exec_task(task, variables, preprocessed_task=None, log=None, config=None, **
"""
if not config:
config = get_config()

if not log_level:
log_level = config.STDOUT_CAPTURE_LEVEL

# process arguments
if not isinstance(doc, SedDocument):
Expand Down