-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Account for symlinked .venv when removing #3375
Conversation
|
||
def err_on_rm_venv_only(path, *args, **kwargs): | ||
if path == str(venv_path): | ||
raise OSError(20, "Test error") # ERRNO 16: Device or resource busy |
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.
Looks like this comment is incorrect.
raise e | ||
|
||
# Delete all files and folders but the toplevel one. This is because sometimes | ||
# the venv folder is mounted by the OS, such as in a docker volume. In such | ||
# the venv folder is mounted or symlinked by the OS, such as in a docker volume, codebuild, etc. In such |
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.
Please reformat this comment block to have a uniform width.
@@ -834,13 +834,16 @@ def remove_venv(cls, path): # type: (Union[Path,str]) -> None | |||
return | |||
except OSError as e: | |||
# Continue only if e.errno == 16 | |||
if e.errno != 16: # ERRNO 16: Device or resource busy | |||
if ( |
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'd like to see the errno
module's named constants used here. A construct like e.errno in {errno.ENOTDIR, errno.EBUSY}
would be more obvious and maintainable.
@@ -834,13 +834,16 @@ def remove_venv(cls, path): # type: (Union[Path,str]) -> None | |||
return | |||
except OSError as e: | |||
# Continue only if e.errno == 16 |
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.
Out of date comment
# cases, an attempt to delete the folder itself will result in an `OSError`. | ||
# See https://github.com/python-poetry/poetry/pull/2064 | ||
# See https://bugs.python.org/issue1669 |
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 don't think this issue is relevant -- it describes a bug that is long-resolved, and not the behavior of throwing an exception when called on a symlink.
@@ -619,6 +621,55 @@ def err_on_rm_venv_only(path, *args, **kwargs): | |||
m.side_effect = original_rmtree # Avoid teardown using `err_on_rm_venv_only` | |||
|
|||
|
|||
def test_remove_keeps_dir_if_not_deleteable_os_err_20( |
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.
Let's parameterize this whole test for different errno
constants instead of doing this copy-and-paste.
Stale. Closing as this has not had any activity for a while, and the error the change attempts to fix is no longer reproducible. |
Pull Request Check List
Resolves: Sometimes the
.venv
is a symlink, such as in caching strategies for CI/CD environments (codebuild, etc)Related: #2064
We are already asserting the file path is a directory, so if OS Error 20 is triggered, which is "Not a directory" we simply delete everything but the top level folder.