This repository was archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
highlight tvm script with pygment on vscode dark theme #185
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c58187
feat: highlight tvm script with pygment on vscode dark theme
ganler c9b0d35
feat: add light theme (Jupyter style)
ganler e8fa6ea
try: add Pygment dependency to gen_requirements.py
ganler 5d100ea
fix: gen_requirement.py ordered by package name
ganler 7d29490
fix: Pygment -> Pygements
ganler 64ee682
Merge branch 'script-highlight' of github.com:ganler/relax into scrip…
ganler 38968f2
refact: refine highlighted printer API
ganler 924d2d4
fix(pylint): line too long
ganler a61644e
refact(doc): add Pygments style url and Pygment -> Pygements
ganler 4ff21e4
feat: add .show syntax sugar
ganler 49851d6
feat: enable .script and .show method for relax.Function
ganler 52395ae
fix: typo Pygements -> Pygment
ganler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |
| ( | ||
| "Base requirements needed to install tvm", | ||
| [ | ||
| "Pygments", | ||
| "attrs", | ||
| "cloudpickle", | ||
| "decorator", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| """Highlight printed TVM script. | ||
| """ | ||
|
|
||
| from typing import Union | ||
|
|
||
| from pygments import highlight | ||
| from pygments.lexers import Python3Lexer | ||
| from pygments.formatters import Terminal256Formatter | ||
| from pygments.style import Style | ||
| from pygments.token import Keyword, Name, Comment, String, Number, Operator | ||
|
|
||
| from tvm.ir import IRModule | ||
| from tvm.tir import PrimFunc | ||
|
|
||
|
|
||
| class VSCDark(Style): | ||
| """A VSCode-Dark-like Pygments style configuration""" | ||
|
|
||
| styles = { | ||
| Keyword: "bold #c586c0", | ||
| Keyword.Namespace: "#4ec9b0", | ||
| Keyword.Type: "#82aaff", | ||
| Name.Function: "bold #dcdcaa", | ||
| Name.Class: "bold #569cd6", | ||
| Name.Decorator: "italic #fe4ef3", | ||
| String: "#ce9178", | ||
| Number: "#b5cea8", | ||
| Operator: "#bbbbbb", | ||
| Operator.Word: "#569cd6", | ||
| Comment: "italic #6a9956", | ||
| } | ||
|
|
||
|
|
||
| class JupyterLight(Style): | ||
| """A Jupyter-Notebook-like Pygments style configuration""" | ||
|
|
||
| styles = { | ||
| Keyword: "bold #008000", | ||
| Keyword.Type: "nobold #008000", | ||
| Name.Function: "#0000FF", | ||
| Name.Class: "bold #0000FF", | ||
| Name.Decorator: "#AA22FF", | ||
| String: "#BA2121", | ||
| Number: "#008000", | ||
| Operator: "bold #AA22FF", | ||
| Operator.Word: "bold #008000", | ||
| Comment: "italic #007979", | ||
| } | ||
|
|
||
|
|
||
| def cprint(printable: Union[IRModule, PrimFunc], style="light") -> None: | ||
| """ | ||
| Print highlighted TVM script string with Pygments | ||
|
|
||
| Parameters | ||
| ---------- | ||
| printable : Union[IRModule, PrimFunc] | ||
| The TVM script to be printed | ||
| style : str, optional | ||
| Style of the printed script | ||
|
|
||
| Notes | ||
| ----- | ||
| The style parameter follows the Pygments style names or Style objects. Two | ||
ganler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| built-in styles are extended: "light" (default) and "dark". Other styles | ||
| can be found in https://pygments.org/styles/ | ||
| """ | ||
| if style == "light": | ||
| style = JupyterLight | ||
| elif style == "dark": | ||
| style = VSCDark | ||
| print(highlight(printable.script(), Python3Lexer(), Terminal256Formatter(style=style))) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.