@@ -64,19 +64,20 @@ def _get_package_versions_in_upstream(target_packages_match_spec_out, target_ver
6464
6565
6666def _generate_staleness_report_per_image (
67- package_versions_in_upstream , target_packages_match_spec_out , image_config , version
67+ package_versions_in_upstream , target_packages_match_spec_out , image_config , version , download_stats
6868):
6969 print ("\n # Staleness Report: " + str (version ) + "(" + image_config ["image_type" ] + ")\n " )
7070 staleness_report_rows = []
7171
72- # Get conda download statistics for all installed packages
73- # Use the month before last to get full month of data
74- previous_month = (datetime .now () - relativedelta (months = 2 )).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 )
72+ if download_stats :
73+ # Get conda download statistics for all installed packages
74+ # Use the month before last to get full month of data
75+ previous_month = (datetime .now () - relativedelta (months = 2 )).strftime ("%Y-%m" )
76+ pkg_list = list (package_versions_in_upstream .keys ())
77+ # Suppress FutureWarning from pandas so it doesn't show in report
78+ with warnings .catch_warnings ():
79+ warnings .filterwarnings ("ignore" , category = FutureWarning )
80+ conda_download_stats = overall (pkg_list , month = previous_month )
8081
8182 for package in package_versions_in_upstream :
8283 version_in_sagemaker_distribution = str (target_packages_match_spec_out [package ].get ("version" )).removeprefix (
@@ -87,32 +88,45 @@ def _generate_staleness_report_per_image(
8788 if version_in_sagemaker_distribution == package_versions_in_upstream [package ]
8889 else "${\color{red}" + package + "}$"
8990 )
90- staleness_report_rows .append (
91- {
92- "package" : package_string ,
93- "version_in_sagemaker_distribution" : version_in_sagemaker_distribution ,
94- "latest_relavant_version" : package_versions_in_upstream [package ],
95- "downloads" : conda_download_stats [package ],
96- }
97- )
9891
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- )
105- print (
106- create_markdown_table (
107- [
108- "Package" ,
109- "Current Version in the Distribution image" ,
110- "Latest Relevant Version in " "Upstream" ,
111- "Downloads (Conda, previous month)" ,
112- ],
113- staleness_report_rows ,
92+ if download_stats :
93+ # Get download count with error handling
94+ try :
95+ download_count = conda_download_stats [package ]
96+ except (KeyError , TypeError ):
97+ download_count = 0
98+
99+ staleness_report_rows .append (
100+ {
101+ "package" : package_string ,
102+ "version_in_sagemaker_distribution" : version_in_sagemaker_distribution ,
103+ "latest_relavant_version" : package_versions_in_upstream [package ],
104+ "downloads" : download_count ,
105+ }
106+ )
107+ else :
108+ staleness_report_rows .append (
109+ {
110+ "package" : package_string ,
111+ "version_in_sagemaker_distribution" : version_in_sagemaker_distribution ,
112+ "latest_relavant_version" : package_versions_in_upstream [package ],
113+ }
114+ )
115+
116+ markdown_table_columns = [
117+ "Package" ,
118+ "Current Version in the Distribution image" ,
119+ "Latest Relevant Version in " "Upstream" ,
120+ ]
121+ if download_stats :
122+ markdown_table_columns .append ("Downloads (Conda, previous month)" )
123+ staleness_report_rows .sort (
124+ key = lambda x : (
125+ not x ["package" ].startswith ("${\\ color" ), # Stale packages at top of list
126+ - x ["downloads" ], # Sorted by downloads
127+ )
114128 )
115- )
129+ print ( create_markdown_table ( markdown_table_columns , staleness_report_rows ) )
116130
117131
118132def _get_installed_package_versions_and_conda_versions (
@@ -281,7 +295,11 @@ def generate_package_staleness_report(args):
281295 latest_package_versions_in_upstream ,
282296 ) = _get_installed_package_versions_and_conda_versions (image_config , target_version_dir , target_version )
283297 _generate_staleness_report_per_image (
284- latest_package_versions_in_upstream , target_packages_match_spec_out , image_config , target_version
298+ latest_package_versions_in_upstream ,
299+ target_packages_match_spec_out ,
300+ image_config ,
301+ target_version ,
302+ args .download_stats ,
285303 )
286304
287305
0 commit comments