Parse pip requirements file.
187514
def parse_pip_file(path):
    """"""
    # requirement lines sorted by importance
    # also collect other pip commands
    rdev = dict()
    rnormal = []
    stuff = []

    try:
        with open(path) as f:
            for line in f:
                line = line.strip()

                # see https://pip.readthedocs.org/en/1.1/requirements.html
                if line.startswith('-e'):
                    # devel requirement
                    splitted = line.split('#egg=')
                    rdev[splitted[1].lower()] = line

                elif line.startswith('-r'):
                    # recursive file command
                    splitted = re.split('-r\\s+', line)
                    subrdev, subrnormal, substuff = parse_pip_file(splitted[1])
                    for k, v in subrdev.iteritems():
                        if k not in rdev:
                            rdev[k] = v
                    rnormal.extend(subrnormal)
                    result.extend(substuff)

                elif line.startswith('-'):
                    # another special command we don't recognize
                    stuff.append(line)

                else:
                    # ordenary requirement, similary to them used in setup.py
                    rnormal.append(line)
    except IOError:
        print(
            'Warning: could not parse requirements file "{}"!',
            file=sys.stderr
        )

    return rdev, rnormal, stuff
772844
def get_requirements_file_from_url(url):
    """"""
    response = requests.get(url)

    if response.status_code == 200:
        return StringIO(response.text)
    else:
        return StringIO("")
1358530
def check_requirements(dist, attr, value):
    """"""
    try:
        list(pkg_resources.parse_requirements(value))
    except (TypeError,ValueError):
        raise DistutilsSetupError(
            "%r must be a string or list of strings "
            "containing valid project/version requirement specifiers" % (attr,)
        )
1161948
def get_requirements():
    ''''''
    packages = []
    with open("requirements.txt", "r") as req_doc:
        for package in req_doc:
            packages.append(package.replace("\n", ""))
    return packages
1154788
def get_requirements(source):
    

    install_reqs = parse_requirements(filename=source, session=PipSession())

    return [str(ir.req) for ir in install_reqs]
1049560
def clean_requires_python(candidates):
    """"""
    all_candidates = []
    sys_version = ".".join(map(str, sys.version_info[:3]))
    from packaging.version import parse as parse_version

    py_version = parse_version(os.environ.get("PIP_PYTHON_VERSION", sys_version))
    for c in candidates:
        from_location = attrgetter("location.requires_python")
        requires_python = getattr(c, "requires_python", from_location(c))
        if requires_python:
            # Old specifications had people setting this to single digits
            # which is effectively the same as '>=digit,<digit+1'
            if requires_python.isdigit():
                requires_python = ">={0},<{1}".format(
                    requires_python, int(requires_python) + 1
                )
            try:
                specifierset = SpecifierSet(requires_python)
            except InvalidSpecifier:
                continue
            else:
                if not specifierset.contains(py_version):
                    continue
        all_candidates.append(c)
    return all_candidates
1277643
def convert_requirements(requirements):
    """"""
    for req in requirements:
        parsed_requirement = pkg_resources.Requirement.parse(req)
        spec = requires_to_requires_dist(parsed_requirement)
        extras = ",".join(parsed_requirement.extras)
        if extras:
            extras = "[%s]" % extras
        yield (parsed_requirement.project_name + extras + spec)
659270
def read_requirements(req_file):
    
    items = list(parse_requirements(req_file, session={}))
    result = []

    for item in items:
        # Get line number from item
        line_number = item.comes_from.split(req_file + ' (line ')[1][:-1]
        if item.req:
            item.req.marker = item.markers
            result.append((item.req, line_number))
        else:
            result.append((item, line_number))

    return result
308571
def parse_requirements(filename):
    

    try:
        with open(filename) as fh_req:
            return [line.strip() for line in fh_req if line.strip() and not line.startswith('#')]
    except FileNotFoundError:
        print('File not found: {}'.format(realpath(filename)), file=stderr)
        raise
413825
def get_requirements(opts):
    '''  '''

    if opts.dev:
        name = 'requirements_dev.txt'
    elif opts.doc:
        name = 'requirements_doc.txt'
    else:
        name = 'requirements.txt'

    requirements_file = os.path.join(os.path.dirname(__file__), name)
    install_requires = [line.strip().replace('==', '>=') for line in open(requirements_file)
                        if not line.strip().startswith('#') and line.strip() != '']
    return install_requires
332020
def parse_requirements(
        requirements_path: str = 'requirements.txt') -> t.List[str]:
    
    requirements = []
    with HERE.joinpath(requirements_path).open() as reqs_file:
        for requirement in [line.strip() for line in reqs_file.read().splitlines()]:
            if not requirement or requirement.startswith('#'):
                continue
            requirements.append(requirement)
    return requirements
851274
def requirements(self, requires):
        '''
        
        '''
        if requires:
            if isinstance(requires, basestring) and \
               os.path.isfile(os.path.abspath(requires)):
                self._requirements_file = os.path.abspath(requires)
            else:
                if isinstance(self._requirements, basestring):
                    requires = requires.split()
                self._requirements_file = None
                self._requirements = requires
        else:
            # If the default requirements file is found use that
            if os.path.isfile(self._requirements_file):
                return
            self._requirements, self._requirements_file = None, None
131463
def read_requirements(filename):
    
    data = []
    for line in read_file(filename):
        line = line.strip()
        if not line or line.startswith('#'):
            continue

        if '+' in line[:4]:
            repo_link, egg_name = line.split('#egg=')
            if not egg_name:
                raise ValueError('Unknown requirement: {0}'
                                    .format(line))

            DEPENDENCY_LINKS.append(line)

            line = egg_name

        data.append(line)

    return data
1218191
def pip(filename):
    ''''''
    path = join('requirements', filename)
    return [line for line in open(path).readlines() if not line.startswith('-e')]
369784
def _install_requirements(self):
        '''
        
        '''
        if not hasattr(self, '_pkg_venv'):
            err = 'Must call build_new_virtualenv before install_requirements'
            raise Exception(err)

        cmd = None
        if self._requirements:
            LOG.debug("Installing requirements found %s in config"
                      % self._requirements)
            cmd = [os.path.join(self._pkg_venv, self._venv_pip),
                   'install'] + self._requirements

        elif _isfile(self._requirements_file):
            # Pip install
            LOG.debug("Installing requirements from requirements.txt file")
            cmd = [os.path.join(self._pkg_venv, self._venv_pip),
                   "install", "-r",
                   self._requirements_file]

        if cmd is not None:
            prc = Popen(cmd, stdout=PIPE, stderr=PIPE)
            stdout, stderr = prc.communicate()
            LOG.debug("Pip stdout: %s" % stdout)
            LOG.debug("Pip stderr: %s" % stderr)

            if prc.returncode is not 0:
                raise Exception('pip returned unsuccessfully')
804691
def parsed_pipfile(self):
        """"""
        contents = self.read_pipfile()
        # use full contents to get around str/bytes 2/3 issues
        cache_key = (self.pipfile_location, contents)
        if cache_key not in _pipfile_cache:
            parsed = self._parse_pipfile(contents)
            _pipfile_cache[cache_key] = parsed
        return _pipfile_cache[cache_key]
801771
def pip(filename):
    """"""
    requirements = []
    for line in open(join(ROOT, 'requirements', filename)):
        line = line.strip()
        if not line or '://' in line:
            continue
        match = RE_REQUIREMENT.match(line)
        if match:
            requirements.extend(pip(match.group('filename')))
        else:
            requirements.append(line)
    return requirements