Exemple #1
0
def check(force, verbose, packages):
    """
    Check whether specified packages need an upgrade
    """
    code = 0
    packages = system.resolved_package_specs(packages, auto_complete=True)
    if not packages:
        print("No packages installed")

    else:
        for name in packages:
            p = PACKAGERS.resolved(name)
            p.refresh_desired(force=force)
            if not p.desired.valid:
                LOG.error(p.desired.representation(verbose))
                code = 1
            elif not p.current.version or not p.current.valid:
                print(
                    p.desired.representation(verbose, note="is not installed"))
                code = 1
            elif p.current.version != p.desired.version:
                print(
                    p.current.representation(verbose,
                                             note="can be upgraded to %s" %
                                             p.desired.version))
                code = 1
            else:
                print(p.current.representation(verbose, note="is installed"))

    sys.exit(code)
Exemple #2
0
def install(force, packages):
    """
    Install a package from pypi
    """
    system.setup_audit_log()
    packages = system.resolved_package_specs(packages)
    for name in packages:
        p = PACKAGERS.resolved(name)
        p.install(force=force)
Exemple #3
0
def list(verbose):
    """
    List installed packages
    """
    packages = system.resolved_package_specs(None, auto_complete=True)
    if not packages:
        print("No packages installed")

    else:
        for name in packages:
            p = PACKAGERS.resolved(name)
            print(p.current.representation(verbose))
Exemple #4
0
def check_specs(text, expected):
    packages = system.resolved_package_specs(text)
    names = [p.dashed for p in packages]
    assert names == expected
Exemple #5
0
def uninstall(all, force, packages):
    """
    Uninstall packages
    """
    if packages and all:
        sys.exit(
            "Either specify packages to uninstall, or --all (but not both)")

    if not packages and not all:
        sys.exit("Specify packages to uninstall, or --all")

    if packages and system.PICKLEY in packages:
        sys.exit(
            "Run 'uninstall --all' if you wish to uninstall pickley itself (and everything it installed)"
        )

    system.setup_audit_log()
    package_specs = system.resolved_package_specs(packages, auto_complete=all)
    errors = 0
    for package_spec in package_specs:
        p = PACKAGERS.resolved(package_spec)
        if not force and not p.current.file_exists:
            errors += 1
            LOG.error("%s was not installed with pickley", package_spec)
            continue

        eps = p.entry_points
        ep_uninstalled = 0
        ep_missed = 0
        meta_deleted = runez.delete(system.SETTINGS.meta.full_path(
            package_spec.dashed),
                                    fatal=False)
        if not eps and force:
            eps = {package_spec.dashed: ""}
        if eps and meta_deleted >= 0:
            for entry_point in eps:
                path = system.SETTINGS.base.full_path(entry_point)
                handler = runez.delete if meta_deleted > 0 else uninstall_existing
                r = handler(path, fatal=False)
                if r < 0:
                    ep_missed += 1
                elif r > 0:
                    ep_uninstalled += 1

        if ep_missed or meta_deleted < 0:
            # Error was already reported
            errors += 1
            continue

        if ep_uninstalled + meta_deleted == 0:
            system.inform("Nothing to uninstall for %s" % package_spec)
            continue

        message = "Would uninstall" if runez.DRYRUN else "Uninstalled"
        message = "%s %s" % (message, package_spec)
        if ep_uninstalled > 1:
            message += " (%s entry points)" % ep_uninstalled
        system.inform(message)

    if all and not errors:
        runez.delete(system.SETTINGS.meta.path)

    if errors:
        sys.exit(1)