1
1
import json
2
2
import os
3
+ import warnings
4
+ from datetime import datetime
3
5
from itertools import islice
4
6
5
7
import boto3
6
8
import conda .cli .python_api
7
9
from conda .models .match_spec import MatchSpec
10
+ from condastats .cli import overall
11
+ from dateutil .relativedelta import relativedelta
8
12
9
13
from config import _image_generator_configs
10
14
from dependency_upgrader import _dependency_metadata
@@ -64,6 +68,16 @@ def _generate_staleness_report_per_image(
64
68
):
65
69
print ("\n # Staleness Report: " + str (version ) + "(" + image_config ["image_type" ] + ")\n " )
66
70
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
+
67
81
for package in package_versions_in_upstream :
68
82
version_in_sagemaker_distribution = str (target_packages_match_spec_out [package ].get ("version" )).removeprefix (
69
83
"=="
@@ -78,11 +92,24 @@ def _generate_staleness_report_per_image(
78
92
"package" : package_string ,
79
93
"version_in_sagemaker_distribution" : version_in_sagemaker_distribution ,
80
94
"latest_relavant_version" : package_versions_in_upstream [package ],
95
+ "downloads" : conda_download_stats [package ],
81
96
}
82
97
)
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
+ )
83
105
print (
84
106
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
+ ],
86
113
staleness_report_rows ,
87
114
)
88
115
)
0 commit comments