Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVMScript] More accurate hints for ImportError #13662

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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