in tools/tensorflow_docs/tools/nblint/__main__.py [0:0]
def add_styles(styles, excluded_lints, verbose):
"""Import lint assertions from style modules.
Style modules must exist in the `style/` directory of this package.
Args:
styles: A list of short names for style modules to import.
excluded_lints: List of lint functions to skip ('style::function').
verbose: Bool, to print more details to console. Default is False.
Returns:
A dictionary containing all the lint styles.
"""
lint_dict = {
decorator.Options.Scope.CODE: {
decorator.Options.Cond.ALL: [],
decorator.Options.Cond.ANY: []
},
decorator.Options.Scope.TEXT: {
decorator.Options.Cond.ALL: [],
decorator.Options.Cond.ANY: []
},
decorator.Options.Scope.CELLS: {
decorator.Options.Cond.ALL: [],
decorator.Options.Cond.ANY: []
},
decorator.Options.Scope.FILE: {
decorator.Options.Cond.ANY: [] # Only one queue is relevant.
}
}
for style in styles:
mod_name = f"tensorflow_docs.tools.nblint.style.{style}"
mod = importlib.import_module(mod_name)
is_lint = _is_user_defined_lint(mod_name)
# Extract Lint instance attached to function object by decorator.
lints = [
getattr(mem[1], "_lint") for mem in inspect.getmembers(mod, is_lint)
]
# Remove lints that have been explictly excluded at the command-line.
lints = [
lint for lint in lints if f"{style}::{lint.name}" not in excluded_lints
]
if verbose:
lint_names = ", ".join([lint.name for lint in lints])
print(f"From style '{mod_name}' import lints: {lint_names}\n")
for lint in lints:
lint.style = style
lint_dict[lint.scope][lint.cond].append(lint)
return lint_dict