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

Fix unintended directory stripping during cylc install #4931

Merged
merged 7 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
7 changes: 5 additions & 2 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
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(expand_path(dir_)))
except ValueError:
continue
return source.name
Expand Down
18 changes: 17 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 20

create_test_global_config "" "
[install]
Expand Down Expand Up @@ -130,3 +130,19 @@ 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__
popd || exit 1
purge_rnd_workflow
10 changes: 5 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,10 @@ 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()) == expected


@pytest.mark.parametrize(
Expand Down