at 24.05-pre 899 B view raw
1from importlib.metadata import PathDistribution 2from pathlib import Path 3import collections 4import sys 5 6 7do_abort = False 8packages = collections.defaultdict(list) 9 10 11for path in sys.path: 12 for dist_info in Path(path).glob("*.dist-info"): 13 dist = PathDistribution(dist_info) 14 15 packages[dist._normalized_name].append( 16 f"{dist._normalized_name} {dist.version} ({dist._path})" 17 ) 18 19 20for name, duplicates in packages.items(): 21 if len(duplicates) > 1: 22 do_abort = True 23 print("Found duplicated packages in closure for dependency '{}': ".format(name)) 24 for duplicate in duplicates: 25 print(f"\t{duplicate}") 26 27if do_abort: 28 print("") 29 print( 30 "Package duplicates found in closure, see above. Usually this " 31 "happens if two packages depend on different version " 32 "of the same dependency." 33 ) 34 sys.exit(1)