Skip to content

Account for symlinked .venv when removing#3375

Closed
vibe wants to merge 1 commit into
python-poetry:mainfrom
vibe:master
Closed

Account for symlinked .venv when removing#3375
vibe wants to merge 1 commit into
python-poetry:mainfrom
vibe:master

Conversation

@vibe
Copy link
Copy Markdown

@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
Comment thread tests/utils/test_env.py

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
Copy Markdown
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.

Comment thread poetry/utils/env.py

# 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
Copy Markdown
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.

Comment thread poetry/utils/env.py
except OSError as e:
# Continue only if e.errno == 16
if e.errno != 16: # ERRNO 16: Device or resource busy
if (
Copy link
Copy Markdown
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.

Comment thread poetry/utils/env.py
@@ -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
Copy Markdown
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

Comment thread poetry/utils/env.py
# the venv folder is mounted or symlinked by the OS, such as in a docker volume, codebuild, etc. In such
# 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
Copy Markdown
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.

Comment thread tests/utils/test_env.py
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
Copy Markdown
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
Copy Markdown
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
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants