blurstudio / hab

A application environment and launcher
GNU Lesser General Public License v3.0
25 stars 3 forks source link

Filter aliases based on current verbosity #71

Closed MHendricks closed 1 year ago

MHendricks commented 1 year ago

@JamesB-Blur Using this PR for communicating changes to hab required by in development work for hab-gui

Note: ~Manually editing Resolver._verbosity_target and _current_verbosity is required currently~ You need to enable filtering with the hab.utils.verbosity_filter with context.

MHendricks commented 1 year ago

I think the code changes are final, but I still need to write documentation and verify I'm covering all the new code.

I decided to switch from implicit verbosity filtering, to requiring using a with context to enable filtering. This makes it so when writing code, you know that you will get everything unless you opt into filtering. I've added these to the correct places so the cli will respect verbosity filtering.

To dump uri's with limited verbosity:

with hab.utils.verbosity_filter(resolver, verbosity=1, target="hab-gui"):
      result = list(resolver.dump_forest(resolver.configs))

And to filter aliases:

cfg = resolver.resolve("verbosity/inherit")
with hab.utils.verbosity_filter(resolver, verbosity=2, target="hab-gui"):
    result = cfg.aliases

And the docstring for verbosity_filter:

def verbosity_filter(resolver, verbosity, target=None):
    """Change the verbosity settings of a hab.Resolver while inside this with
    context.

    Args:
        resolver (hab.Resolver): The resolver to change verbosity settings on.
        verbosity (int): Change the verbosity setting to this value. If None is
            passed, all results are be shown without any filtering.
        target (str, optional): Change the verbosity target, ignored if None.
    """