def prepare(*, step: str, default_parameters: dict = {}, default_inputs: dict = {}): """Define the name of the step and it's required inputs and parameters Has dual purpose: - Provide default values for inputs & parameters so the user code can be executed - Provide entry-point for the parser that generates/updates valohai.yaml integration file :param step: Step name for valohai.yaml :param default_parameters: Dict of parameters and default values :param default_inputs: Dict of inputs with (list of) default URIs """ global_state.step_name = step parser = argparse.ArgumentParser() for name, default_value in dict(default_inputs).items(): parser.add_argument(f"--{name}", type=str, nargs="+", default=default_value) for name, default_value in dict(default_parameters).items(): parser.add_argument( f"--{name}", type=type(default_value), default=default_value ) known_args, unknown_args = parser.parse_known_args() if not is_running_in_valohai(): _load_inputs(known_args, list(default_inputs.keys())) _load_parameters(known_args, list(default_parameters.keys())) for unknown in unknown_args: print( f"Warning: Unexpected command-line argument {unknown} found.", file=sys.stderr, )
def get_outputs_path() -> str: if is_running_in_valohai(): return os.environ.get("VH_OUTPUTS_DIR", "/valohai/outputs") else: return os.environ.get( "VH_OUTPUTS_DIR", os.path.join( VH_LOCAL_OUTPUTS_DIR, get_execution_guid(), global_state.step_name ), )
def get_inputs_path(input_name: Optional[str] = None) -> str: if is_running_in_valohai(): path = os.environ.get("VH_INPUTS_DIR", "/valohai/inputs") else: path = os.environ.get( "VH_INPUTS_DIR", os.path.join(VH_LOCAL_INPUTS_DIR, global_state.step_name) ) if input_name: path = os.path.join(path, input_name) return path
def get_config_path() -> str: return os.environ.get( "VH_CONFIG_DIR", "/valohai/config" if is_running_in_valohai() else VH_LOCAL_CONFIG_DIR, )
def get_repository_path() -> str: return os.environ.get( "VH_REPOSITORY_DIR", "/valohai/repository" if is_running_in_valohai() else VH_LOCAL_REPOSITORY_DIR, )