Skip to content

Commit

Permalink
Merge pull request #98 from seqeralabs/dev
Browse files Browse the repository at this point in the history
Release v0.4.4
  • Loading branch information
ejseqera authored Nov 29, 2023
2 parents 1937f2b + 403f490 commit f214e99
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
6 changes: 6 additions & 0 deletions seqerakit/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def parse_pipelines_block(item):
)
params_args.extend(["--params-file", temp_file_name])

if params_file_path and "params" not in item:
params_args.extend(["--params-file", params_file_path])

combined_args = cmd_args + repo_args + params_args
return combined_args

Expand All @@ -267,6 +270,9 @@ def parse_launch_block(item):
)
params_args.extend(["--params-file", temp_file_name])

if params_file_path and "params" not in item:
params_args.extend(["--params-file", params_file_path])

cmd_args = cmd_args + repo_args + params_args
return cmd_args

Expand Down
41 changes: 21 additions & 20 deletions seqerakit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,40 +111,41 @@ def is_url(s):
return False


class quoted_str(str):
pass


def quoted_str_representer(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style='"')


yaml.add_representer(quoted_str, quoted_str_representer)


def create_temp_yaml(params_dict, params_file=None):
"""
Create a generic temporary yaml file given a dictionary
Create a temporary YAML file given a dictionary.
Optionally combine with contents from a JSON or YAML file if provided.
"""
combined_params = {}

def read_file(file_path):
with open(file_path, "r") as file:
if file_path.endswith(".json"):
return json.load(file)
else:
return yaml.safe_load(file)
return (
json.load(file) if file_path.endswith(".json") else yaml.safe_load(file)
)

combined_params = {}

# If a params_file is provided, update the dict
if params_file:
file_params = read_file(params_file)
combined_params.update(file_params)

combined_params.update(params_dict)

class quoted_str(str):
pass

def quoted_str_representer(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style='"')

yaml.add_representer(quoted_str, quoted_str_representer)

# # Expand environment variables and quote strings
params_dict = {
k: quoted_str(os.path.expandvars(v)) if isinstance(v, str) else v
for k, v in combined_params.items()
}
for key, value in combined_params.items():
if isinstance(value, str):
expanded_value = re.sub(r"\$\{?\w+\}?", replace_env_var, value)
combined_params[key] = quoted_str(expanded_value)

with tempfile.NamedTemporaryFile(
mode="w", delete=False, suffix=".yaml"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import find_packages, setup

VERSION = "0.4.3"
VERSION = "0.4.4"

with open("README.md") as f:
readme = f.read()
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def test_create_mock_pipeline_add_yaml(mock_yaml_file):
"--workspace",
"my_organization/my_workspace",
"https://github.com/nf-core/test_pipeline1",
"--params-file",
"./examples/yaml/pipelines/test_pipeline1/params.yaml",
],
"overwrite": True,
}
Expand Down

0 comments on commit f214e99

Please sign in to comment.