This PR enables ruff pyupgrade (UP) rules with py310 target, auto-fixing
~5600 annotation modernizations (PEP 585 generics, PEP 604 unions,
deprecated typing imports).
Also removes from __future__ import annotations from ir/module.py and
rmsnorm.py, bumps requires-python to >=3.10, and removes absolute_import
aliases from topi/contrib files.
* [TVMScript] Optionally use `ruff format` instead of `black`
The `ruff format` tool is significantly faster than the `black`
formatter. For some particularly long TVMScript modules, using it can
reduce the time required to show a formatted module from ~5 minutes to
~1 minute. This commit updates the `.show()` function to apply the
optionally formatting using `ruff format` if available, falling back
to `black` otherwise.
* Fix lint error
Current `cprint` allows `PrimFunc` and `IRModule` as input. However,
after the fragment printing enabled by @junrushao, we can make it robust
to support any Objects that have method `script`
* [TVMScript] Improvements tvm.script.highlight
- Automatically use "black" formatter if available.
- Allow overrides of pygmentize style based on environment variable
`TVM_PYGMENTIZE_STYLE`.
- Forwarded `black_format` argument from `show` method to `cprint`
Previously we use ANSI color sequences to highlight TVM script. In jupyter notebook environments, such color sequence will be recoginized and translated to corresponding HTML to display things.
This works fine for most notebook environments (including the jupyter notebook and the VS Code plugin). Recently, thanks to @tqchen, we found that Google Colab does not well support ansi color sequence for 24-bit colors (`JupyterLight` and `VSCDark`) that all its displayed colors are unexpectedly black/gray/white. To also bring highlighting in Colab, in this PR, we directly render the highlighted code with HTML when a notebook environment is detected.
* feat(ux): highlight tvm script
* resolve dependency
* refact(tvmscript): highlight fallback as plain text with warning; put ansi colors as default terminal style
* refact(tvmscript): make terminal style close to the default notebook style
* fix(pylint): disable=import-outside-toplevel
* fix(ci-dep): Pygments>=2.4.0 to support ansicolors w/o #
* refact: making Pygments versioning most robust and user-friendly
* fix: pylint var naming