How to use the johnnydep.lib.JohnnyDist function in johnnydep

To help you get started, we’ve selected a few johnnydep 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 wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_resolve_unresolvable(make_dist):
    make_dist(
        name="dist1", description="unresolvable", install_requires=["dist2<=0.1", "dist2>0.2"]
    )
    make_dist(name="dist2", version="0.1")
    make_dist(name="dist2", version="0.3")
    dist = JohnnyDist("dist1")
    data = dist.serialise(recurse=False, fields=["project_name", "summary", "requires"])
    assert data == [
        {
            "project_name": "dist1",
            "summary": "unresolvable",
            "requires": ["dist2<=0.1", "dist2>0.2"],
        }
    ]
    gen = flatten_deps(dist)
    assert next(gen) is dist
    with pytest.raises(CalledProcessError) as cm:
        next(gen)
    msg = "DistributionNotFound: No matching distribution found for dist2<=0.1,>0.2\n"
    assert cm.value.output.decode().endswith(msg)
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_requires(make_dist):
    make_dist(name="parent", install_requires=["child1", "child3[extra]", "child2<0.5"])
    make_dist(name="child1")
    make_dist(name="child2")
    make_dist(name="child3")
    jdist = JohnnyDist("parent")
    assert jdist.requires == ["child1", "child2<0.5", "child3[extra]"]
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_serialiser_pinned(make_dist):
    make_dist()
    jdist = JohnnyDist("jdtest[a]")
    assert jdist.serialise(format="pinned") == "jdtest[a]==0.1.2"
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_version_nonexisting(make_dist):
    # v0.404 does not exist in index
    make_dist()
    with pytest.raises(CalledProcessError) as cm:
        JohnnyDist("jdtest==0.404")
    msg = "DistributionNotFound: No matching distribution found for jdtest==0.404\n"
    assert cm.value.output.decode().endswith(msg)
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_pprint(make_dist, mocker):
    mocker.patch("johnnydep.lib.id", return_value=3735928559, create=True)
    mock_printer = mocker.MagicMock()
    make_dist()
    jdist = JohnnyDist("jdtest")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = ""
    mock_printer.text.assert_called_once_with(pretty)
    mock_printer.text.reset_mock()
    jdist = JohnnyDist("jdtest[a]~=0.1.2")
    jdist._repr_pretty_(mock_printer, cycle=False)
    pretty = ""
    mock_printer.text.assert_called_once_with(pretty)
    mock_printer.text.reset_mock()
    jdist._repr_pretty_(mock_printer, cycle=True)
    mock_printer.text.assert_called_once_with(repr(jdist))
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_version_latest_in_spec(make_dist):
    make_dist(version="1.2.3")
    make_dist(version="2.3.4")
    make_dist(version="3.4.5")
    jdist = JohnnyDist("jdtest<3")
    assert jdist.version_latest_in_spec == "2.3.4"
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_flatten_dist_with_deps(make_dist):
    make_dist(name="root", install_requires=["dep"])
    make_dist(name="dep")
    jdist = JohnnyDist("root")
    reqs = list(flatten_deps(jdist))
    [dist0, dist1] = reqs
    assert dist0 is jdist
    assert dist1.name == "dep"
github wimglenn / johnnydep / tests / test_lib.py View on Github external
def test_serialiser_with_children(make_dist):
    make_dist(name="a", install_requires=["b"])
    make_dist(name="b", version="2.0")
    jdist = JohnnyDist("A")
    assert jdist.serialise(format="pinned", recurse=True) == "a==0.1.2\nb==2.0"
github wimglenn / johnnydep / johnnydep / lib.py View on Github external
v=dist.version_latest_in_spec,
                    spec=str(spec) or "ANY",
                )
                yield dist
                break
        else:
            nameset = {dist.name for dist in dists}
            assert len(nameset) == 1  # name attributes were canonicalized by JohnnyDist.__init__
            [name] = nameset
            johnnydist.log.info("merged specs", name=name, spec=spec, extras=extras)
            req_string = "{name}{extras}{spec}".format(
                name=name,
                extras="[{}]".format(",".join(sorted(extras))) if extras else "",
                spec=spec,
            )
            dist = JohnnyDist(
                req_string=req_string,
                index_url=johnnydist.index_url,
                env=johnnydist.env,
                extra_index_url=johnnydist.extra_index_url,
            )
            dist.required_by = required_by
            yield dist
            # TODO: check if this new version causes any new reqs!!
github wimglenn / johnnydep / johnnydep / lib.py View on Github external
def children(self):
        """my immediate deps, as a tuple of johnnydists"""
        if not self._recursed:
            self.log.debug("populating dep tree")
            for dep in self.requires:
                JohnnyDist(
                    req_string=dep,
                    parent=self,
                    index_url=self.index_url,
                    env=self.env,
                    extra_index_url=self.extra_index_url,
                )
            self._recursed = True
        return super(JohnnyDist, self).children