Example #1
0
def get_pypi_versions() -> Dict[str, Optional[str]]:
    """Get versions from ``pip freeze``"""
    d = dict()
    for line in pip_freeze():
        try:
            k, v = line.strip().split("==")
        except ValueError:
            continue
        d[k] = v
    return d
Example #2
0
File: setup.py Project: aghast/larn
def pip_requirements(path: str) -> List[str]:
    """ Parse the requirements out of a pip requirements file. """
    path_list = [path]

    while path_list:
        path = path_list.pop(0)

        with open(path) as reqfile:
            lines = reqfile.readlines()

        missing_versions = set()
        results = []

        version_ops = """== >= <= < >""".split()

        for line in lines:
            line = line.strip()
            if not line:
                continue

            if any(operator in line for operator in version_ops):
                results.append(line)
                continue

            if line.startswith('-r'):
                # recursive requirements file
                _, subfile = line.split()
                path_list.append(subfile)
                continue

            if line.startswith('-e'):
                # editable repo or path spec
                _, eggname = line.split('#egg=')
                results.append(eggname)
                continue

            # Now we have a line with a package but no version. Add it to
            # the list of needs.
            missing_versions.add(line)

    # Now all recursive files have been parsed. If any packages are missing
    # versions, run `pip freeze` to get the version numbers.

    if missing_versions:
        for line in pip_freeze(exclude_editable=True):
            name, eql, rest = line.partition('==')
            if name in missing_versions:
                results.append(line)

    return results
Example #3
0
    def get(self, request):
        context = {}

        # Flags in settings: Their expected  and actual values.
        SETTINGS_FLAGS = [
            ('DEBUG', False),
            ('LANGUAGE_CODE', None),
            ('TIME_ZONE', None),
        ]

        context['python'] = '.'.join(str(x) for x in sys.version_info[:3])
        context['platform'] = {
            'os': platform.system(),
            'release': platform.release(),
            'version': platform.version(),
            'mac_version': platform.mac_ver(),
            'win_version': platform.win32_ver(),
            'linux_dist': platform.linux_distribution(),
        }
        context['hostname'] = socket.gethostname()
        context['version'] = get_versions()
        context['core_version'] = get_core_versions()
        context['time_checked'] = timezone.now()
        context['database'] = get_database_info()

        try:
            context['elasticsearch'] = get_elasticsearch_info()
        except KeyError:
            pass

        context['redis'] = get_redis_info()
        context['rabbitmq'] = get_rabbitmq_info()
        context['workers'] = get_workers()
        context['python_packages'] = pip_freeze()

        context['settings_flags'] = []
        for name, expected in SETTINGS_FLAGS:
            actual_setting = getattr(settings, name, None)
            if expected is not None:
                unexpected = expected != actual_setting
            else:
                unexpected = False
            context['settings_flags'].append({
                'name': name,
                'unexpected': unexpected,
                'actual': actual_setting
            })

        return Response(context)
Example #4
0
def get_mismatches(requirements_file_path):
    """Return a dictionary of requirement mismatches."""
    pip_lines = read_pip(requirements_file_path)

    expected = get_package_versions(pip_lines)
    actual = get_package_versions(pip_freeze(), ignore_external=True)

    mismatches = {}
    for name, version in expected.items():
        if name not in actual:
            mismatches[name] = (version, None)
            continue

        if version != actual[name]:
            mismatches[name] = (version, actual[name])

    return mismatches