[object Object]

← back to Exo

add script to calculate pipsize

5521dcbffd123e9894a86717b0634844abc7a96d · 2024-10-02 23:04:57 +0400 · Alex Cheema

Files touched

Diff

commit 5521dcbffd123e9894a86717b0634844abc7a96d
Author: Alex Cheema <alexcheema123@gmail.com>
Date:   Wed Oct 2 23:04:57 2024 +0400

    add script to calculate pipsize
---
 extra/pipsize.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/extra/pipsize.py b/extra/pipsize.py
new file mode 100644
index 00000000..a3d458de
--- /dev/null
+++ b/extra/pipsize.py
@@ -0,0 +1,33 @@
+import os
+import pkg_resources
+from tabulate import tabulate
+
+def calc_container(path):
+  total_size = 0
+  for dirpath, dirnames, filenames in os.walk(path):
+    for f in filenames:
+      fp = os.path.join(dirpath, f)
+      total_size += os.path.getsize(fp)
+  return total_size
+
+dists = [d for d in pkg_resources.working_set]
+package_sizes = []
+
+for dist in dists:
+  try:
+    path = os.path.join(dist.location, dist.project_name)
+    size = calc_container(path)
+    if size / (1024 * 1024) > 0.1:  # Only include packages larger than 0.1 MB
+      package_sizes.append((dist.project_name, size))
+  except OSError:
+    print(f'{dist.project_name} no longer exists')
+
+# Sort packages by size in descending order
+package_sizes.sort(key=lambda x: x[1], reverse=True)
+
+# Convert sizes to MB and prepare data for tabulation
+table_data = [(name, f"{size/(1024*1024):.2f}") for name, size in package_sizes]
+
+# Print sorted packages in a tabular format
+headers = ["Package", "Size (MB)"]
+print(tabulate(table_data, headers=headers, tablefmt="grid"))

← 3ed8a52a Fixed the retry  ·  back to Exo  ·  clean up download progress 4746ffdd →