about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/python/catch_conflicts/catch_conflicts.py
blob: d5c99e64751c781c1a7afdf78f7199083c0ffb43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from importlib.metadata import PathDistribution
from pathlib import Path
import collections
import sys


do_abort = False
packages = collections.defaultdict(list)


for path in sys.path:
    for dist_info in Path(path).glob("*.dist-info"):
        dist = PathDistribution(dist_info)

        packages[dist._normalized_name].append(
            f"{dist._normalized_name} {dist.version} ({dist._path})"
        )


for name, duplicates in packages.items():
    if len(duplicates) > 1:
        do_abort = True
        print("Found duplicated packages in closure for dependency '{}': ".format(name))
        for duplicate in duplicates:
            print(f"\t{duplicate}")

if do_abort:
    print("")
    print(
        "Package duplicates found in closure, see above. Usually this "
        "happens if two packages depend on different version "
        "of the same dependency."
    )
    sys.exit(1)