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

VirtualenvCreateError: checking for .venv existence rather than emptiness #2270

Closed
1 task done
dennispg opened this issue Sep 20, 2023 · 1 comment
Closed
1 task done
Labels
🐛 bug Something isn't working

Comments

@dennispg
Copy link
Contributor

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

I am mounting a docker volume in my devcontainer at <project path>/.venv to try and cache the virtual environments between rebuilds, and then running pdm venv create in my project. I also have venv.in_project set to true in pdm.toml.

Actual behavior

[VirtualenvCreateError]: The location /<project path>/.venv is not empty, add --force to overwrite it.

Adding --force gives:

Cleaning existing target directory /<project path>/.venv
[OSError]: [Errno 16] Device or resource busy: '/<project path>/.venv'
Add '-v' to see the detailed traceback

Expected behavior

The .venv volume is in fact empty, however pdm is looking for existence rather than empty and since the volume mount cannot be deleted, it fails.

Can _ensure_clean instead check that the directory is empty and be done with it?

https://github.com/pdm-project/pdm/blob/main/src/pdm/cli/commands/venv/backends.py#L81

Adding this seems to resolve it for me:

        if location.is_dir() and not any(location.iterdir()):
            return

I can make a pull request to that effect if its deemed appropriate?

Environment Information

PDM version:
  2.9.2
{
  "implementation_name": "cpython",
  "implementation_version": "3.11.5",
  "os_name": "posix",
  "platform_machine": "aarch64",
  "platform_release": "6.4.16-orbstack-00103-g02b40eb69695",
  "platform_system": "Linux",
  "platform_version": "#1 SMP Wed Sep 13 10:13:30 UTC 2023",
  "python_full_version": "3.11.5",
  "platform_python_implementation": "CPython",
  "python_version": "3.11",
  "sys_platform": "linux"
}
@dennispg dennispg added the 🐛 bug Something isn't working label Sep 20, 2023
@dennispg dennispg changed the title VirtualenvCreateError: checking for .venv existence rather emptiness VirtualenvCreateError: checking for .venv existence rather than emptiness Sep 20, 2023
@dennispg
Copy link
Contributor Author

Here's my full patch:

3a4
> import os
73a75,76
>         if location.is_dir() and not any(location.iterdir()):
>             return
81c84,90
<             shutil.rmtree(location)
---
>             self.project.core.ui.echo("Dennis code here")
>             with os.scandir(location) as entries:
>                 for entry in entries:
>                     if entry.is_dir() and not entry.is_symlink():
>                         shutil.rmtree(entry.path)
>                     else:
>                         os.remove(entry.path)

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

No branches or pull requests

2 participants