Exemple #1
0
def test_idempotency(converter, path):
    root1 = converter.load(path)
    reqs1 = Requirement.from_graph(graph=Graph(root1), lock=False)

    content1 = converter.dumps(reqs1, project=root1)

    root2 = converter.loads(content1)
    reqs2 = Requirement.from_graph(graph=Graph(root2), lock=False)

    content2 = converter.dumps(reqs2, project=root2, content=content1)

    assert content1 == content2
Exemple #2
0
def check(root, resolved=True, missed=None, **deps):
    resolver = Resolver(
        graph=Graph(root),
        mutator=Mutator(),
    )
    with patch(
            target='dephell.controllers.dependency.get_repo',
            return_value=resolver.graph._roots[0].repo,
    ):
        result = resolver.resolve(debug=True, silent=True)

    reqs = Requirement.from_graph(resolver.graph, lock=True)
    reqs = {req.name: req for req in reqs}

    try:
        assert result is resolved
    except AssertionError:
        if result is False:
            print(analyze_conflict(resolver=resolver))
        raise

    assert resolver.graph.applied

    for name in sorted(deps.keys()):
        if name not in reqs:
            raise AssertionError('Dep not in graph: ' + name)
        print(name, reqs[name].version)

    for name, version in deps.items():
        assert reqs[name].version == version, '{}: {} != {}'.format(
            name, reqs[name].version, version)

    if missed:
        for name in missed:
            assert name not in reqs
def check(root, conflict, mutations):
    resolver = Resolver(
        graph=Graph(root),
        mutator=Mutator(),
    )
    with patch(
        target='dephell.controllers.dependency.get_repo',
        return_value=resolver.graph._roots[0].repo,
    ):
        resolver.resolve(debug=True)

    graph = resolver.graph
    graph.conflict = graph.get(conflict)
    assert graph.conflict is not None

    mutator = Mutator()
    for _ in range(10):
        groups = mutator.mutate(graph)
        # if cannot mutate
        if groups is None:
            break
        for group in groups:
            dep = graph.get(group.name)
            dep.group = group

    assert mutator.mutations == mutations
Exemple #4
0
def fast_filter(root, *, deep=True):
    resolver = Resolver(
        graph=Graph(root),
        mutator=Mutator(),
    )
    resolver.graph.fast_apply()
    resolver.apply_envs(envs={'main'}, deep=deep)
    reqs = Requirement.from_graph(resolver.graph, lock=False)
    return {req.name: req for req in reqs}
Exemple #5
0
def test_load_dump_load_deps(converter, path):
    root1 = converter.load(path)
    reqs1 = Requirement.from_graph(graph=Graph(root1), lock=False)

    content = converter.dumps(reqs1, project=root1)
    root2 = converter.loads(content)
    reqs2 = Requirement.from_graph(graph=Graph(root2), lock=False)

    map1 = {req.name: req for req in reqs1}
    map2 = {req.name: req for req in reqs2}
    assert set(map1) == set(map2), 'loaded and dumped different deps set'

    # check all params
    exclude = {'sources', 'description'}
    if isinstance(converter, converters.EggInfoConverter):
        exclude.add('git')
    for name, req1 in map1.items():
        req2 = map2[name]
        d1 = {k: v for k, v in req1 if k not in exclude}
        d2 = {k: v for k, v in req2 if k not in exclude}
        assert d1 == d2

    # check warehouse URL
    for name, req1 in map1.items():
        req2 = map2[name]
        if isinstance(req1.dep.repo, RepositoriesRegistry):
            assert len(req1.dep.repo.repos) == len(req2.dep.repo.repos)
            for repo1, repo2 in zip(req1.dep.repo.repos, req2.dep.repo.repos):
                assert repo1.name == repo2.name
                assert repo1.url == repo2.url

    # exactly one dev or main env should be specified for dep
    for name, req1 in map1.items():
        req2 = map2[name]
        assert req1.is_dev is not req1.is_main
        assert req2.is_dev is not req2.is_main

    # check envs (extras)
    for name, req1 in map1.items():
        req2 = map2[name]
        assert req1.dep.envs == req2.dep.envs
Exemple #6
0
def merge(*roots, merged=True, deps=None):
    graph = Graph()
    for root in roots:
        graph.add(root)
    resolver = Resolver(graph=graph, mutator=Mutator())
    resolved = resolver.resolve(level=1)

    try:
        assert merged == resolved
    except AssertionError:
        if resolved is False:
            print(analyze_conflict(resolver=resolver))
        raise

    if deps:
        for dep in deps:
            assert dep in resolver.graph
        names = set(resolver.graph.names) - set(root.name for root in roots)
        assert names == set(deps)

    return resolver
Exemple #7
0
def test_load_dump_load_metainfo(converter, path, exclude):
    root1 = converter.load(path)
    reqs1 = Requirement.from_graph(graph=Graph(root1), lock=False)

    content = converter.dumps(reqs1, project=root1)
    root2 = converter.loads(content)

    root1.dependencies = None
    root2.dependencies = None
    for field in exclude:
        setattr(root1, field, None)
        setattr(root2, field, None)
    assert attr.asdict(root1) == attr.asdict(root2)
def test_patch_imports(temp_path: Path):
    (temp_path / 'project').mkdir()
    (temp_path / 'project' / '__init__.py').write_text('import requests\nimport django')
    (temp_path / 'project' / 'vendor' / 'requests').mkdir(parents=True)
    (temp_path / 'project' / 'vendor' / 'requests' / '__init__.py').touch()

    config = Config()
    config.attach(dict(project=str(temp_path)))
    package = PackageRoot(name='project', path=temp_path)
    root = RootDependency(raw_name='project', package=package)
    resolver = Resolver(
        graph=Graph(root),
        mutator=Mutator(),
    )
    command = VendorImportCommand(argv=[], config=config)
    command._patch_imports(
        resolver=resolver,
        output_path=temp_path / 'project' / 'vendor',
    )

    expected = 'import project.vendor.requests as requests\nimport django'
    assert (temp_path / 'project' / '__init__.py').read_text() == expected
Exemple #9
0
"""
Замена оригинальной команде `dephell convert deps`
тк иногда с ней бывают проблемы и она падает с TypeError
"""
import pathlib

from dephell import converters
from dephell.controllers import Graph
from dephell.models import Requirement

BASEDIR = pathlib.Path(__file__).parent

if __name__ == '__main__':
    pc = converters.PoetryConverter()
    spc = converters.SetupPyConverter()

    root = pc.load(BASEDIR.joinpath('pyproject.toml'))
    if root.readme.markup == 'md':
        # SetupPyConverter принудительно конвертирует README в rst
        # чтобы этого не допустить - обманываем его
        root.readme.markup = 'rst'

    reqs = Requirement.from_graph(graph=Graph(root), lock=False)
    content = spc.dumps(reqs, project=root)

    BASEDIR.joinpath('setup.py').write_text(content)

    print('setup.py was updated successfully')