Skip to content

Instantly share code, notes, and snippets.

@MarcoGorelli
Last active September 3, 2024 13:26
Show Gist options
  • Save MarcoGorelli/ec7b3d0c27eb08bca4568a8841d80454 to your computer and use it in GitHub Desktop.
Save MarcoGorelli/ec7b3d0c27eb08bca4568a8841d80454 to your computer and use it in GitHub Desktop.
get_size_of.py
"""
Example usage:
python3 get_size_of.py polars altair
"""
import sys
import subprocess
import os
args = ' '.join(sys.argv[1:])
def get_size(start_path = '.'):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
# skip if it is symbolic link
if not os.path.islink(fp):
total_size += os.path.getsize(fp)
return total_size // 1024**2
os.system('rm -rf .tmpvenv')
os.system('python3.11 -m venv .tmpvenv')
size = get_size('.tmpvenv')
print('empty venv size', size)
os.system(f'.tmpvenv/bin/python -m pip install -U {args}')
new_size = get_size('.tmpvenv')
size = new_size - size
print('final result: ', size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment