def do_patch_activate_script(venv_path):
 script_path = os.path.join(venv_path, 'bin', 'activate')
 file_obj = open(script_path)
 lines = file_obj.readlines()
 for (i, line) in enumerate(lines):
  if line.startswith('VIRTUAL_ENV='):
   lines[i] = ('VIRTUAL_ENV="%s"\n' % (venv_path,))
 file_obj.close()
 file_obj = open(script_path, 'w')
 file_obj.write(''.join(lines))
 file_obj.close()

def do_patch_activate_script ( venv_path ) : script_path = os . path . join ( venv_path , 'bin' , 'activate' ) file_obj = open ( script_path ) lines = file_obj . readlines ( ) for ( i , line ) in enumerate ( lines ) : if line . startswith ( 'VIRTUAL_ENV=' ) : lines [ i ] = ( 'VIRTUAL_ENV="%s"\n' % ( venv_path , ) ) file_obj . close ( ) file_obj = open ( script_path , 'w' ) file_obj . write ( '' . join ( lines ) ) file_obj . close ( )
patches the bin/activate script so that the value of the environment variable virtual_env is set to venv_path during the scripts execution whenever it is sourced .