def cmd_pip_outdated_packages(self, *argv, **kwargs): local = kwargs.get('local', False) user = kwargs.get('user', False) update_available = [] list_command = ListCommand() options, args = list_command.parse_args([]) options.local = local options.user = user for dist, version, typ in list_command.find_packages_latest_versions(options): if version > dist.parsed_version: update_available.append((dist.project_name, str(dist.version), str(version), typ)) return update_available
def cmd_pip_check_version(self, *argv, **kwargs): list_command = ListCommand() options, args = list_command.parse_args([]) session = list_command._build_session(options, retries=0, timeout=min(5, options.timeout)) installed_version = get_installed_version("pip") if installed_version is None: return pypi_version = None try: state = load_selfcheck_statefile() current_time = datetime.datetime.utcnow() if "last_check" in state.state and "pypi_version" in state.state: last_check = datetime.datetime.strptime( state.state["last_check"], SELFCHECK_DATE_FMT ) if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60: pypi_version = state.state["pypi_version"] # Refresh the version if we need to or just see if we need to warn if pypi_version is None: resp = session.get( PyPI.pip_json_url, headers={"Accept": "application/json"}, ) resp.raise_for_status() pypi_version = [ v for v in sorted( list(resp.json()["releases"]), key=parse_version, ) if not parse_version(v).is_prerelease ][-1] state.save(pypi_version, current_time) except Exception: pass return 'pip', installed_version, str(pypi_version)
class ListCmd(object): def __init__(self): self.cmd = ListCommand() self.options, self.args = self.cmd.parser.parse_args(['-o']) @property def outdated_packages(self): for package_data in self.cmd.find_packages_latests_versions( self.options): dist, remote = package_data[0], package_data[1:] if len(remote) == 1: # Later versions of pip remote_parsed = remote[0] else: remote_parsed = remote[-1] if remote_parsed > dist.parsed_version: yield dist.project_name, dist.parsed_version, remote_parsed
def __init__(self): self.cmd = ListCommand() self.options, self.args = self.cmd.parser.parse_args(['-o'])