[New-bugs-announce] [issue46326] 'virtualenv --clear' should prompt user before nuking entire directory

Ali Mohammad Pur report at bugs.python.org
Mon Jan 10 04:01:46 EST 2022

New submission from Ali Mohammad Pur <Ali.mpfard at gmail.com>:

`virtualenv --clear` is extremely eager to delete the passed directory without
any sort of confirmation, leading to possible data-loss
(e.g. with a mistyped command, or a misunderstanding of what it actually does).

Simply deleting an entire directory tree with a command that's extremely
prone to misunderstanding should not be virtualenv's job, but as it has
decided to make this its job, then it should take proper precautions to avoid
unintentional `rm -fr some-directory` by *at least* asking for confirmation.
The previous behaviour can of course, stay behind a `--force` flag for uses in
CI or similar, but this should *not* be the default behaviour.

related: https://github.com/pypa/virtualenv/issues/1890 mentions that
"[it is not] good practice to put non-virtual environment-related files into a
virtual environment", which is sensible, and so virtualenv should then simply
refuse to be instantiated in a non-empty directory.

On a more subjetive note, `virtualenv --clear <dir>` sounds like a way to purge the virtual environment files from a directory (yes, I understand what the help says, but that hardly changes anything), so perhaps a more verbose flag like "--clear-contents" would be more appropriate, but I digress.

messages: 410192
nosy: alimpfard
priority: normal
severity: normal
status: open
title: 'virtualenv --clear' should prompt user before nuking entire directory
type: behavior

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list