Skip to content

Commit

Permalink
create and reuse implementation for get-default-config notion
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Jun 19, 2019
1 parent 731812b commit 1e88d90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 4 additions & 5 deletions pypiper/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from .exceptions import PipelineHalt, SubprocessError
from .flags import *
from .utils import \
check_shell, checkpoint_filepath, clear_flags, flag_name, \
is_multi_target, make_lock_name, pipeline_filepath, \
CHECKPOINT_SPECIFICATIONS, get_proc_name, parse_cmd
check_shell, checkpoint_filepath, clear_flags, default_pipeline_config, \
flag_name, get_proc_name, is_multi_target, make_lock_name, parse_cmd, \
pipeline_filepath, CHECKPOINT_SPECIFICATIONS
from .const import PROFILE_COLNAMES
from ._version import __version__
import __main__
Expand Down Expand Up @@ -305,8 +305,7 @@ def __init__(
# print("\nUsing custom config file: {}".format(config_to_load))
else:
# No custom config file specified. Check for default
pipe_path_base, _ = os.path.splitext(os.path.basename(sys.argv[0]))
default_config = "{}.yaml".format(pipe_path_base)
default_config = default_pipeline_config(sys.argv[0])
if os.path.isfile(default_config):
config_to_load = default_config
print("Using default pipeline config file: {}".
Expand Down
15 changes: 11 additions & 4 deletions pypiper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,16 @@ def _determine_args(argument_groups, arguments, use_all_args=False):
return uniqify(final_args)


def default_pipeline_config(pipeline_filepath):
"""
Determine the default filepath for a pipeline's config file.
:param str pipeline_filepath: path to a pipeline
:return str: default filepath for pipeline's config file
"""
return os.path.splitext(os.path.basename(pipeline_filepath))[0] + ".yaml"


def _add_args(parser, args, required):
"""
Add new arguments to an ArgumentParser.
Expand All @@ -749,10 +759,7 @@ def _add_args(parser, args, required):

required = required or []

# Determine the default pipeline config file.
pipeline_script = os.path.basename(sys.argv[0])
default_config, _ = os.path.splitext(pipeline_script)
default_config += ".yaml"
default_config = default_pipeline_config(sys.argv[0])

# Define the arguments.
argument_data = {
Expand Down

2 comments on commit 1e88d90

@nsheff
Copy link
Member

@nsheff nsheff commented on 1e88d90 Jun 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we re-use functionality from yacman for this? if we think of the pipeline config file as a YacAttMap, we have some functaionlity there for default configs as well... just a thought, not sure it makes sense.

@vreuter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I deliberately didn't use YacAttMap -- it lacks echo functionality.

Please sign in to comment.