How to use the requirementslib.models.requirements.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
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
m.setattr(SetupInfo, "get_info", mock_run_requires)
        m.setattr(Line, "get_setup_info", mock_run_requires)
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        pkg_name = next(iter(expected.keys()))
        pkg_pipfile = expected[pkg_name]
        line = Line(requirement)
        if (
            hasattr(pkg_pipfile, "keys")
            and "editable" in pkg_pipfile
            and not pkg_pipfile["editable"]
        ):
            del expected[pkg_name]["editable"]
        req = Requirement.from_line(requirement)
        assert req.as_pipfile() == expected
        assert line.line_with_prefix == req.as_line(include_hashes=False)
        assert hash(Line(line.line_with_prefix)) == hash(Line(line.line_with_prefix))
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_requirement_line(req):
    line = Line(req.line)
    assert line.get_line(with_markers=True, with_hashes=True) == req.line
    assert line.get_line(with_markers=True, with_hashes=True, as_list=True) == req.as_list
    assert line.get_line(with_markers=False, with_hashes=True) == req.line_without_markers
    assert (
        line.get_line(with_markers=False, with_hashes=True, as_list=True)
        == req.list_without_markers
    )
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_convert_from_pip(monkeypatch, expected, requirement):
    with monkeypatch.context() as m:
        m.setattr(Requirement, "run_requires", mock_run_requires)
        m.setattr(SetupInfo, "get_info", mock_run_requires)
        m.setattr(Line, "get_setup_info", mock_run_requires)
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        pkg_name = next(iter(expected.keys()))
        pkg_pipfile = expected[pkg_name]
        line = Line(requirement)
        if (
            hasattr(pkg_pipfile, "keys")
            and "editable" in pkg_pipfile
            and not pkg_pipfile["editable"]
        ):
            del expected[pkg_name]["editable"]
        req = Requirement.from_line(requirement)
        assert req.as_pipfile() == expected
        assert line.line_with_prefix == req.as_line(include_hashes=False)
        assert hash(Line(line.line_with_prefix)) == hash(Line(line.line_with_prefix))