Пример #1
0
def get_requirements_list(requirements_file_path, dev_deps=False):
    # TODO: refactor recognizing the dependency manager to a single place
    if os.path.basename(requirements_file_path) == 'Pipfile':
        with io.open(requirements_file_path, 'r', encoding='utf-8') as f:
            requirements_data = f.read()
        parsed_reqs = pipfile.parse(requirements_data)
        req_list = list(parsed_reqs.get('packages', []))
        if dev_deps:
            req_list.extend(parsed_reqs.get('dev-packages', []))
    else:
        # assume this is a requirements.txt formatted file
        # Note: requirements.txt files are unicode and can be in any encoding.
        with open(requirements_file_path, 'r') as f:
            requirements_data = f.read()
        req_list = list(requirements.parse(requirements_data))

    req_list = filter(matches_environment, req_list)
    req_list = filter(is_testable, req_list)
    required = [req.name.replace('_', '-') for req in req_list]
    return required
Пример #2
0
def get_requirements_list(requirements_file_path, dev_deps=False):
    # TODO: refactor recognizing the dependency manager to a single place
    if os.path.basename(requirements_file_path) == 'Pipfile':
        with io.open(requirements_file_path, 'r', encoding='utf-8') as f:
            requirements_data = f.read()
        parsed_reqs = pipfile.parse(requirements_data)
        req_list = list(parsed_reqs.get('packages', []))
        if dev_deps:
            req_list.extend(parsed_reqs.get('dev-packages', []))
        if not req_list:
            return []
        else:
            for r in req_list:
                r.provenance = (requirements_file_path, r.provenance[1], r.provenance[2])
    elif os.path.basename(requirements_file_path) == 'setup.py':
        with open(requirements_file_path, 'r') as f:
            setup_py_file_content = f.read()
        requirements_data = setup_file.parse_requirements(setup_py_file_content)
        req_list = list(requirements.parse(requirements_data))

        provenance = setup_file.get_provenance(setup_py_file_content)
        for req in req_list:
            req.provenance = (
                os.path.basename(requirements_file_path),
                provenance,
                provenance
            )
    else:
        # assume this is a requirements.txt formatted file
        # Note: requirements.txt files are unicode and can be in any encoding.
        with open(requirements_file_path, 'r') as f:
            req_list = list(requirements.parse(f))

    req_list = filter(matches_environment, req_list)
    req_list = filter(is_testable, req_list)
    req_list = filter(matches_python_version, req_list)
    req_list = [r for r in req_list if r.name]
    for req in req_list:
        req.name = req.name.lower().replace('_', '-')
    return req_list