How to use the requirementslib.models.requirements.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 / requirementslib / tests / unit / test_requirements.py View on Github external
wheel = Requirement.from_line(wheel_line)
    assert wheel.as_pipfile() == {
        "six": {
            "file": "https://github.com/pypa/pipenv/raw/master/tests/test_artifacts/six-1.11.0+mkl-py2.py3-none-any.whl"
        }
    }
    # Requirementslib inserts egg fragments as names when possible if we know the appropriate name
    # this allows for custom naming
    assert (
        Requirement.from_pipfile(wheel.name, list(wheel.as_pipfile().values())[0])
        .as_line()
        .split("#")[0]
        == wheel_line
    )
    # Test VCS urls with refs and eggnames
    vcs_url = Requirement.from_line(
        "git+https://github.com/kennethreitz/tablib.git@master#egg=tablib"
    ).requirement
    assert (
        vcs_url.vcs == "git" and vcs_url.name == "tablib" and vcs_url.revision == "master"
    )
    assert vcs_url.url == "git+https://github.com/kennethreitz/tablib.git"
    # Test normal package requirement
    normal = Requirement.from_line("tablib").requirement
    assert normal.name == "tablib"
    # Pinned package  requirement
    spec = Requirement.from_line("tablib==0.12.1").requirement
    assert spec.name == "tablib" and spec.specs == [("==", "0.12.1")]
    # Test complex package with both extras and markers
    extras_markers = Requirement.from_line(
        "requests[security]; os_name=='posix'"
    ).requirement
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
assert vcs_url.url == "git+https://github.com/kennethreitz/tablib.git"
    # Test normal package requirement
    normal = Requirement.from_line("tablib").requirement
    assert normal.name == "tablib"
    # Pinned package  requirement
    spec = Requirement.from_line("tablib==0.12.1").requirement
    assert spec.name == "tablib" and spec.specs == [("==", "0.12.1")]
    # Test complex package with both extras and markers
    extras_markers = Requirement.from_line(
        "requests[security]; os_name=='posix'"
    ).requirement
    assert list(extras_markers.extras) == ["security"]
    assert extras_markers.name == "requests"
    assert str(extras_markers.marker) == 'os_name == "posix"'
    # Test VCS uris get generated correctly, retain git+git@ if supplied that way, and are named according to egg fragment
    git_reformat = Requirement.from_line(
        "-e git+git@github.com:pypa/pipenv.git#egg=pipenv"
    ).requirement
    assert git_reformat.url == "git+ssh://git@github.com/pypa/pipenv.git"
    assert git_reformat.name == "pipenv"
    assert git_reformat.editable
    # Previously VCS uris were being treated as local files, so make sure these are not handled that way
    assert not git_reformat.local_file
    # Test regression where VCS uris were being handled as paths rather than VCS entries
    assert git_reformat.vcs == "git"
    assert git_reformat.link.url == "git+ssh://git@github.com/pypa/pipenv.git#egg=pipenv"
    # Test VCS requirements being added with extras for constraint_line
    git_extras = Requirement.from_line(
        "-e git+https://github.com/requests/requests.git@master#egg=requests[security]"
    )
    assert (
        git_extras.as_line()
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_convert_from_pip_git_uri_normalize(monkeypatch):
    """Pip does not parse this correctly, but we can (by converting to ssh://).
    """
    with monkeypatch.context() as m:
        m.setattr(Requirement, "run_requires", mock_run_requires)
        m.setattr(SetupInfo, "get_info", mock_run_requires)
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        dep = "git+git@host:user/repo.git#egg=myname"
        dep = Requirement.from_line(dep).as_pipfile()
        assert dep == {"myname": {"git": "git@host:user/repo.git"}}
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_stdout_is_suppressed(capsys, tmpdir):
    r = Requirement.from_line("git+https://github.com/benjaminp/six.git@master#egg=six")
    r.req.get_vcs_repo(src_dir=tmpdir.strpath)
    out, err = capsys.readouterr()
    assert out.strip() == "", out
    assert err.strip() == "", err
github sarugaku / requirementslib / tests / unit / test_dependencies.py View on Github external
def test_get_deps_from_index():
    r = Requirement.from_line("requests==2.19.1")
    deps = get_dependencies_from_index(r.as_ireq())
    assert len(deps) > 0
github sarugaku / requirementslib / tests / unit / test_utils.py View on Github external
def test_format_specifier():
    ireq = Requirement.from_line("foo").as_ireq()
    assert utils.format_specifier(ireq) == ""

    ireq = Requirement.from_line("foo==1.2").as_ireq()
    assert utils.format_specifier(ireq) == "==1.2"

    ireq = Requirement.from_line("foo>1.2,~=1.1,<1.5").as_ireq()
    assert utils.format_specifier(ireq) == "~=1.1,>1.2,<1.5"
    ireq = Requirement.from_line("foo~=1.1,<1.5,>1.2").as_ireq()
    assert utils.format_specifier(ireq) == "~=1.1,>1.2,<1.5"