diff --git a/latch_cli/snakemake/config/parser.py b/latch_cli/snakemake/config/parser.py index 42878b60..37b83b8b 100644 --- a/latch_cli/snakemake/config/parser.py +++ b/latch_cli/snakemake/config/parser.py @@ -9,6 +9,7 @@ from latch_cli.snakemake.workflow import reindent from latch_cli.utils import identifier_from_str +from ..serialize_utils import best_effort_display_name from .utils import JSONValue, get_preamble, parse_type, parse_value, type_repr T = TypeVar("T") @@ -81,10 +82,11 @@ def generate_metadata( is_file = typ in {LatchFile, LatchDir} param_typ = "SnakemakeFileParameter" if is_file else "SnakemakeParameter" + param_str = reindent( f"""\ {repr(identifier_from_str(k))}: {param_typ}( - display_name={repr(k)}, + display_name={repr(best_effort_display_name(k))}, type={type_repr(typ)}, __config____default__),""", 0, @@ -126,14 +128,19 @@ def generate_metadata( old_metadata_path.rename(metadata_path) elif old_metadata_path.exists() and metadata_path.exists(): click.secho( - "Warning: Found both `latch_metadata.py` and" - " `latch_metadata/__init__.py` in current directory." - " `latch_metadata.py` will be ignored.", + ( + "Warning: Found both `latch_metadata.py` and" + " `latch_metadata/__init__.py` in current directory." + " `latch_metadata.py` will be ignored." + ), fg="yellow", ) if not metadata_path.exists() and click.confirm( - "Could not find an `__init__.py` file in `latch_metadata`. Generate one?" + "Could not find an `__init__.py` file in `latch_metadata`. This file" + "defines the metadata object that configures your interface and " + "uses parameters imported from `parameters.py`" + "Generate one?" ): metadata_path.write_text( reindent( @@ -182,7 +189,7 @@ def generate_metadata( # Import these into your `__init__.py` file: # # from .parameters import generated_parameters - # + generated_parameters = { __params__ } diff --git a/latch_cli/snakemake/serialize.py b/latch_cli/snakemake/serialize.py index 63354480..473c9c30 100644 --- a/latch_cli/snakemake/serialize.py +++ b/latch_cli/snakemake/serialize.py @@ -426,7 +426,8 @@ def generate_jit_register_code( from functools import partial from pathlib import Path import shutil - from typing import List, NamedTuple, Optional, TypedDict, Dict + import typing + from typing import NamedTuple, Optional, TypedDict, Dict import hashlib from urllib.parse import urljoin from dataclasses import is_dataclass, asdict diff --git a/latch_cli/snakemake/serialize_utils.py b/latch_cli/snakemake/serialize_utils.py index 4064c1a1..9d793cfa 100644 --- a/latch_cli/snakemake/serialize_utils.py +++ b/latch_cli/snakemake/serialize_utils.py @@ -1,3 +1,4 @@ +import re from typing import Dict, Union from flytekit import LaunchPlan @@ -210,3 +211,8 @@ def get_serializable_workflow( admin_wf = admin_workflow_models.WorkflowSpec(template=wf_t, sub_workflows=[]) cache[entity] = admin_wf return admin_wf + + +def best_effort_display_name(x: str): + expr = re.compile(r"_+") + return expr.sub(" ", x).title().strip()