How to use the requirementslib.models.requirements.Requirement.from_pipfile 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
# 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_local_editable_ref(monkeypatch):
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        path = Path(ARTIFACTS_DIR) / "git/requests"
        req = Requirement.from_pipfile(
            "requests", {"editable": True, "git": path.as_uri(), "ref": "2.18.4"}
        )
        assert req.as_line() == "-e git+{0}@2.18.4#egg=requests".format(path.as_uri())
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_convert_from_pipfile_vcs(monkeypatch):
    """ssh VCS links should be converted correctly"""
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        pkg_name = "shellingham"
        pkg_pipfile = {"editable": True, "git": "git@github.com:sarugaku/shellingham.git"}
        req = Requirement.from_pipfile(pkg_name, pkg_pipfile)
        assert (
            req.req.link.url
            == "git+ssh://git@github.com/sarugaku/shellingham.git#egg=shellingham"
        )
github sarugaku / requirementslib / tests / unit / test_requirements.py View on Github external
def test_convert_from_pipfile(monkeypatch, requirement, expected):
    with monkeypatch.context() as m:
        m.setattr(pip_shims.shims, "unpack_url", mock_unpack)
        m.setattr(SetupInfo, "get_info", mock_run_requires)
        m.setattr(Requirement, "run_requires", mock_run_requires)
        pkg_name = next(iter(requirement.keys()))
        pkg_pipfile = requirement[pkg_name]
        req = Requirement.from_pipfile(pkg_name, pkg_pipfile)
        if " (" in expected and expected.endswith(")"):
            # To strip out plette[validation] (>=0.1.1)
            expected = expected.replace(" (", "").rstrip(")")
        assert req.as_line() == expected.lower() if "://" not in expected else expected
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
def test_extras(pathlib_tmpdir, setup_py_dir, setup_py_name, extras, dependencies):
    """Test named extras as a dependency."""
    setup_dir = pathlib_tmpdir.joinpath("test_package")
    shutil.copytree(setup_py_dir.joinpath(setup_py_name).as_posix(), setup_dir.as_posix())
    assert setup_dir.is_dir()
    pipfile_entry = {
        "path": "./{0}".format(setup_dir.name),
        "extras": extras,
        "editable": True,
    }
    setup_dict = None
    with vistir.contextmanagers.cd(pathlib_tmpdir.as_posix()):
        r = Requirement.from_pipfile("test-package", pipfile_entry)
        assert r.name == "test-package"
        r.req.setup_info.get_info()
        setup_dict = r.req.setup_info.as_dict()
        assert sorted(list(setup_dict.get("requires").keys())) == dependencies
github sarugaku / requirementslib / tests / unit / test_setup_info.py View on Github external
install_requires=["raven==5.32.0"],
    extras_require={
        'PDF': ["socks"]
    }
)
    """.strip()
        )
    )
    setup_dict = None
    with vistir.contextmanagers.cd(setup_dir.as_posix()):
        pipfile_entry = {
            "path": os.path.abspath(os.curdir),
            "editable": True,
            "extras": ["socks"],
        }
        r = Requirement.from_pipfile("e1839a8", pipfile_entry)
        r.run_requires()
        setup_dict = r.req.setup_info.as_dict()
        assert sorted(list(setup_dict.get("requires").keys())) == ["raven"]