Skip to content

Commit 4839de2

Browse files
author
Ruinong Tian
committed
revert _generate_staleness_report_per_image change
1 parent 7b941ce commit 4839de2

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

src/package_report.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,10 @@ def _generate_staleness_report_per_image(
7373
# Use previous month to get full month of data
7474
previous_month = (datetime.now() - relativedelta(months=1)).strftime("%Y-%m")
7575
pkg_list = list(package_versions_in_upstream.keys())
76-
77-
# Process packages individually to handle exceptions per package
78-
conda_download_stats = {}
79-
for pkg in pkg_list:
80-
try:
81-
# Suppress FutureWarning from pandas so it doesn't show in report
82-
with warnings.catch_warnings():
83-
warnings.filterwarnings("ignore", category=FutureWarning)
84-
# Get stats for single package
85-
pkg_stats = overall([pkg], month=previous_month)
86-
conda_download_stats[pkg] = pkg_stats.get(pkg, "N/A")
87-
except ValueError as e:
88-
conda_download_stats[pkg] = "N/A"
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)
8980

9081
for package in package_versions_in_upstream:
9182
version_in_sagemaker_distribution = str(target_packages_match_spec_out[package].get("version")).removeprefix(
@@ -105,23 +96,12 @@ def _generate_staleness_report_per_image(
10596
}
10697
)
10798

108-
def sort_key(x):
109-
# First key: False for stale packages (they start with "${\\color")
110-
is_current = not x["package"].startswith("${\\color")
111-
112-
# Second key: downloads count, with "N/A" treated as lowest priority
113-
downloads = x["downloads"]
114-
if downloads == "N/A":
115-
download_value = float('-inf') # Put N/A at the bottom
116-
else:
117-
try:
118-
download_value = float(downloads)
119-
except (ValueError, TypeError):
120-
download_value = float('-inf') # Handle any other non-numeric values
121-
122-
return (is_current, download_value)
123-
124-
staleness_report_rows.sort(key=sort_key, reverse=True)
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+
)
125105
print(
126106
create_markdown_table(
127107
[

0 commit comments

Comments
 (0)