import zipfile, os, glob

target = '/workspace/.local/lib/python3.11/site-packages'
os.makedirs(target, exist_ok=True)

wheels = sorted(glob.glob('/workspace/*.whl'))
print(f'Found {len(wheels)} wheel files')

for whl in wheels:
    name = os.path.basename(whl)
    size = os.path.getsize(whl)
    print(f'Installing {name} ({size//1024}KB)...')
    try:
        with zipfile.ZipFile(whl, 'r') as z:
            z.extractall(target)
        print(f'  -> done')
    except Exception as e:
        print(f'  -> ERROR: {e}')

print()
print('Installed packages:')
pkgs = sorted([d for d in os.listdir(target)
               if not d.endswith('.dist-info') and not d.endswith('.data')
               and not d.startswith('_') and os.path.isdir(os.path.join(target, d))])
for p in pkgs:
    print(f'  {p}')
