Example #1
0
def getReqs(filename, salida):
    toImport = []
    #Imports necesarios
    with open(filename) as f:
        for line in f.readlines():
            if '\n' == line:
                break
            else:
                if 'import' in line.split()[0]:
                    if ',' in line:
                        words = line.split()
                        words = [s.replace(',', '') for s in words]
                        words = words[words.index('import') + 1:len(words)]
                        [toImport.append(s) for s in words]
                    else:
                        words = line.split()
                        toImport.append(words[words.index('import') + 1])
                elif 'from' in line.split()[0]:
                    toImport.append(line.split()[1])

    print toImport
    fileSalida = open(salida, "w")
    x = freeze.freeze()
    for p in x:
        #print p
        if any(s.lower() in p for s in toImport):
            fileSalida.write(p + "\n")
            print p

    fileSalida.close()
    f.close()
Example #2
0
def packages(**kwargs):
    """
    Uses pip freeze to yield a list of packages installed.
    TODO: Directly implement pip freeze: https://github.com/pypa/pip
    """
    for dep in freeze.freeze(**kwargs):
        yield parse(dep)
Example #3
0
def pythonInfo():
    """Returns Python information.
    """
    try:
        from pip.operations.freeze import freeze
        pipInfo = list()
        for i in freeze():
            pipInfo.append(i)
    except ImportError as e:
        pipInfo = ["Could not get PIP information: {}".format(str(e))]

    return {
        "Python information": {
            "Python implementation":
            platform.python_implementation(),
            "Python version":
            "{} {}".format(platform.python_version(), platform.python_build()),
            "Python binary path":
            sys.executable,
            "Prefix":
            sys.prefix,
            "Exec prefix":
            sys.exec_prefix,
            "Module search paths":
            sys.path,
            "pip freeze":
            pipInfo
        }
    }
Example #4
0
def packages(**kwargs):
    """
    Uses pip freeze to yield a list of packages installed.
    TODO: Directly implement pip freeze: https://github.com/pypa/pip
    """
    for dep in freeze.freeze(**kwargs):
        yield parse(dep)
Example #5
0
def _freeze2df():
    d = dict(v.split('==') for v in freeze() if '==' in v)
    d['version'] = 'version'
    df = pd.DataFrame([d])
    df.set_index(['version'], inplace=True)
    df = df.transpose()
    setattr(df, 'name', 'packages')
    return df
Example #6
0
def _freeze2df():
    from pip.operations.freeze import freeze
    d = dict(v.split('==') for v in freeze() if '==' in v)
    d = {k: (v, ) for k, v in d.items()}
    d['version'] = 'version'
    df = pd.DataFrame([d])
    df.set_index(['version'], inplace=True)
    df = df.transpose()
    setattr(df, 'name', 'packages')
    return df
Example #7
0
    def run(self, options, args):
        freeze_kwargs = dict(requirement=options.requirement,
                             find_links=options.find_links,
                             local_only=options.local,
                             user_only=options.user,
                             skip_regex=options.skip_requirements_regex,
                             isolated=options.isolated_mode)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
def test_env_matches_requirements_txt():
    from pip.operations import freeze

    def check_is_in(src, dests):
        if src not in dests:
            print("%s not in" % src)
            return False
        return True

    def skip_line(line):
        return (
            line == ''
            or line.strip().startswith('#')
            or line.strip().startswith('git')
            or line.startswith('-e')
            or '## The following requirements were added by pip freeze' in line
        )

    base_dir = settings.BASE_DIR
    requirements_path = os.path.join(base_dir, '../', 'requirements/requirements.txt')

    reqs_actual = []
    xs = freeze.freeze(local_only=True)
    for x in xs:
        if skip_line(x):
            continue
        x = x.lower()
        (pkg_name, pkg_version) = x.split('==')
        reqs_actual.append([pkg_name, pkg_version])

    reqs_expected = []
    with open(requirements_path) as f:
        for line in f:
            line = line.partition('#')[0]
            line = line.rstrip().lower()
            # TODO: process git requiremenst and use egg
            if skip_line(line):
                continue

            '''
            Special case pkg_name[pkg_subname]==version
            For this case, we strip out [pkg_subname]
            '''
            (pkg_name, pkg_version) = line.split('==')
            pkg_name = re.sub(r'\[.*\]', '', pkg_name)
            reqs_expected.append([pkg_name, pkg_version])

    not_found = []
    for r in reqs_expected:
        res = check_is_in(r, reqs_actual)
        if res is False:
            not_found.append(r)

    if len(not_found) > 0:
        raise RuntimeError("%s not found in \n\n%s" % (not_found, reqs_actual))
Example #9
0
    def run(self, options, args):
        freeze_kwargs = dict(
            requirement=options.requirement,
            find_links=options.find_links,
            local_only=options.local,
            user_only=options.user,
            skip_regex=options.skip_requirements_regex,
            isolated=options.isolated_mode)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
Example #10
0
def check_publisher_version():
    '''Check if an existing version of the Publisher is found on the system'''
    module_list = list(freeze.freeze())
    matcher = re.compile("esgcet==.*")
    results_list = filter(matcher.match, module_list)
    if results_list:
        version = results_list[0].split("==")[1]
        print "Found existing esg-publisher installation (esg-publisher version {version})".format(
            version=version)
        return version
    else:
        print "esg-publisher not found on system."
Example #11
0
    def run(self, options, args):
        format_control = pip.index.FormatControl(set(), set())
        wheel_cache = WheelCache(options.cache_dir, format_control)
        freeze_kwargs = dict(requirement=options.requirement,
                             find_links=options.find_links,
                             local_only=options.local,
                             user_only=options.user,
                             skip_regex=options.skip_requirements_regex,
                             isolated=options.isolated_mode,
                             wheel_cache=wheel_cache)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
Example #12
0
    def run(self, options, args):
        format_control = pip.index.FormatControl(set(), set())
        wheel_cache = WheelCache(options.cache_dir, format_control)
        freeze_kwargs = dict(
            requirement=options.requirement,
            find_links=options.find_links,
            local_only=options.local,
            user_only=options.user,
            skip_regex=options.skip_requirements_regex,
            isolated=options.isolated_mode,
            wheel_cache=wheel_cache)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
Example #13
0
def pip_freeze():
    from pip.operations import freeze
    _packages = freeze.freeze()
    packages = []
    for _package in _packages:
        _package = _package.strip()
        if not _package:
            continue
        if _package.startswith("-e"):
            packages.append(["-e (#%d)" % len(packages), _package[3:]])
        else:
            _pack, _ver = _package.split("==", 1)
            packages.append([_pack, _ver])
    return packages
Example #14
0
def pip_list(pkg_name=None):
    """Dict of installed PIP packages with version.

    If 'pkg_name' is not None, will return only those packages matching the
    name."""
    pip_regex = re.compile(r"(?P<name>.*)==(?P<version>[\w\.]+)")
    git_regex = re.compile(r".*@(?P<version>[\w]+)#egg=(?P<name>[\w]+)")

    pkg_dict = {}
    for _pkg in freeze.freeze(local_only=True):
        match = pip_regex.match(_pkg) or git_regex.match(_pkg)
        if match and (not pkg_name or (
                pkg_name and match.group('name').find(pkg_name) != -1)):
            pkg_dict[match.group('name')] = match.group('version')

    return pkg_dict
Example #15
0
    def run(self, options, args):
        format_control = pip.index.FormatControl(set(), set())
        wheel_cache = WheelCache(options.cache_dir, format_control)
        skip = set(stdlib_pkgs)
        if not options.freeze_all:
            skip.update(DEV_PKGS)

        freeze_kwargs = dict(requirement=options.requirements,
                             find_links=options.find_links,
                             local_only=options.local,
                             user_only=options.user,
                             skip_regex=options.skip_requirements_regex,
                             isolated=options.isolated_mode,
                             wheel_cache=wheel_cache,
                             skip=skip,
                             exclude_editable=options.exclude_editable)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
Example #16
0
    def run(self, options, args):
        format_control = pip.index.FormatControl(set(), set())
        wheel_cache = WheelCache(options.cache_dir, format_control)
        skip = set(stdlib_pkgs)
        if not options.freeze_all:
            skip.update(DEV_PKGS)

        freeze_kwargs = dict(
            requirement=options.requirements,
            find_links=options.find_links,
            local_only=options.local,
            user_only=options.user,
            skip_regex=options.skip_requirements_regex,
            isolated=options.isolated_mode,
            wheel_cache=wheel_cache,
            skip=skip,
            exclude_editable=options.exclude_editable)

        for line in freeze(**freeze_kwargs):
            sys.stdout.write(line + '\n')
Example #17
0
def about(
):  #---------------------------------------------------------------<<<
    """About page - about.tpl"""
    sys_info = dict()
    sys_info['PY_VERSION'] = sys.version.strip().split(' ')[0] + \
        (' (64-bit)' if '64 bit' in sys.version else ' (32-bit)')
    sys_info['PY_LOCATION'] = sys.prefix
    sys_info['PY_PACKAGES'] = ','.join([_ for _ in freeze.freeze()])
    sys_info['PY_PATH'] = ','.join(sys.path)
    sys_info['OS_VERSION'] = platform.platform()
    sys_info['HOST_NAME'] = socket.gethostname()
    sys_info['HOST_PROC'] = \
        os.environ['PROCESSOR_ARCHITECTURE'] + ', ' + \
        os.environ['PROCESSOR_IDENTIFIER'].split(' ')[0] + ', ' + \
        os.environ['NUMBER_OF_PROCESSORS'] + ' cores'
    sys_info['HOST_IPADDR'] = socket.gethostbyname(socket.gethostname())
    sys_info['CLIENT_IP'] = request.environ.get('REMOTE_ADDR')
    sys_info['DIRECTORY'] = os.getcwd()
    size, used, free = shutil.disk_usage('/')
    sys_info['DISK_SIZE'] = '{:,}'.format(size)
    sys_info['DISK_USED'] = '{:,}'.format(used)
    sys_info['DISK_FREE'] = '{:,}'.format(free)
    return dict(sysdict=sys_info)
Example #18
0
def pip_freeze():
	from pip.operations import freeze
	x = freeze.freeze()
	return list(x)