Package: howigothere
HowIGotHereA package containing a single functionhowigotherethat returns a condensed
stack preview. Useful for debugging to easily trace how some call was made,
even through a jungle of calls made by frameworks and other packages.To see it in action, you can runexample.pyor, if
you didn't install the package but you only downloaded this repository,example.sh. Both
approaches require thatsettings-collectoris
installed. The result should look like this:ContentThe nameUsageGlobal setupLocal setupThe nameThe name of the package is "How I Got Here?". If your question is "How I Go
There?", wherever "there" might be, you'll need to ask some other package.UsageMake an import:fromhowigothereimporthowigothereand then callprint(howigothere())# or logger.debug(howigothere())somewhere in your code.Global setupThis package relies onsettings-collectorto collect
settings from various frameworks. This means that you can set it up through
standard mechanisms of the framework used by your project.For example, if you are using Django, you can set the separator colour by
definingHOWIGOTHERE__COLOR_SEP(note two underscores beforeCOLOR, but
only one after it) in your Django settings. The frameworks' settings character
casing is respected, so - for example - in TurboGears this will behowigothere__color_sepIf you don't use a framework (or, at least, not one supported bysettings-collector), you can also usesc_settings(settings-collector'sdict-like equivalent of frameworks' configs) and do something this:fromsettings_collectorimportsc_settingssc_settings["howigothere__color_sep"]=colorama.Fore.REDFor more details, please see the documentation ofsettings-collector.If the setup (either insc_settingsor in framework's settings) containssettings-collector's scopes, you can specify the scope to use like this:howigothere(namespace="some_scope")Local setupLastly, you can also configure values when calling the function. For example,howigothere(color_sep=colorama.Fore.RED)Here is the list of all arguments accepted by the function. All butnamespaceare also available insc_settingsand frameworks' settings. The default
values are as shown, unless overridden insc_settingsor framework's setup.namespace[default:None]: If set, it is used as scope identifier insettings_collector.keep_dirs[default: 1]: The number of directories to keep in output (Noneto keep them all). For example, if set to2, path/a/b/c/d/e/f.pywill be
displayed asd/e/f.py. This is to reduce the output while still being able
to distinguish between files with the same name.sep[default:" > "]: Separator between calls.call_format[default:"{function} ({path}:{lineno})"]: The format of each
call.no_color[default:False]: If set toTrue, colours won't be used even
if they are properly defined. This is useful if you want to have properly
coloured printouts most of the times, but you sometimes want to add these to
some logging system that doesn't support your preferred way of colouring
text.start_from_dir[default:None]: If set, output is suppressed until the
first file havingstart_from_diras its parent. This can also be a tuple of
strings, in which case encountering any of them starts the output.To add to those, colours can also be redefined. Their defaults depend on the
presence ofcoloramapackage (if it's not there, these are all empty strings
by default). The displayed defaults assume thatcoloramais installed and
that itsForeandStyleconstants are imported.color_reset[default:Style.RESET_ALL]: This is added to the end of each
colourisable chunk (separator, function name, etc.).color_sep[default:"", i.e., no colouring]: Colour used for the
separators between calls.color_func[ default:Style.BRIGHT + Fore.GREEN]: Colour used for
functions' names in each call.color_path[default:Style.BRIGHT + Fore.CYAN]: Colour used for path of
the each file containing called functions.color_lineno[default:Fore.CYAN]: Colour used for the line numbers where
calls were made.