From: Andrew Svetlov Date: Fri, 24 Aug 2012 16:00:15 +0000 (+0300) Subject: Issue #15776: Allow pyvenv to work in existing directory with --clean. X-Git-Tag: v3.3.0rc1~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82649f3b873f470941d5226802dd3c0e45221173;p=python Issue #15776: Allow pyvenv to work in existing directory with --clean. Patch by Vinay Sajip. --- diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 8d2deb7385..3553fecb89 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] diff --git a/Misc/NEWS b/Misc/NEWS index 227f2acc88..57f022c048 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -29,6 +29,8 @@ Core and Builtins Library ------- +- Issue #15776: Allow pyvenv to work in existing directory with --clean. + - Issue #15249: BytesGenerator now correctly mangles From lines (when requested) even if the body contains undecodable bytes.