#!/usr/bin/env python3
from subprocess import call

try:
    import pkg_resources
except ImportError as err:
    import sys

    print(err)
    sys.exit(1)

IGNORE_PACKAGES = {"pip", "setuptools", "wheel"}


def colorcode(code: int) -> str:
    return "\033[" + str(code) + "m"


GREEN = colorcode(32)
BOLD = colorcode(1)
RESET = colorcode(0)


print(f"{BOLD}==> Collecting packages...{RESET}")
packages = [dist.project_name for dist in pkg_resources.working_set]
print(f"{GREEN}✓ Collected {len(packages)} packages.{RESET}")

for pkg in packages:
    print(f"\n{BOLD}==> Uninstalling {pkg}...{RESET}")
    if pkg in IGNORE_PACKAGES:
        print(f"\n{GREEN}Skipping {pkg}...{RESET}")
        continue
    call(f"pip uninstall --yes {pkg}", shell=True)
