Esempio n. 1
0
def format_for_columns(pkgs, options):
    """
    Convert the package data into something usable
    by output_package_listing_columns.
    """
    running_outdated = options.outdated
    # Adjust the header for the `pip list --outdated` case.
    if running_outdated:
        header = ["Package", "Version", "Latest", "Type"]
    else:
        header = ["Package", "Version"]

    data = []
    if any(dist_is_editable(x) for x in pkgs):
        header.append("Location")

    for proj in pkgs:
        # if we're working on the 'outdated' list, separate out the
        # latest_version and type
        row = [proj.project_name, proj.version]

        if running_outdated:
            row.append(proj.latest_version)
            row.append(proj.latest_filetype)

        if dist_is_editable(proj):
            row.append(proj.location)

        data.append(row)

    return data, header
Esempio n. 2
0
File: freeze.py Progetto: zsmjwk/pip
 def from_dist(cls, dist, dependency_links):
     location = os.path.normcase(os.path.abspath(dist.location))
     comments = []
     from pip.vcs import vcs, get_src_requirement
     if dist_is_editable(dist) and vcs.get_backend_name(location):
         editable = True
         try:
             req = get_src_requirement(dist, location)
         except InstallationError as exc:
             logger.warning(
                 "Error when trying to get requirement for VCS system %s, "
                 "falling back to uneditable format", exc)
             req = None
         if req is None:
             logger.warning('Could not determine repository location of %s',
                            location)
             comments.append(
                 '## !! Could not determine repository location')
             req = dist.as_requirement()
             editable = False
     else:
         editable = False
         req = dist.as_requirement()
         specs = req.specs
         assert len(specs) == 1 and specs[0][0] in ["==", "==="], \
             'Expected 1 spec with == or ===; specs = %r; dist = %r' % \
             (specs, dist)
         version = specs[0][1]
         ver_match = cls._rev_re.search(version)
         date_match = cls._date_re.search(version)
         if ver_match or date_match:
             svn_backend = vcs.get_backend('svn')
             if svn_backend:
                 svn_location = svn_backend().get_location(
                     dist,
                     dependency_links,
                 )
             if not svn_location:
                 logger.warning('Warning: cannot find svn location for %s',
                                req)
                 comments.append(
                     '## FIXME: could not find svn URL in dependency_links '
                     'for this package:')
             else:
                 warnings.warn(
                     "SVN editable detection based on dependency links "
                     "will be dropped in the future.",
                     RemovedInPip11Warning,
                 )
                 comments.append(
                     '# Installing as editable to satisfy requirement %s:' %
                     req)
                 if ver_match:
                     rev = ver_match.group(1)
                 else:
                     rev = '{%s}' % date_match.group(1)
                 editable = True
                 req = '%s@%s#egg=%s' % (svn_location, rev,
                                         cls.egg_name(dist))
     return cls(dist.project_name, req, editable, comments)
Esempio n. 3
0
    def output_legacy(self, dist):
        # RED Brick patch begin
        summary = ''
        try:
            pkg_info_string = dist.get_metadata("PKG-INFO")
            pkg_info_lines = pkg_info_string.split("\n")
            for line in pkg_info_lines:
                line_split_array = line.split("Summary:")
                if len(line_split_array) == 2:
                    summary = line_split_array[1]
        except:
            pass

        return '{0}<==>{1}<==>{2}'.format(dist.project_name, dist.version,
                                          summary.strip())
        # RED Brick patch end

        if dist_is_editable(dist):
            return '%s (%s, %s)' % (
                dist.project_name,
                dist.version,
                dist.location,
            )
        else:
            return '%s (%s)' % (dist.project_name, dist.version)
Esempio n. 4
0
File: list.py Progetto: ADA110/Cibus
 def output_package(self, dist):
     if dist_is_editable(dist):
         return '%s (%s, %s)' % (
             dist.project_name,
             dist.version,
             dist.location,
         )
     else:
         return '%s (%s)' % (dist.project_name, dist.version)
Esempio n. 5
0
File: list.py Progetto: rwols/pip
 def output_legacy(self, dist, options):
     if options.verbose >= 1 or dist_is_editable(dist):
         return '%s (%s, %s)' % (
             dist.project_name,
             dist.version,
             dist.location,
         )
     else:
         return '%s (%s)' % (dist.project_name, dist.version)
Esempio n. 6
0
File: list.py Progetto: biya-bi/gps
 def output_legacy(self, dist):
     if dist_is_editable(dist):
         return '%s (%s, %s)' % (
             dist.project_name,
             dist.version,
             dist.product,
         )
     else:
         return '%s (%s)' % (dist.project_name, dist.version)
Esempio n. 7
0
def is_installed_editable(pip_module_info):
    """Returns whether a pip installed module was installed editable."""
    # https://stackoverflow.com/questions/40530000
    try:
        from pip.utils import dist_is_editable
    except ModuleNotFoundError:
        from pip._internal.utils.misc import dist_is_editable

    return dist_is_editable(pip_module_info)
Esempio n. 8
0
 def __pretty_version__(self):
     from topicexplorer.update import get_dist
     from pip.utils import dist_is_editable
     dist = get_dist('topicexplorer')
     __pv__ = None
     if dist_is_editable(dist):
         import subprocess
         __pv__ = subprocess.check_output(
             'git describe --long --tags --always --dirty',
             cwd=dist.location,
             shell=True)
         __pv__ = __pv__.strip()
     return __pv__ or self.__version__
Esempio n. 9
0
 def output_package_listing(self, installed_packages):
     installed_packages = sorted(
         installed_packages,
         key=lambda dist: dist.project_name.lower(),
     )
     for dist in installed_packages:
         if dist_is_editable(dist):
             line = '%s (%s, %s)' % (
                 dist.project_name,
                 dist.version,
                 dist.location,
             )
         else:
             line = '%s (%s)' % (dist.project_name, dist.version)
         logger.info(line)
Esempio n. 10
0
def format_for_columns(pkgs, options):
    """
    Convert the package data into something usable
    by output_package_listing_columns.
    """
    header = ["Package", "Version"]
    running_outdated = False
    # Adjust the header for the `pip list --outdated` case.
    if isinstance(pkgs[0], (list, tuple)):
        running_outdated = True
        header = ["Package", "Version", "Latest", "Type"]

    data = []
    if any(
            dist_is_editable(x[0]) if running_outdated else dist_is_editable(x)
            for x in pkgs):
        header.append("Location")

    for proj in pkgs:
        # if we're working on the 'outdated' list, separate out the
        # latest_version and type
        if running_outdated:
            proj, latest_version, typ = proj

        row = [proj.project_name, proj.version]

        if running_outdated:
            row.append(latest_version)
            row.append(typ)

        if dist_is_editable(proj):
            row.append(proj.location)

        data.append(row)

    return data, header
Esempio n. 11
0
def update(args=None):
    from pip.utils import (get_installed_version, dist_is_editable,
                           dist_location)

    import platform
    import subprocess
    from subprocess import CalledProcessError

    dist = get_dist('topicexplorer')

    if dist_is_editable(dist):  # pragma: no cover
        print(
            "You have an editable install, so updates will be pulled from git."
        )
        print("Your install directory is: {}\n".format(dist.location))
        for attempt in range(2):
            try:
                import git
                from git.exc import InvalidGitRepositoryError
                break
            except ImportError:
                install = input(
                    "GitPython is required, but is not installed. Install? [Y/n] "
                )
                if install == '' or install.lower()[0] == 'y':
                    subprocess.check_call('pip install gitpython', shell=True)
                    # TODO: Add error handling for failed gitpython install
                    # Refresh local python path to reflect gitpython
                    import site
                    reload(site)

                    # attempt import once again
                    import git
                    reload(git)
                    from git.exc import InvalidGitRepositoryError
        else:
            print("GitPython is required to work with an editable install,")
            print("but it was not successfully installed.\n")
            return

        try:
            repo = git.Repo(dist.location)
        except InvalidGitRepositoryError:
            print(
                "pip has detected an editable install, but the install directory"
            )
            print("is not a valid git repository.\n")
            return

        if repo.is_dirty():
            print("There are uncommitted changes in your local repository.")
            print("Please commit before running `topicexplorer update`.\n")
            return

        if repo.active_branch != repo.heads.master:
            print("You are on the '{}' branch.".format(repo.active_branch),
                  end=' ')
            install = input("Switch to the 'master' branch? [Y/n] ")
            if install == '' or install.lower()[0] == 'y':
                print("Switched to 'master' branch.")
                repo.heads.master.checkout()
            else:
                print(
                    "You must switch to the 'master' branch to use `topicexplorer update`."
                )
                return

        if not repo.bare:
            # check for upstream updates
            branch = repo.active_branch
            repo.remotes.origin.fetch(branch)
            commits_behind = list(
                repo.iter_commits(
                    '{BRANCH}..origin/{BRANCH}'.format(BRANCH=branch.name)))
            commits_ahead = list(
                repo.iter_commits(
                    'origin/{BRANCH}..{BRANCH}'.format(BRANCH=branch.name)))
            if commits_behind:
                print("Your branch is {} commits behind GitHub.".format(
                    len(commits_behind)))
                if platform.system() == 'Windows':  # pragma: no cover
                    import sys
                    if sys.argv[0] != __file__:
                        print(
                            "Use the `python -m topicexplorer.update` command to update."
                        )
                        return

                    # TODO: remove process_exists('vsm.exe') on 1.0rc1
                    if process_exists('topicexplorer.exe') or process_exists(
                            'vsm.exe'):
                        print("vsm is currently running,", end=' ')
                        print("please close all Topic Explorers to update.")
                        return

                print("Pulling changes.")
                repo.remotes.origin.pull()
                # reinstall, just in case dependencies or version have updated
                try:
                    subprocess.check_call('python setup.py develop',
                                          cwd=dist.location,
                                          shell=True)
                except:
                    print("ERROR: Update did not comlete installation.\n")
                else:
                    print("Your local branch was updated.\n")

            elif commits_ahead:
                print("Your branch is {} commits ahead of GitHub.".format(
                    len(commits_ahead)))
                push = input("Do you want to push? [Y/n] ")
                if push == '' or push.lower()[0] == 'y':
                    repo.remotes.origin.push()
            else:
                print(
                    "Your local branch is synced with GitHub. No updates available.\n"
                )

    else:
        # TODO: Check if pre-release, if so, then continue beta updates.
        # If not, then wait for stable release. Allow for override flag.
        from pip._vendor.packaging.version import parse as parse_version

        installed_version = parse_version(
            get_installed_version('topicexplorer'))
        pypi_version = parse_version(pypi_versions('topicexplorer')[-1])
        update_available = pypi_version > installed_version

        if update_available:
            if platform.system() == 'Windows':  # pragma: no cover
                import sys
                if sys.argv[0] != __file__:
                    print(
                        "Update available. Use the `python -m topicexplorer.update`",
                        end=' ')
                    print("command to update.")
                    return
                # TODO: remove process_exists('vsm.exe') on 1.0rc1
                if process_exists('topicexplorer.exe') or process_exists(
                        'vsm.exe'):
                    print(
                        "topicexplorer is currently running, please close all Topic Explorers to update."
                    )
                    return

            try:
                subprocess.check_call(
                    'pip install topicexplorer=={} --no-cache-dir'.format(
                        pypi_version),
                    shell=True)
            except CalledProcessError:
                print("ERROR: Update did not comlete installation.\n")
            else:
                print("Updated from {} to {}.\n".format(
                    installed_version, pypi_version))
        else:
            print("You have the most recent release. No updates available.\n")