"""Compare the dist file created by a migrated package to one created by the original.""" import argparse import glob import os import shutil import subprocess import sys import tarfile import zipfile parser = argparse.ArgumentParser() parser.add_argument(dest='source_dir', help="Source Directory") parser.add_argument(dest='target_dir', help="Target Directory") parser.add_argument(dest='dist_name', help="Dist name") args = parser.parse_args() subprocess.run([sys.executable, '-m', 'pip', 'install', 'build']) def build_file(dirname): orig_dir = os.getcwd() os.chdir(dirname) if os.path.exists('dist'): shutil.rmtree('dist') subprocess.run([sys.executable, '-m', 'build', f'--{args.dist_name}']) os.chdir(orig_dir) def get_tar_names(dirname): dist_file = glob.glob(f'{dirname}/dist/*.tar.gz')[0] tarf = tarfile.open(dist_file, 'r:gz') return set(tarf.getnames()) def get_zip_names(dirname): wheel_file = glob.glob(f'{dirname}/dist/*.whl')[0] with zipfile.ZipFile(wheel_file, 'r') as f: return set(f.namelist()) def filter_file(path): if 'egg-info' in path: return True _, ext = os.path.splitext(path) if not ext: return True if os.path.basename(path) in [path, 'setup.py', 'setup.cfg', 'MANIFEST.in']: return True return False build_file(args.source_dir) build_file(args.target_dir) if args.dist_name == 'sdist': source_names = get_tar_names(args.source_dir) target_names = get_tar_names(args.target_dir) else: source_names = get_zip_names(args.source_dir) target_names = get_zip_names(args.target_dir) removed = source_names - target_names if removed: print('Removed_files:') [print(f'{f}\n') for f in removed if not filter_file(f)] added = target_names - source_names if added: print('\nAdded files:') [print(f'{f}\n') for f in added if not filter_file(f)]