|
1 | 1 | import json |
2 | 2 | import os |
| 3 | +import subprocess |
3 | 4 | import warnings |
4 | 5 | from datetime import datetime |
5 | 6 | from itertools import islice |
6 | 7 |
|
7 | 8 | import boto3 |
8 | | -import conda.cli.python_api |
9 | 9 | from conda.models.match_spec import MatchSpec |
10 | 10 | from condastats.cli import overall |
11 | 11 | from dateutil.relativedelta import relativedelta |
@@ -39,11 +39,18 @@ def _get_package_versions_in_upstream(target_packages_match_spec_out, target_ver |
39 | 39 | continue |
40 | 40 | channel = match_spec_out.get("channel").channel_name |
41 | 41 | subdir_filter = "[subdir=" + match_spec_out.get("subdir") + "]" |
42 | | - search_result = conda.cli.python_api.run_command( |
43 | | - "search", channel + "::" + package + ">=" + str(package_version) + subdir_filter, "--json" |
44 | | - ) |
45 | | - # Load the first result as json. The API sends a json string inside an array |
46 | | - package_metadata = json.loads(search_result[0])[package] |
| 42 | + try: |
| 43 | + search_result = subprocess.run( |
| 44 | + ["conda", "search", channel + "::" + package + ">=" + str(package_version) + subdir_filter, "--json"], |
| 45 | + capture_output=True, |
| 46 | + text=True, |
| 47 | + check=True, |
| 48 | + ) |
| 49 | + # Load the result as json |
| 50 | + package_metadata = json.loads(search_result.stdout)[package] |
| 51 | + except (subprocess.CalledProcessError, json.JSONDecodeError, KeyError) as e: |
| 52 | + print(f"Error searching for package {package}: {str(e)}") |
| 53 | + continue |
47 | 54 | # Response is of the structure |
48 | 55 | # { 'package_name': [{'url':<someurl>, 'dependencies': <List of dependencies>, 'version': |
49 | 56 | # <version number>}, ..., {'url':<someurl>, 'dependencies': <List of dependencies>, 'version': |
@@ -90,7 +97,7 @@ def _generate_staleness_report_per_image( |
90 | 97 | package_string = ( |
91 | 98 | package |
92 | 99 | if version_in_sagemaker_distribution == package_versions_in_upstream[package] |
93 | | - else "${\color{red}" + package + "}$" |
| 100 | + else "${\\color{red}" + package + "}$" |
94 | 101 | ) |
95 | 102 |
|
96 | 103 | if download_stats: |
@@ -170,7 +177,7 @@ def _validate_new_package_size(new_package_total_size, target_total_size, image_ |
170 | 177 | + str(new_package_total_size_percent) |
171 | 178 | + "%)" |
172 | 179 | ) |
173 | | - new_package_total_size_percent_string = "${\color{red}" + str(new_package_total_size_percent) + "}$" |
| 180 | + new_package_total_size_percent_string = "${\\color{red}" + str(new_package_total_size_percent) + "}$" |
174 | 181 |
|
175 | 182 | print( |
176 | 183 | "The total size of newly introduced Python packages is " |
@@ -276,10 +283,13 @@ def _generate_python_package_dependency_report(image_config, base_version_dir, t |
276 | 283 | for package, version in new_packages.items(): |
277 | 284 | try: |
278 | 285 | # Pull package metadata from conda-forge and dump into json file |
279 | | - search_result = conda.cli.python_api.run_command( |
280 | | - "search", "-c", "conda-forge", f"{package}=={version}", "--json" |
| 286 | + search_result = subprocess.run( |
| 287 | + ["conda", "search", "-c", "conda-forge", f"{package}=={version}", "--json"], |
| 288 | + capture_output=True, |
| 289 | + text=True, |
| 290 | + check=True, |
281 | 291 | ) |
282 | | - package_metadata = json.loads(search_result[0])[package][0] |
| 292 | + package_metadata = json.loads(search_result.stdout)[package][0] |
283 | 293 | results[package] = {"version": package_metadata["version"], "depends": package_metadata["depends"]} |
284 | 294 | except Exception as e: |
285 | 295 | print(f"Error in report generation: {str(e)}") |
|
0 commit comments