Skip to content

Commit

Permalink
Fix unintended directory stripping during cylc install (#4931)
Browse files Browse the repository at this point in the history
* Fix unintended directory stripping during cylc install
* Update tests/unit/test_workflow_files.py
* Add functional test and add to docstring.
Co-authored-by: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com>
  • Loading branch information
datamel authored Jun 29, 2022
1 parent 73cef83 commit e117e3b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ in `global.cylc[install]source dirs`.

### Fixes

[#4931](https://github.com/cylc/cylc-flow/pull/4931) - Fix cylc install for
installing workflows from multi-level directories.

[#4926](https://github.com/cylc/cylc-flow/pull/4926) - Fix a docstring
formatting problem presenting in the UI mutation flow argument info.

Expand Down
9 changes: 6 additions & 3 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ def install_workflow(
Trying to install a workflow that is nested inside of another.
"""
abort_if_flow_file_in_path(source)
source = Path(expand_path(source))
source = Path(expand_path(source)).resolve()
if not workflow_name:
workflow_name = get_source_workflow_name(source)
validate_workflow_name(workflow_name, check_reserved_names=True)
Expand Down Expand Up @@ -1904,10 +1904,13 @@ def search_install_source_dirs(workflow_name: Union[Path, str]) -> Path:

def get_source_workflow_name(source: Path) -> str:
"""Return workflow name relative to configured source dirs if possible,
else the basename of the given path."""
else the basename of the given path.
Note the source path provided should be fully expanded (user and env vars)
and normalised.
"""
for dir_ in get_source_dirs():
try:
return str(source.relative_to(dir_))
return str(source.relative_to(Path(expand_path(dir_)).resolve()))
except ValueError:
continue
return source.name
Expand Down
24 changes: 23 additions & 1 deletion tests/functional/cylc-install/00-simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#------------------------------------------------------------------------------
# Test workflow installation
. "$(dirname "$0")/test_header"
set_test_number 18
set_test_number 22

create_test_global_config "" "
[install]
Expand Down Expand Up @@ -130,3 +130,25 @@ INSTALLED $RND_WORKFLOW_NAME/run2 from ${RND_WORKFLOW_SOURCE}
__OUT__
popd || exit 1
purge_rnd_workflow

# -----------------------------------------------------------------------------
# Test running cylc install with multi level name works correctly
TEST_NAME="${TEST_NAME_BASE}-install-multi-level"
pushd cylc-src || exit 1
make_rnd_workflow
SUB_DIR="cylctb-x$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6)"
mkdir "${RND_WORKFLOW_NAME}/${SUB_DIR}"
mv "${RND_WORKFLOW_NAME}/flow.cylc" "${RND_WORKFLOW_NAME}/${SUB_DIR}"

run_ok "${TEST_NAME}" cylc install "${RND_WORKFLOW_NAME}/${SUB_DIR}"
contains_ok "${TEST_NAME}.stdout" <<__OUT__
INSTALLED ${RND_WORKFLOW_NAME}/${SUB_DIR}/run1 from ${RND_WORKFLOW_SOURCE}/$SUB_DIR
__OUT__
TEST_NAME="${TEST_NAME_BASE}-multi-level-from-pwd"
pushd "${RND_WORKFLOW_SOURCE}/$SUB_DIR" || exit 1
run_ok "${TEST_NAME}" cylc install
contains_ok "${TEST_NAME}.stdout" <<__OUT__
INSTALLED ${RND_WORKFLOW_NAME}/${SUB_DIR}/run2 from ${RND_WORKFLOW_SOURCE}/${SUB_DIR}
__OUT__
popd || exit 1
purge_rnd_workflow
11 changes: 6 additions & 5 deletions tests/unit/test_workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,9 +1526,9 @@ def test_search_install_source_dirs_empty(mock_glbl_cfg: Callable):
@pytest.mark.parametrize(
'path, expected',
[
('/isla/nublar/dennis/nedry', 'dennis/nedry'),
('/isla/sorna/paul/kirby', 'paul/kirby'),
('/mos/eisley/owen/skywalker', 'skywalker')
('~/isla/nublar/dennis/nedry', 'dennis/nedry'),
('~/isla/sorna/paul/kirby', 'paul/kirby'),
('~/mos/eisley/owen/skywalker', 'skywalker')
]
)
def test_get_source_workflow_name(
Expand All @@ -1540,10 +1540,11 @@ def test_get_source_workflow_name(
'cylc.flow.workflow_files.glbl_cfg',
'''
[install]
source dirs = /isla/nublar, /isla/sorna
source dirs = ~/isla/nublar, ${HOME}/isla/sorna
'''
)
assert get_source_workflow_name(Path(path)) == expected
assert get_source_workflow_name(
Path(path).expanduser().resolve()) == expected


@pytest.mark.parametrize(
Expand Down

0 comments on commit e117e3b

Please sign in to comment.