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

Allow src dir in run dir #4861

Merged
merged 5 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ Third Release Candidate for Cylc 8 suitable for acceptance testing.

### Enhancements


[#4842](https://github.com/cylc/cylc-flow/pull/4842) -
Improve Jinja2 error reporting when the error is behind an `{% include`.

[#4861](https://github.com/cylc/cylc-flow/pull/4861) - Allow workflow source
directories to be under `cylc-run`.

[#4828](https://github.com/cylc/cylc-flow/pull/4828) - scan CLI: corrupt
workflow contact files should result in a warning, not a crash.

Expand Down
12 changes: 0 additions & 12 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
expand_path,
get_cylc_run_dir,
get_workflow_run_dir,
is_relative_to,
make_localhost_symlinks,
parse_rm_dirs,
remove_dir_and_target,
Expand Down Expand Up @@ -1791,15 +1790,13 @@ def validate_source_dir(
"""Ensure the source directory is valid:
- has flow file
- does not contain reserved dir names
- is not inside ~/cylc-run.

Args:
source: Path to source directory
Raises:
WorkflowFilesError:
If log, share, work or _cylc-install directories exist in the
source directory.
Cylc installing from within the cylc-run dir
"""
# Ensure source dir does not contain log, share, work, _cylc-install
for dir_ in WorkflowFiles.RESERVED_DIRNAMES:
Expand All @@ -1808,15 +1805,6 @@ def validate_source_dir(
f"{workflow_name} installation failed. "
f"- {dir_} exists in source directory."
)
cylc_run_dir = get_cylc_run_dir()
if is_relative_to(
os.path.abspath(os.path.realpath(source)),
os.path.abspath(os.path.realpath(cylc_run_dir))
):
raise WorkflowFilesError(
f"{workflow_name} installation failed. Source directory "
f"should not be in {cylc_run_dir}."
)
check_flow_file(source)


Expand Down
19 changes: 1 addition & 18 deletions tests/functional/cylc-install/02-failures.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


. "$(dirname "$0")/test_header"
set_test_number 47
set_test_number 45

create_test_global_config '' '
[install]
Expand Down Expand Up @@ -228,23 +228,6 @@ grep_ok "WorkflowFilesError: Symlink broken" "${TEST_NAME}.stderr"
rm -rf "${ALT_SOURCE}"
purge_rnd_workflow

# -----------------------------------------------------------------------------
# Test cylc install can not be run from within the cylc-run directory

make_rnd_workflow
TEST_NAME="${TEST_NAME_BASE}-forbid-cylc-run-dir-install"
BASE_NAME="test-install-${CYLC_TEST_TIME_INIT}"
mkdir -p "${RUN_DIR}/${BASE_NAME}/${TEST_SOURCE_DIR_BASE}/${TEST_NAME}" && cd "$_" || exit
touch flow.cylc
run_fail "${TEST_NAME}" cylc install --workflow-name "$RND_WORKFLOW_NAME"
contains_ok "${TEST_NAME}.stderr" <<__ERR__
WorkflowFilesError: ${RND_WORKFLOW_NAME} installation failed. Source directory should not be in ${RUN_DIR}.
__ERR__

cd "${RUN_DIR}" || exit
rm -rf "${BASE_NAME}"
purge_rnd_workflow

# -----------------------------------------------------------------------------
# --run-name cannot be a path

Expand Down
13 changes: 10 additions & 3 deletions tests/unit/test_workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,12 +1884,19 @@ def test_validate_source_dir(tmp_run_dir: Callable, tmp_src_dir: Callable):
with pytest.raises(WorkflowFilesError) as exc_info:
validate_source_dir(src_dir, 'roland')
assert "exists in source directory" in str(exc_info.value)
# Test that src dir is not allowed to be inside ~/cylc-run
# Test that src dir is allowed to be inside ~/cylc-run
src_dir = cylc_run_dir / 'dieter'
src_dir.mkdir()
(src_dir / WorkflowFiles.FLOW_FILE).touch()
validate_source_dir(src_dir, 'dieter')
# Test that src dir is not allowed to be an installed dir.
src_dir = cylc_run_dir / 'ajay'
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Hehe, I hope so 🤣

src_dir.mkdir()
(src_dir / WorkflowFiles.Install.DIRNAME).mkdir()
(src_dir / WorkflowFiles.FLOW_FILE).touch()
with pytest.raises(WorkflowFilesError) as exc_info:
validate_source_dir(src_dir, 'dieter')
assert "Source directory should not be in" in str(exc_info.value)
validate_source_dir(src_dir, 'ajay')
assert "exists in source directory" in str(exc_info.value)


@pytest.mark.parametrize(
Expand Down