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

Guard against deletion of the current environment #1327

Open
zanieb opened this issue Feb 15, 2024 · 5 comments
Open

Guard against deletion of the current environment #1327

zanieb opened this issue Feb 15, 2024 · 5 comments
Labels
bug Something isn't working windows Specific to the Windows platform

Comments

@zanieb
Copy link
Member

zanieb commented Feb 15, 2024

For example, uv venv will happily clear the current virtual environment.

This is most notably an issue when uv is installed in that environment.

@MichaReiser
Copy link
Member

This also an issue on Windows where the operation fails.

uv venv
Using Python 3.12.2 interpreter at C:\Users\Micha\AppData\Local\Programs\Python\Python312\python.exe
Creating virtualenv at: .venv
uv::venv::creation

  × Failed to create virtualenv
  ├─▶ failed to remove directory `.venv`
  ╰─▶ Access is denied. (os error 5)

@charliermarsh charliermarsh added bug Something isn't working windows Specific to the Windows platform labels Feb 15, 2024
@charliermarsh
Copy link
Member

@gaborbernat -- just curious, do virtualenv do anything special here (e.g., if you try to create a virtualenv with --clear, and the virtualenv.exe you're running is in the directory that needs to be removed)?

@gaborbernat
Copy link
Contributor

@charliermarsh
Copy link
Member

Thanks!

@bersbersbers
Copy link

Here's another/similar issue regarding uv trying to delete the current environment. I think the main issue is the mismatch between some leftover .python-version that I had and the (new) .venv. But ideally, uv would be smart enough to detect that it is currently running from said .venv, and should not try deleting it.

bug.bat:

@echo off
if not exist c:\ws\bug mkdir c:\ws\bug
pushd c:\ws\bug

if exist .venv rmdir .venv /s/q
echo 3.12.3 > .python-version
echo [project] > pyproject.toml
echo name = "Bug" >> pyproject.toml
echo version = "1" >> pyproject.toml

python -m venv .venv
call .venv\scripts\activate

pip install uv
uv sync --verbose

pause

Output:

Collecting uv
  Using cached uv-0.4.20-py3-none-win_amd64.whl.metadata (11 kB)
Using cached uv-0.4.20-py3-none-win_amd64.whl (14.2 MB)
Installing collected packages: uv
Successfully installed uv-0.4.20
DEBUG uv 0.4.20
DEBUG Found project root: `c:\ws\bug`
DEBUG No workspace root found, using project root
DEBUG Reading requests from `c:\ws\bug\.python-version`
DEBUG The virtual environment's Python version does not satisfy `Python 3.12.3`
DEBUG Searching for Python 3.12.3 in managed installations, system path, or `py` launcher
DEBUG Searching for managed installations at `C:\Users\bers\AppData\Roaming\uv\python`
DEBUG Found managed installation `cpython-3.12.3-windows-x86_64-none`
DEBUG Found `cpython-3.12.3-windows-x86_64-none` at `C:\Users\bers\AppData\Roaming\uv\python\cpython-3.12.3-windows-x86_64-none\python.exe` (managed installations)
Using CPython 3.12.3
error: failed to remove directory `c:\ws\bug\.venv`
  Caused by: Access is denied. (os error 5)
Press any key to continue . . .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

No branches or pull requests

5 participants