Mercurial > forks > mercurial
changeset 53177:749e7d9113a6
pytype: add a scrip to colorize `importlab --tree` output
This will help us to spot the import cycle that make pytype slower.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 16 Apr 2025 10:27:02 +0200 |
parents | 99a7cfe324e6 |
children | 93e4d0c51639 |
files | contrib/import-lab-tree-color.sh |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/import-lab-tree-color.sh Wed Apr 16 10:27:02 2025 +0200 @@ -0,0 +1,30 @@ +#!/bin/sh +# +# add color to the output of `importlab --trim --tree` +# +# cycles are flagged with `cycle {}` so we make the "cycle" red and the content +# of the cycle yellow to make them easy to spot. +# +# the module starting with '::' are internal module that we don't really care +# about (the subgraph is filtered by `--trim`) +# +# The "+" before module mark "direct" (vs "local") import and we don't really +# care about that. +# +# We replace new lines by null bytes during process as it is easier to have sed +# not do multiline work. + +if [ -z "$TERM" ]; then + TERM=ansi + export TERM +fi + +RED="$(tput setaf 1)" +YELLOW="$(tput setaf 3)" +BLUE="$(tput setaf 4)" +BLACK="$(tput sgr0)" +tr '\n' '\0' \ + | sed 's/\bcycle\b/'${RED}'\0'${BLACK}'/g' \ + | sed -E 's/\{[^{]+\}/'${YELLOW}'\0'${BLACK}'/g' \ + | sed 's,:: [^\x0]*,'${BLUE}'\0'${BLACK}',g' \ + | tr '\0' '\n'