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

Account for symlinked .venv when removing #3375

Closed
wants to merge 1 commit into from

Conversation

vibe
Copy link

@vibe vibe commented Nov 18, 2020

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.

  • [ X] Added tests for changed code.
  • [ X] Updated documentation for changed code.

@finswimmer finswimmer requested a review from a team November 18, 2020 07:24

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
Copy link
Member

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
Copy link
Member

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 (
Copy link
Member

@neersighted neersighted Nov 14, 2021

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
Copy link
Member

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
Copy link
Member

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(
Copy link
Member

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.

@neersighted neersighted self-assigned this Nov 14, 2021
@abn
Copy link
Member

abn commented Jan 17, 2025

Stale. Closing as this has not had any activity for a while, and the error the change attempts to fix is no longer reproducible.

@abn abn closed this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants