How to use the requirementslib.models.requirements.Requirement 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_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_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_utils.py View on Github external
def test_format_requirement():
    ireq = Requirement.from_line("test==1.2").as_ireq()
    assert utils.format_requirement(ireq) == "test==1.2"
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))
github sarugaku / requirementslib / tests / unit / test_dependencies.py View on Github external
def test_find_all_matches():
    r = Requirement.from_line("six")
    matches = r.find_all_matches()
    assert len(matches) > 0
github sarugaku / requirementslib / tests / unit / test_utils.py View on Github external
def test_as_tuple():
    ireq = Requirement.from_line("foo==1.1").as_ireq()
    name, version, extras = utils.as_tuple(ireq)
    assert name == "foo"
    assert version == "1.1"
    assert extras == ()

    ireq = Requirement.from_line("foo[extra1,extra2]==1.1").as_ireq()
    name, version, extras = utils.as_tuple(ireq)
    assert name == "foo"
    assert version == "1.1"
    assert extras == ("extra1", "extra2")

    # Non-pinned versions aren't accepted
    should_be_rejected = [
        "foo==1.*",
        "foo~=1.1,<1.5,>1.2",
        "foo",
github sarugaku / requirementslib / tests / unit / test_lockfile.py View on Github external
"requests": {
                "path": ".",
                "editable": true
            }
        }
    }
    """.strip()
        )
    )
    loaded = Lockfile.load(lockfile.as_posix())
    dump_to = pathlib_tmpdir.joinpath("new_lockfile")
    dump_to.mkdir()
    from_data = Lockfile.from_data(
        dump_to.as_posix(), json.loads(lockfile.read_text()), meta_from_project=False
    )
    assert isinstance(loaded.dev_requirements[0], Requirement)
    assert isinstance(loaded.dev_requirements_list[0], dict)
    with cd(pathlib_tmpdir.as_posix()):
        auto_detected_path = Lockfile()
        assert (
            auto_detected_path.path.absolute().as_posix()
            == lockfile.absolute().as_posix()
        )
        assert auto_detected_path["develop-editable"]["requests"] is not None
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_local_req(test_artifact):
    r = Requirement.from_line(test_artifact.as_posix())
    assert r.name == "environ_config"
    setup_dict = r.req.setup_info.as_dict()
    assert sorted(list(setup_dict.get("requires").keys())) == ["attrs"]
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_no_duplicate_egg_info():
    """When the package has 'src' directory, do not write egg-info in base
    dir."""
    base_dir = vistir.compat.Path(os.path.abspath(os.getcwd())).as_posix()
    r = Requirement.from_line("-e {}".format(base_dir))
    egg_info_name = "{}.egg-info".format(r.name.replace("-", "_"))
    distinfo_name = "{0}.dist-info".format(r.name.replace("-", "_"))

    def find_metadata(path):
        metadata_names = [
            os.path.join(path, name) for name in (egg_info_name, distinfo_name)
        ]
        if not os.path.isdir(path):
            return None
        pth = next(iter(pth for pth in metadata_names if os.path.isdir(pth)), None)
        if not pth:
            pth = next(
                iter(
                    pth
                    for pth in os.listdir(path)
                    if any(