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

add import + better message for par #347

Merged
merged 6 commits into from
Nov 12, 2023
Merged
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: 13 additions & 6 deletions latch_cli/snakemake/config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -182,7 +189,7 @@ def generate_metadata(
# Import these into your `__init__.py` file:
#
# from .parameters import generated_parameters
#

generated_parameters = {
__params__
}
Expand Down
3 changes: 2 additions & 1 deletion latch_cli/snakemake/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions latch_cli/snakemake/serialize_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Dict, Union

from flytekit import LaunchPlan
Expand Down Expand Up @@ -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()
Loading