-
Notifications
You must be signed in to change notification settings - Fork 94
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
Prevent cylc clean from removing workflow base dirs containing run dirs/named runs #4289
Conversation
… a workflow All workflow run dirs contain a log/workflow/log dir, which was getting erroneously identified as a workflow. Solution was to exit from the generator if the scan dir itself is a workflow run dir.
This comment has been minimized.
This comment has been minimized.
@pytest.fixture(scope='session') | ||
def badly_messed_up_run_dir(): | ||
tmp_path = Path(TemporaryDirectory().name) | ||
tmp_path.mkdir() | ||
@pytest.fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixture only used once so I've made it function-scoped to allow monkeypatching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Read, all makes sense.
- Tried it out → Working.
cylc/flow/workflow_files.py
Outdated
f"Cannot remove running workflow.\n\n{exc}") | ||
raise ServiceFileError(f"Cannot remove running workflow.\n\n{exc}") | ||
# Check dir does not contain other workflows: | ||
contained_workflows = asyncio.run(get_contained_workflows(run_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok (if it wasn't I would expect all the tests to fail), however, could cause bugs later on.
The convenience function asyncio.run
function creates a new event loop and closes it, I think that can cause issues when other event loops are kicking about.
This function cannot be called when another asyncio event loop is running in the same thread.
If debug is True, the event loop will be run in debug mode.
This function always creates a new event loop and closes it at the end. It should be used as a main entry point for asyncio programs, and should ideally only be called once.
I think the alternative here would be the totally user-friendly asyncio.get_event_loop().run_until_complete(coro())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit worried about that
Should
|
Marking as draft while investigating the (As discussed on Teams) |
- Increase scan depth for cylc clean when it checks that the dir doesn't contain other workflows - Try to safen up use of asyncio
e8ac170
to
9e20d8d
Compare
9e20d8d
to
8060cc2
Compare
f"{bullet}{bullet.join(contained_workflows)}" | ||
) | ||
if not opts.force: | ||
raise WorkflowFilesError(f"Cannot clean - {msg}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a note to the end of the message to the effect that the user can use --force
if that is what they genuinely want to do...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Scan read changes since last time.
- Played with result branch, run some examples.
- Had an in-depth play with
test_init_clean__multiple_runs
. Assured myself that Codecov is wrong in stating some logic not tested. - Had an in-depth play with
test_remove_empty_parents
Merging as 2 approvals |
These changes close #4163 (assuming we're happy not having an
--all
option and will instead wait until universal ID is implemented, allowingcylc clean foo/*
)Explanation
If you have
Up til now, doing
cylc clean foo
would just delete~/cylc-run/foo
, and if you had any symlink dirs or remote installations, they wouldn't get cleaned.With this PR, it now raises an error if you try to clean a dir containing multiple (>1) runs - you have to explicitly type out the run dir. However:
foo/run1
followed by deletingfoo
)--force
to allow possibly incomplete cleaning of the specified dir (e.g. it will just delete thefoo
dir)Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.setup.py
andconda-environment.yml
.