How to use the requirementslib.Requirement.from_line function in requirementslib

To help you get started, we’ve selected a few requirementslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sarugaku / passa / src / passa / projects.py View on Github external
def add_line_to_pipfile(self, line, develop):
        from requirementslib import Requirement
        requirement = Requirement.from_line(line)
        section = self._get_pipfile_section(develop=develop)
        key = requirement.normalized_name
        entry = next(iter(requirement.as_pipfile().values()))
        if isinstance(entry, dict):
            # HACK: TOMLKit prefers to expand tables by default, but we
            # always want inline tables here. Also tomlkit.inline_table
            # does not have `update()`.
            table = tomlkit.inline_table()
            for k, v in entry.items():
                table[k] = v
            entry = table
        section[key] = entry
github sarugaku / passa / src / passa / internals / dependencies.py View on Github external
The extra extraction is not comprehensive. Tt assumes the marker is NEVER
    something like `extra == "foo" and extra == "bar"`. I guess this never
    makes sense anyway? Markers are just terrible.
    """
    extras = extras or ()
    requirements = []
    for entry in metadata.run_requires:
        if isinstance(entry, six.text_type):
            entry = {"requires": [entry]}
            extra = None
        else:
            extra = entry.get("extra")
        if extra is not None and extra not in extras:
            continue
        for line in entry.get("requires", []):
            r = requirementslib.Requirement.from_line(line)
            if r.markers:
                contained = get_contained_extras(r.markers)
                if (contained and not any(e in contained for e in extras)):
                    continue
                marker = get_without_extra(r.markers)
                r.markers = str(marker) if marker else None
                line = r.as_line(include_hashes=False)
            requirements.append(line)
    return requirements
github pypa / pipenv / pipenv / vendor / passa / internals / dependencies.py View on Github external
def _is_cache_broken(line, parent_name):
    dep_req = requirementslib.Requirement.from_line(line)
    if contains_extra(dep_req.markers):
        return True     # The "extra =" marker breaks everything.
    elif dep_req.normalized_name == parent_name:
        return True     # A package cannot depend on itself.
    return False
github pypa / pipenv / pipenv / vendor / passa / internals / dependencies.py View on Github external
The extra extraction is not comprehensive. Tt assumes the marker is NEVER
    something like `extra == "foo" and extra == "bar"`. I guess this never
    makes sense anyway? Markers are just terrible.
    """
    extras = extras or ()
    requirements = []
    for entry in metadata.run_requires:
        if isinstance(entry, six.text_type):
            entry = {"requires": [entry]}
            extra = None
        else:
            extra = entry.get("extra")
        if extra is not None and extra not in extras:
            continue
        for line in entry.get("requires", []):
            r = requirementslib.Requirement.from_line(line)
            if r.markers:
                contained = get_contained_extras(r.markers)
                if (contained and not any(e in contained for e in extras)):
                    continue
                marker = get_without_extra(r.markers)
                r.markers = str(marker) if marker else None
                line = r.as_line(include_hashes=False)
            requirements.append(line)
    return requirements
github pypa / pipenv / pipenv / vendor / requirementslib / models / project.py View on Github external
def add_line_to_pipfile(self, line, develop):
        from requirementslib import Requirement
        requirement = Requirement.from_line(line)
        section = self._get_pipfile_section(develop=develop)
        key = requirement.normalized_name
        entry = next(iter(requirement.as_pipfile().values()))
        if isinstance(entry, dict):
            # HACK: TOMLKit prefers to expand tables by default, but we
            # always want inline tables here. Also tomlkit.inline_table
            # does not have `update()`.
            table = tomlkit.inline_table()
            for k, v in entry.items():
                table[k] = v
            entry = table
        section[key] = entry
github sarugaku / requirementslib / src / requirementslib / models / project.py View on Github external
def add_line_to_pipfile(self, line, develop):
        from requirementslib import Requirement

        requirement = Requirement.from_line(line)
        section = self._get_pipfile_section(develop=develop)
        key = requirement.normalized_name
        entry = next(iter(requirement.as_pipfile().values()))
        if isinstance(entry, dict):
            # HACK: TOMLKit prefers to expand tables by default, but we
            # always want inline tables here. Also tomlkit.inline_table
            # does not have `update()`.
            table = tomlkit.inline_table()
            for k, v in entry.items():
                table[k] = v
            entry = table
        section[key] = entry
github sarugaku / resolvelib / play / resolve.py View on Github external
from requirementslib import Pipfile, Requirement
from requirementslib.models.utils import make_install_requirement

from resolvelib import (
    AbstractProvider, BaseReporter, Resolver,
    NoVersionsAvailable, ResolutionImpossible,
)


parser = argparse.ArgumentParser()
parser.add_argument('packages', metavar='PACKAGE', nargs='*')
parser.add_argument('--project', type=os.path.abspath)
options = parser.parse_args()


requirements = [Requirement.from_line(line) for line in options.packages]
if options.project:
    os.chdir(options.project)
    pipfile = Pipfile.load(options.project)
    requirements.extend(pipfile.packages.requirements)
    requirements.extend(pipfile.dev_packages.requirements)


def _filter_needed(requirement):
    if not requirement.markers:
        return True
    return requirement.ireq.match_markers()


class RequirementsLibProvider(AbstractProvider):
    """Provider implementation to interface with `requirementslib.Requirement`.
    """