Provide better error message for activate_this.py

Ref #2257.
This commit is contained in:
Tzu-ping Chung
2018-05-25 17:42:06 +09:00
parent 9550056344
commit 2fc28bcc0a
+8
View File
@@ -2226,6 +2226,14 @@ def do_shell(three=None, python=False, fancy=False, shell_args=None):
def inline_activate_virtualenv():
try:
activate_this = which('activate_this.py')
if not activate_this or not os.path.exists(activate_this):
click.echo(
u'{0}: activate_this.py not found. Your environment is most '
u'certainly not activated. Continuing anyway…'
u''.format(crayons.red('Warning', bold=True)),
err=True,
)
return
with open(activate_this) as f:
code = compile(f.read(), activate_this, 'exec')
exec(code, dict(__file__=activate_this))