Skip to content

Commit

Permalink
Fixed #410
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Aug 18, 2023
1 parent 4fa946e commit d90fa8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 43 deletions.
8 changes: 6 additions & 2 deletions looper/cli_looper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from .utils import (
dotfile_path,
enrich_args_via_cfg,
init_dotfile,
is_registry_path,
read_looper_dotfile,
read_looper_config_file,
read_yaml_file,
initiate_looper_config,
)


Expand Down Expand Up @@ -564,9 +564,13 @@ def main(test_args=None):

if args.command == "init":
return int(
not init_dotfile(
not initiate_looper_config(
dotfile_path(),
args.config_file,
args.output_dir,
args.sample_pipeline_interfaces,
args.project_pipeline_interfaces,
args.force,
)
)

Expand Down
42 changes: 7 additions & 35 deletions looper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,30 +358,15 @@ def init_generic_pipeline():
return True


def init_dotfile(
path: str,
looper_config_path: str,
force=False,
):
def read_looper_dotfile():
"""
Initialize looper dotfile
:param str path: absolute path to the dot file to initialize
:param str looper_config_path: path to the looper config file. Absolute or relative to 'path'
:param bool force: whether the existing file should be overwritten
:return bool: whether the file was initialized
Read looper config file
:return str: path to the config file read from the dotfile
:raise MisconfigurationException: if the dotfile does not consist of the
required key pointing to the PEP
"""
if os.path.exists(path) and not force:
print(f"Can't initialize, file exists: {path}")
return False
dot_dict = {
"looper_config": os.path.relpath(looper_config_path, os.path.dirname(path)),
}

with open(path, "w") as dotfile:
yaml.dump(dot_dict, dotfile)
print(f"Initialized looper dotfile: {path}")
return True
dot_file_path = dotfile_path(must_exist=True)
return read_looper_config_file(looper_config_path=dot_file_path)


def initiate_looper_config(
Expand Down Expand Up @@ -439,19 +424,6 @@ def initiate_looper_config(
return True


def read_looper_dotfile():
"""
Read looper config file
:raise MisconfigurationException: if the dotfile does not consist of the
required key pointing to the PEP
"""
dot_file_path = dotfile_path(must_exist=True)
with open(dot_file_path, "r") as file:
looper_config_path = yaml.safe_load(file)["looper_config"]
return read_looper_config_file(looper_config_path=looper_config_path)


def read_looper_config_file(looper_config_path: str) -> dict:
"""
Read Looper config file which includes:
Expand Down
13 changes: 7 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,15 @@ def prepare_pep_with_dot_file(prep_temp_pep):
},
}

looper_config_path = os.path.join(os.path.dirname(pep_config), "looper_config.yaml")
# looper_config_path = os.path.join(os.path.dirname(pep_config), "looper_config.yaml")
#
# with open(looper_config_path, "w") as f:
# config = dump(looper_config, f)
#
# looper_dot_file_content = {"looper_config": looper_config_path}

with open(looper_config_path, "w") as f:
config = dump(looper_config, f)

looper_dot_file_content = {"looper_config": looper_config_path}
dot_file_path = ".looper.yaml"
with open(dot_file_path, "w") as f:
config = dump(looper_dot_file_content, f)
config = dump(looper_config, f)

return dot_file_path

0 comments on commit d90fa8b

Please sign in to comment.