How to use requirementslib - 10 common examples

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
# Test URLs without eggs pointing at installable zipfiles
    url = Requirement.from_line(
        "https://codeload.github.com/kennethreitz/tablib/zip/v0.12.1"
    ).requirement
    assert url.url == "https://codeload.github.com/kennethreitz/tablib/zip/v0.12.1"
    wheel_line = "https://github.com/pypa/pipenv/raw/master/tests/test_artifacts/six-1.11.0+mkl-py2.py3-none-any.whl"
    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
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_repo_line(repo_line):
    reformatted_line = repo_line
    if repo_line.startswith("-e "):
        repo_list = repo_line.split(" ", 1)
        if "; " in repo_list[1]:
            reformatted_line = '{0} "{1}"'.format(repo_list[0], repo_list[1])
    else:
        repo_list = [repo_line]
    line_as_list = repo_line.split(" ", 1) if repo_line.startswith("-e ") else [repo_line]
    assert (
        Line(repo_line).get_line(with_prefix=True, with_markers=True, as_list=False)
        == reformatted_line
    )
    assert (
        Line(repo_line).get_line(with_prefix=True, with_markers=True, as_list=True)
        == repo_list
    )
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_convert_from_pip_fail_if_no_egg():
    """Parsing should fail without `#egg=`.
    """
    dep = "git+https://github.com/kennethreitz/requests.git"
    with pytest.raises(ValueError) as e:
        dep = Requirement.from_line(dep).as_pipfile()
        assert "pipenv requires an #egg fragment for vcs" in str(e)
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 get_abstract_deps():
    r = Requirement.from_line("requests")
    deps = [InstallRequirement.from_line(d) for d in r.get_dependencies()]
    abstract_deps = r.get_abstract_dependencies()
    req_abstract_dep = AbstractDependency.from_requirement(r)
    assert r.abstract_dep == req_abstract_dep
    assert len(abstract_deps) > 0
    deps_from_ireqs = get_abstract_dependencies(deps, parent=r)
    assert len(deps_from_ireqs) > 0
    assert sorted(set(deps_from_ireqs)) == sorted(set(abstract_deps))
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"