Skip to content

Commit

Permalink
[TVMScript] More accurate hints for ImportError (apache#13662)
Browse files Browse the repository at this point in the history
  • Loading branch information
standbyme authored and fzi-peccia committed Mar 27, 2023
1 parent a6337ca commit 9c16365
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/tvm/script/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,20 @@ def _get_pygments_style(
if version.parse(pygments.__version__) < version.parse("2.4.0"):
raise ImportError("Required Pygments version >= 2.4.0 but got " + pygments.__version__)
except ImportError as err:
if err.name == "packaging":
name = "packaging"
elif err.name == "pygments":
name = "Pygments>=2.4.0"
else:
raise ValueError(f'Package "{err.name}" should not be used')

with warnings.catch_warnings():
warnings.simplefilter("once", UserWarning)
install_cmd = sys.executable + ' -m pip install "Pygments>=2.4.0" --upgrade --user'
install_cmd = sys.executable + f' -m pip install "{name}" --upgrade --user'
warnings.warn(
str(err)
+ "\n"
+ "To print highlighted TVM script, please install Pygments:\n"
+ f"To print highlighted TVM script, please install {name}:\n"
+ install_cmd,
category=UserWarning,
)
Expand Down

0 comments on commit 9c16365

Please sign in to comment.