Skip to content

Commit dcce388

Browse files
Add download stats to staleness report (#622)
1 parent 13ba0a2 commit dcce388

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ dependencies:
1414
- black
1515
- isort
1616
- pre-commit
17+
- condastats

src/package_report.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import json
22
import os
3+
import warnings
4+
from datetime import datetime
35
from itertools import islice
46

57
import boto3
68
import conda.cli.python_api
79
from conda.models.match_spec import MatchSpec
10+
from condastats.cli import overall
11+
from dateutil.relativedelta import relativedelta
812

913
from config import _image_generator_configs
1014
from dependency_upgrader import _dependency_metadata
@@ -64,6 +68,16 @@ def _generate_staleness_report_per_image(
6468
):
6569
print("\n# Staleness Report: " + str(version) + "(" + image_config["image_type"] + ")\n")
6670
staleness_report_rows = []
71+
72+
# Get conda download statistics for all installed packages
73+
# Use previous month to get full month of data
74+
previous_month = (datetime.now() - relativedelta(months=1)).strftime("%Y-%m")
75+
pkg_list = list(package_versions_in_upstream.keys())
76+
# Suppress FutureWarning from pandas so it doesn't show in report
77+
with warnings.catch_warnings():
78+
warnings.filterwarnings("ignore", category=FutureWarning)
79+
conda_download_stats = overall(pkg_list, month=previous_month)
80+
6781
for package in package_versions_in_upstream:
6882
version_in_sagemaker_distribution = str(target_packages_match_spec_out[package].get("version")).removeprefix(
6983
"=="
@@ -78,11 +92,24 @@ def _generate_staleness_report_per_image(
7892
"package": package_string,
7993
"version_in_sagemaker_distribution": version_in_sagemaker_distribution,
8094
"latest_relavant_version": package_versions_in_upstream[package],
95+
"downloads": conda_download_stats[package],
8196
}
8297
)
98+
99+
staleness_report_rows.sort(
100+
key=lambda x: (
101+
not x["package"].startswith("${\\color"), # Stale packages at top of list
102+
-x["downloads"], # Sorted by downloads
103+
)
104+
)
83105
print(
84106
create_markdown_table(
85-
["Package", "Current Version in the Distribution image", "Latest Relevant Version in " "Upstream"],
107+
[
108+
"Package",
109+
"Current Version in the Distribution image",
110+
"Latest Relevant Version in " "Upstream",
111+
"Downloads (Conda, previous month)",
112+
],
86113
staleness_report_rows,
87114
)
88115
)

0 commit comments

Comments
 (0)