@task
@timed
def uninstall_python_packages():
 hasher = hashlib.sha1()
 hasher.update(repr(PACKAGES_TO_UNINSTALL))
 expected_version = hasher.hexdigest()
 state_file_path = os.path.join(PREREQS_STATE_DIR, 'Python_uninstall.sha1')
 create_prereqs_cache_dir()
 if os.path.isfile(state_file_path):
  with open(state_file_path) as state_file:
   version = state_file.read()
  if (version == expected_version):
   print 'Python uninstalls unchanged, skipping...'
   return
 for _ in range(3):
  uninstalled = False
  frozen = sh('pip freeze', capture=True)
  for package_name in PACKAGES_TO_UNINSTALL:
   if package_in_frozen(package_name, frozen):
    sh('pip uninstall --disable-pip-version-check -y {}'.format(package_name))
    uninstalled = True
  if (not uninstalled):
   break
 else:
  print "Couldn't uninstall unwanted Python packages!"
  return
 with open(state_file_path, 'w') as state_file:
  state_file.write(expected_version)

@ task @ timed def uninstall_python_packages ( ) : hasher = hashlib . sha1 ( ) hasher . update ( repr ( PACKAGES_TO_UNINSTALL ) ) expected_version = hasher . hexdigest ( ) state_file_path = os . path . join ( PREREQS_STATE_DIR , 'Python_uninstall.sha1' ) create_prereqs_cache_dir ( ) if os . path . isfile ( state_file_path ) : with open ( state_file_path ) as state_file : version = state_file . read ( ) if ( version == expected_version ) : print 'Python uninstalls unchanged, skipping...' return for _ in range ( 3 ) : uninstalled = False frozen = sh ( 'pip freeze' , capture = True ) for package_name in PACKAGES_TO_UNINSTALL : if package_in_frozen ( package_name , frozen ) : sh ( 'pip uninstall --disable-pip-version-check -y {}' . format ( package_name ) ) uninstalled = True if ( not uninstalled ) : break else : print "Couldn't uninstall unwanted Python packages!" return with open ( state_file_path , 'w' ) as state_file : state_file . write ( expected_version )
uninstall python packages that need explicit uninstallation .