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 options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): header.append("Location") if options.verbose >= 1: header.append("Installer") 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 options.verbose >= 1 or dist_is_editable(proj): row.append(proj.location) if options.verbose >= 1: row.append(get_installer(proj)) data.append(row) return data, header
def format_for_columns(pkgs, options): """ Convert the package data into something usable by output_package_listing_columns. """ running_outdated = options.outdated running_columnsx = True if options.list_format == 'columnsx' else False # Adjust the header for the `pip list --outdated` case. running_showlatest = False header = ["Package", "Version"] if running_outdated: header.append("Latest") header.append("Type") running_showlatest = True data = [] if options.verbose >= 1 or any(dist_is_editable(x) for x in pkgs): header.append("Location") if options.verbose >= 1 or running_columnsx: header.append("Installer") dct = rdCndGetNames() if running_columnsx else {} nLngDct = len(dct) if (nLngDct > 1): # dct may be empty on Python without Anaconda header.append("Owner") 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 options.verbose >= 1 or dist_is_editable(proj): row.append(proj.location) if options.verbose >= 1 or running_columnsx: row.append(get_installer(proj)) if (nLngDct > 1): if rdCndIsNameIn(dct, proj.project_name): row.append("Anaconda") else: row.append("ThePip") data.append(row) return data, header
def _init_args_from_dist(cls, dist, dependency_links): """ Compute and return arguments (req, editable, comments) to pass to FrozenRequirement.__init__(). This method is for use in FrozenRequirement.from_dist(). """ location = os.path.normcase(os.path.abspath(dist.location)) from pip._internal.vcs import vcs, get_src_requirement if not dist_is_editable(dist): req = dist.as_requirement() return (req, False, []) vc_type = vcs.get_backend_type(location) if not vc_type: req = dist.as_requirement() return (req, False, []) try: req = get_src_requirement(vc_type, dist, location) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc) else: if req is not None: return (req, True, []) logger.warning('Could not determine repository location of %s', location) comments = ['## !! Could not determine repository location'] req = dist.as_requirement() return (req, False, comments)
def from_dist(cls, dist, dependency_links): location = os.path.normcase(os.path.abspath(dist.location)) comments = [] from pip._internal.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' % \ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
def get_requirement_info(dist): # type: (Distribution) -> RequirementInfo """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, []) location = os.path.normcase(os.path.abspath(dist.location)) from pip._internal.vcs import vcs, RemoteNotFoundError vc_type = vcs.get_backend_type(location) if not vc_type: req = dist.as_requirement() logger.debug( 'No VCS found for editable requirement {!r} in: {!r}', req, location, ) comments = [ '# Editable install with no version control ({})'.format(req) ] return (location, True, comments) try: req = vc_type.get_src_requirement(location, dist.project_name) except RemoteNotFoundError: req = dist.as_requirement() comments = [ '# Editable {} install with no remote ({})'.format( vc_type.__name__, req, ) ] return (location, True, comments) except BadCommand: logger.warning( 'cannot determine version of editable source in %s ' '(%s command not found in path)', location, vc_type.name, ) return (None, True, []) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc ) else: if req is not None: return (req, True, []) logger.warning( 'Could not determine repository location of %s', location ) comments = ['## !! Could not determine repository location'] return (None, False, comments)
def from_dist(cls, dist, dependency_links): location = os.path.normcase(os.path.abspath(dist.location)) comments = [] from pip._internal.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)
def get_requirement_info(dist): # type: (Distribution) -> RequirementInfo """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, [])
def output_package(dist): """Return string displaying package information.""" if dist_is_editable(dist): return '%s (%s, %s)' % ( dist.project_name, dist.version, dist.location, ) return '%s (%s)' % (dist.project_name, dist.version)
def output_legacy(self, dist, options): if options.verbose >= 1: return "%s (%s, %s, %s)" % ( dist.project_name, dist.version, dist.location, get_installer(dist), ) elif dist_is_editable(dist): return "%s (%s, %s)" % (dist.project_name, dist.version, dist.location) else: return "%s (%s)" % (dist.project_name, dist.version)
def output_legacy(self, dist, options): if options.verbose >= 1: return '%s (%s, %s, %s)' % ( dist.project_name, dist.version, dist.location, get_installer(dist), ) elif dist_is_editable(dist): return '%s (%s, %s)' % ( dist.project_name, dist.version, dist.location, ) else: return '%s (%s)' % (dist.project_name, dist.version)
def get_requirement_info(dist): """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, []) location = os.path.normcase(os.path.abspath(dist.location)) from pip._internal.vcs import vcs vc_type = vcs.get_backend_type(location) if not vc_type: return (None, False, []) try: req = vc_type().get_src_requirement(dist, location) except BadCommand: logger.warning( 'cannot determine version of editable source in %s ' '(%s command not found in path)', location, vc_type.name, ) return (None, True, []) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc ) else: if req is not None: return (req, True, []) logger.warning( 'Could not determine repository location of %s', location ) comments = ['## !! Could not determine repository location'] return (None, False, comments)
def make_package(dist): pkg_info = message_from_string(dist.get_metadata(dist.PKG_INFO)) pkg = { 'key': dist.key, 'name': dist.project_name, 'version': dist.version, 'description': get_pkg_info(pkg_info, 'Summary'), 'license': get_pkg_info(pkg_info, 'License'), 'home_page': get_pkg_info(pkg_info, 'Home-page'), 'is_editable': dist_is_editable(dist), 'in_user_site': dist_in_usersite(dist), 'in_global_site': not dist_is_local(dist), 'requirements': { req.key: str(req.specifier) or None for req in dist.requires() }, 'issues': [], } return pkg
def read_installed(verbose=True): cwd = os.getcwd() if verbose: try: # virtual environment with venv in python 3.3+ from site import getsitepackages site_package_dirs = getsitepackages() except ImportError: # virtual environment with virtualenv # https://github.com/pypa/virtualenv/issues/228 from distutils.sysconfig import get_python_lib site_package_dirs = [get_python_lib()] print('reading installed from:\n\t{}'.format('\n\t'.join( [os.path.relpath(x, cwd) for x in site_package_dirs]))) pkgs = get_installed_distributions() tree = PackageDAG.from_pkgs(pkgs) branch_keys = set(r.key for r in flatten(tree.values())) nodes = [p for p in tree.keys() if p.key not in branch_keys] project_names = set(normalize_package_name(p.project_name) for p in nodes) editable_packages = set( normalize_package_name(p.project_name) for p in nodes if dist_is_editable(p._obj)) return set(project_names), editable_packages, tree
def is_editable(self) -> bool: return dist_is_editable(self.dist)
def from_dist(cls, dist, dependency_links): location = os.path.normcase(os.path.abspath(dist.location)) comments = [] from pip._internal.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)
def get_requirement_info(dist): # type: (Distribution) -> RequirementInfo """ Compute and return values (req, editable, comments) for use in FrozenRequirement.from_dist(). """ if not dist_is_editable(dist): return (None, False, []) location = os.path.normcase(os.path.abspath(dist.location)) from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidError, vcs vcs_backend = vcs.get_backend_for_dir(location) if vcs_backend is None: req = dist.as_requirement() logger.debug( 'No VCS found for editable requirement "%s" in: %r', req, location, ) comments = [f'# Editable install with no version control ({req})'] return (location, True, comments) try: req = vcs_backend.get_src_requirement(location, dist.project_name) except RemoteNotFoundError: req = dist.as_requirement() comments = [ '# Editable {} install with no remote ({})'.format( type(vcs_backend).__name__, req, ) ] return (location, True, comments) except RemoteNotValidError as ex: req = dist.as_requirement() comments = [ f"# Editable {type(vcs_backend).__name__} install ({req}) with " f"either a deleted local remote or invalid URI:", f"# '{ex.url}'", ] return (location, True, comments) except BadCommand: logger.warning( 'cannot determine version of editable source in %s ' '(%s command not found in path)', location, vcs_backend.name, ) return (None, True, []) except InstallationError as exc: logger.warning( "Error when trying to get requirement for VCS system %s, " "falling back to uneditable format", exc) else: return (req, True, []) logger.warning('Could not determine repository location of %s', location) comments = ['## !! Could not determine repository location'] return (None, False, comments)
def is_editable(self): # type: () -> bool return dist_is_editable(self.dist)
def editable(self): # type: () -> bool return misc.dist_is_editable(self._dist)
def update(args=None): try: from pip._internal.utils.misc import (get_installed_version, dist_is_editable, dist_location) except ImportError: 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")
def resolve( self, root_reqs: List[InstallRequirement], check_supported_wheels: bool ) -> RequirementSet: collected = self.factory.collect_root_requirements(root_reqs) provider = PipProvider( factory=self.factory, constraints=collected.constraints, ignore_dependencies=self.ignore_dependencies, upgrade_strategy=self.upgrade_strategy, user_requested=collected.user_requested, ) if "PIP_RESOLVER_DEBUG" in os.environ: reporter: BaseReporter = PipDebuggingReporter() else: reporter = PipReporter() resolver: RLResolver[Requirement, Candidate, str] = RLResolver( provider, reporter, ) try: try_to_avoid_resolution_too_deep = 2000000 result = self._result = resolver.resolve( collected.requirements, max_rounds=try_to_avoid_resolution_too_deep ) except ResolutionImpossible as e: error = self.factory.get_installation_error( cast("ResolutionImpossible[Requirement, Candidate]", e), collected.constraints, ) raise error from e req_set = RequirementSet(check_supported_wheels=check_supported_wheels) for candidate in result.mapping.values(): ireq = candidate.get_install_requirement() if ireq is None: continue # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed. installed_dist = self.factory.get_dist_to_uninstall(candidate) if installed_dist is None: # There is no existing installation -- nothing to uninstall. ireq.should_reinstall = False elif self.factory.force_reinstall: # The --force-reinstall flag is set -- reinstall. ireq.should_reinstall = True elif parse_version(installed_dist.version) != candidate.version: # The installation is different in version -- reinstall. ireq.should_reinstall = True elif candidate.is_editable or dist_is_editable(installed_dist): # The incoming distribution is editable, or different in # editable-ness to installation -- reinstall. ireq.should_reinstall = True elif candidate.source_link and candidate.source_link.is_file: # The incoming distribution is under file:// if candidate.source_link.is_wheel: # is a local wheel -- do nothing. logger.info( "%s is already installed with the same version as the " "provided wheel. Use --force-reinstall to force an " "installation of the wheel.", ireq.name, ) continue looks_like_sdist = ( is_archive_file(candidate.source_link.file_path) and candidate.source_link.ext != ".zip" ) if looks_like_sdist: # is a local sdist -- show a deprecation warning! reason = ( "Source distribution is being reinstalled despite an " "installed package having the same name and version as " "the installed package." ) replacement = "use --force-reinstall" deprecated( reason=reason, replacement=replacement, gone_in="21.2", issue=8711, ) # is a local sdist or path -- reinstall ireq.should_reinstall = True else: continue link = candidate.source_link if link and link.is_yanked: # The reason can contain non-ASCII characters, Unicode # is required for Python 2. msg = ( "The candidate selected for download or install is a " "yanked version: {name!r} candidate (version {version} " "at {link})\nReason for being yanked: {reason}" ).format( name=candidate.name, version=candidate.version, link=link, reason=link.yanked_reason or "<none given>", ) logger.warning(msg) req_set.add_named_requirement(ireq) reqs = req_set.all_requirements self.factory.preparer.prepare_linked_requirements_more(reqs) return req_set
def _init_args_from_dist(cls, dist, dependency_links): """ Compute and return arguments (req, editable, comments) to pass to FrozenRequirement.__init__(). This method is for use in FrozenRequirement.from_dist(). """ location = os.path.normcase(os.path.abspath(dist.location)) comments = [] from pip._internal.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: deprecated( "SVN editable detection based on dependency links " "will be dropped in the future.", replacement=None, gone_in="18.2", issue=4187, ) 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 egg_name = cls.egg_name(dist) req = make_vcs_requirement_url(svn_location, rev, egg_name) return (req, editable, comments)
def resolve(self, root_reqs, check_supported_wheels): # type: (List[InstallRequirement], bool) -> RequirementSet constraints = {} # type: Dict[str, SpecifierSet] user_requested = set() # type: Set[str] requirements = [] for req in root_reqs: if req.constraint: # Ensure we only accept valid constraints problem = check_invalid_constraint_type(req) if problem: raise InstallationError(problem) if not req.match_markers(): continue name = canonicalize_name(req.name) if name in constraints: constraints[name] = constraints[name] & req.specifier else: constraints[name] = req.specifier else: if req.user_supplied and req.name: user_requested.add(canonicalize_name(req.name)) r = self.factory.make_requirement_from_install_req( req, requested_extras=(), ) if r is not None: requirements.append(r) provider = PipProvider( factory=self.factory, constraints=constraints, ignore_dependencies=self.ignore_dependencies, upgrade_strategy=self.upgrade_strategy, user_requested=user_requested, ) reporter = BaseReporter() resolver = RLResolver(provider, reporter) try: try_to_avoid_resolution_too_deep = 2000000 self._result = resolver.resolve( requirements, max_rounds=try_to_avoid_resolution_too_deep, ) except ResolutionImpossible as e: error = self.factory.get_installation_error(e) six.raise_from(error, e) req_set = RequirementSet(check_supported_wheels=check_supported_wheels) for candidate in self._result.mapping.values(): ireq = candidate.get_install_requirement() if ireq is None: continue # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed. # * There isn't, good -- no uninstalltion needed. # * The --force-reinstall flag is set. Always reinstall. # * The installation is different in version or editable-ness, so # we need to uninstall it to install the new distribution. # * The installed version is the same as the pending distribution. # Skip this distrubiton altogether to save work. installed_dist = self.factory.get_dist_to_uninstall(candidate) if installed_dist is None: ireq.should_reinstall = False elif self.factory.force_reinstall: ireq.should_reinstall = True elif installed_dist.parsed_version != candidate.version: ireq.should_reinstall = True elif dist_is_editable(installed_dist) != candidate.is_editable: ireq.should_reinstall = True else: continue link = candidate.source_link if link and link.is_yanked: # The reason can contain non-ASCII characters, Unicode # is required for Python 2. msg = ( u'The candidate selected for download or install is a ' u'yanked version: {name!r} candidate (version {version} ' u'at {link})\nReason for being yanked: {reason}').format( name=candidate.name, version=candidate.version, link=link, reason=link.yanked_reason or u'<none given>', ) logger.warning(msg) req_set.add_named_requirement(ireq) return req_set
def _init_args_from_dist(cls, dist, dependency_links): """ Compute and return arguments (req, editable, comments) to pass to FrozenRequirement.__init__(). This method is for use in FrozenRequirement.from_dist(). """ location = os.path.normcase(os.path.abspath(dist.location)) comments = [] from pip._internal.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: deprecated( "SVN editable detection based on dependency links " "will be dropped in the future.", replacement=None, gone_in="18.2", issue=4187, ) 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 egg_name = cls.egg_name(dist) req = make_vcs_requirement_url(svn_location, rev, egg_name) return (req, editable, comments)
def editable(self) -> bool: return misc.dist_is_editable(self._dist)
import os from warnings import warn from pip._internal.utils.misc import dist_is_editable import pkg_resources __author__ = "cnheider" __version__ = "0.1.3" __doc__ = """ Created on 27/04/2019 @author: cnheider """ distributions = {v.key: v for v in pkg_resources.working_set} distribution = distributions["nvidia-smi"] DEVELOP = dist_is_editable(distribution) def get_version(append_time=DEVELOP): version = __version__ if not version: version = os.getenv("VERSION", "0.0.0") if append_time: now = datetime.datetime.utcnow() date_version = now.strftime("%Y%m%d%H%M%S") # date_version = time.time() if version: # Most git tags are prefixed with 'v' (example: v1.2.3) this is # never desirable for artifact repositories, so we strip the
import pkg_resources from pip._internal.utils.misc import dist_is_editable distributions = {v.key: v for v in pkg_resources.working_set} DEV_MODE = dist_is_editable(distributions["jupyter-flex"]) # DEV_MODE = False del distributions
def update(args=None): try: from pip._internal.utils.misc import (get_installed_version, dist_is_editable, dist_location) except ImportError: 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")
def resolve(self, root_reqs, check_supported_wheels): # type: (List[InstallRequirement], bool) -> RequirementSet constraints = {} # type: Dict[str, Constraint] user_requested = set() # type: Set[str] requirements = [] for req in root_reqs: if req.constraint: # Ensure we only accept valid constraints problem = check_invalid_constraint_type(req) if problem: raise InstallationError(problem) if not req.match_markers(): continue name = canonicalize_name(req.name) if name in constraints: constraints[name] &= req else: constraints[name] = Constraint.from_ireq(req) else: if req.user_supplied and req.name: user_requested.add(canonicalize_name(req.name)) r = self.factory.make_requirement_from_install_req( req, requested_extras=(), ) if r is not None: requirements.append(r) provider = PipProvider( factory=self.factory, constraints=constraints, ignore_dependencies=self.ignore_dependencies, upgrade_strategy=self.upgrade_strategy, user_requested=user_requested, ) if "PIP_RESOLVER_DEBUG" in os.environ: reporter = PipDebuggingReporter() else: reporter = PipReporter() resolver = RLResolver(provider, reporter) try: try_to_avoid_resolution_too_deep = 2000000 self._result = resolver.resolve( requirements, max_rounds=try_to_avoid_resolution_too_deep, ) except ResolutionImpossible as e: error = self.factory.get_installation_error(e) six.raise_from(error, e) req_set = RequirementSet(check_supported_wheels=check_supported_wheels) for candidate in self._result.mapping.values(): ireq = candidate.get_install_requirement() if ireq is None: continue # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed. installed_dist = self.factory.get_dist_to_uninstall(candidate) if installed_dist is None: # There is no existing installation -- nothing to uninstall. ireq.should_reinstall = False elif self.factory.force_reinstall: # The --force-reinstall flag is set -- reinstall. ireq.should_reinstall = True elif installed_dist.parsed_version != candidate.version: # The installation is different in version -- reinstall. ireq.should_reinstall = True elif candidate.is_editable or dist_is_editable(installed_dist): # The incoming distribution is editable, or different in # editable-ness to installation -- reinstall. ireq.should_reinstall = True elif candidate.source_link.is_file: # The incoming distribution is under file:// if candidate.source_link.is_wheel: # is a local wheel -- do nothing. logger.info( "%s is already installed with the same version as the " "provided wheel. Use --force-reinstall to force an " "installation of the wheel.", ireq.name, ) continue looks_like_sdist = (is_archive_file( candidate.source_link.file_path) and candidate.source_link.ext != ".zip") if looks_like_sdist: # is a local sdist -- show a deprecation warning! reason = ( "Source distribution is being reinstalled despite an " "installed package having the same name and version as " "the installed package.") replacement = "use --force-reinstall" deprecated( reason=reason, replacement=replacement, gone_in="21.1", issue=8711, ) # is a local sdist or path -- reinstall ireq.should_reinstall = True else: continue link = candidate.source_link if link and link.is_yanked: # The reason can contain non-ASCII characters, Unicode # is required for Python 2. msg = ('The candidate selected for download or install is a ' 'yanked version: {name!r} candidate (version {version} ' 'at {link})\nReason for being yanked: {reason}').format( name=candidate.name, version=candidate.version, link=link, reason=link.yanked_reason or '<none given>', ) logger.warning(msg) req_set.add_named_requirement(ireq) reqs = req_set.all_requirements self.factory.preparer.prepare_linked_requirements_more(reqs) return req_set
continue # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed. <<<<<<< HEAD installed_dist = self.factory.get_dist_to_uninstall(candidate) if installed_dist is None: # There is no existing installation -- nothing to uninstall. ireq.should_reinstall = False elif self.factory.force_reinstall: # The --force-reinstall flag is set -- reinstall. ireq.should_reinstall = True elif installed_dist.parsed_version != candidate.version: # The installation is different in version -- reinstall. ireq.should_reinstall = True elif candidate.is_editable or dist_is_editable(installed_dist): # The incoming distribution is editable, or different in # editable-ness to installation -- reinstall. ireq.should_reinstall = True elif candidate.source_link.is_file: # The incoming distribution is under file:// if candidate.source_link.is_wheel: # is a local wheel -- do nothing. logger.info( "%s is already installed with the same version as the " "provided wheel. Use --force-reinstall to force an " "installation of the wheel.", ireq.name, ) continue