summaryrefslogtreecommitdiffstats
path: root/Lib/venv
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-08-24 16:00:15 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-08-24 16:00:15 (GMT)
commit82649f3b873f470941d5226802dd3c0e45221173 (patch)
treeed70fcf6488fd2570a322b3d61148ab92425a9ef /Lib/venv
parentad2a7d528acbb94bd4def418201d808226cb9f38 (diff)
downloadcpython-82649f3b873f470941d5226802dd3c0e45221173.zip
cpython-82649f3b873f470941d5226802dd3c0e45221173.tar.gz
cpython-82649f3b873f470941d5226802dd3c0e45221173.tar.bz2
Issue #15776: Allow pyvenv to work in existing directory with --clean.
Patch by Vinay Sajip.
Diffstat (limited to 'Lib/venv')
-rw-r--r--Lib/venv/__init__.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 8d2deb7..3553fec 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -105,7 +105,15 @@ class EnvBuilder:
if os.path.exists(env_dir) and not (self.clear or self.upgrade):
raise ValueError('Directory exists: %s' % env_dir)
if os.path.exists(env_dir) and self.clear:
- shutil.rmtree(env_dir)
+ # Issue 15776: To support running pyvenv on '.', the venv
+ # directory contents are emptied and recreated, instead of
+ # the venv directory being deleted and recreated.
+ for f in os.listdir(env_dir):
+ f = os.path.join(env_dir, f)
+ if os.path.isdir(f):
+ shutil.rmtree(f)
+ else:
+ os.remove(f)
context = Context()
context.env_dir = env_dir
context.env_name = os.path.split(env_dir)[1]