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

Added Files using tenacity for retrying renaming a directory on a opened filepath. #1826

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spa51273
Copy link
Contributor

@spa51273 spa51273 commented May 21, 2024

PR Checklist:

  • [ x] All new features have been tested
  • All new features have been documented
  • [ x] I have read the CONTRIBUTING.md file
  • [ x] I will abide by the code of conduct

@spa51273 spa51273 marked this pull request as ready for review May 21, 2024 18:36
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR - the broad structure looks good; I've got some comments inline.

"tomli >= 2.0, < 3.0; python_version <= '3.10'",
"tomli_w >= 1.0, < 2.0",
"tomli_w >= 1.0, < 2.0"
Copy link
Member

Choose a reason for hiding this comment

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

Comma on the end is intentional.

Suggested change
"tomli_w >= 1.0, < 2.0"
"tomli_w >= 1.0, < 2.0",

def test_rename_path(mock_tools, tmp_path):
def openclose(filepath):
handler = filepath.open(encoding="UTF-8")
time.sleep(1)
Copy link
Member

Choose a reason for hiding this comment

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

Sleep needs to be shorter - 1 second is a long time in a test

def openclose(filepath):
handler = filepath.open(encoding="UTF-8")
time.sleep(1)
handler.close()
Copy link
Member

Choose a reason for hiding this comment

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

The close should be in a try:finally to ensure that if other parts of the process fail, the file will still be closed.

rename_thread = threading.Thread(
target=mock_tools.files.path_rename,
args=(tmp_path / "orig-dir-1", tmp_path / "new-dir-1"),
)
Copy link
Member

Choose a reason for hiding this comment

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

Is the rename thread needed? It should be possible to do this inline.

file_access_thread.start()
rename_thread.start()

rename_thread.join()
Copy link
Member

Choose a reason for hiding this comment

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

We should join on the file_access_thread to ensure that it cleans up.



@pytest.mark.xfail(
sys.platform == "win32",
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little concerned about this being a win32 only error. macOS and Linux won't fail because of a file rename, but they could fail for other reasons - we need to verify the "will eventually fail" path on all platforms.


Windows does not like renaming a dir in a path with an opened file.
"""
old_path.rename(new_path)
Copy link
Member

Choose a reason for hiding this comment

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

If this is a "retry on any error" handler - what happens for predictable failure - e.g., attempting to rename a file that doesn't exist? There are some failures that should be surfaced immediately.

@spa51273
Copy link
Contributor Author

Russell / Russell and Malcom,
Thanks so much for all your patience and guidance!

I will address all the above on this PR this weekend or early next week. Hope it's not too late. Work got backlogged for the past 7 days and unfortunately I'll need to catch up with it first...

@rmartin16
Copy link
Member

Just FYI: I ended up implementing the File tool in #1871; this will save you some work in this PR but you will first either need to rebase what's here on main or merge main in to update it. Feel free to let us know if you run in to issues or have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants