gt4py.cartesian.utils package

Submodules

gt4py.cartesian.utils.attrib module

class gt4py.cartesian.utils.attrib.AttributeClassLike[source]

Bases: object

property as_dict
property attributes
validate()[source]
gt4py.cartesian.utils.attrib.attribclass(cls_or_none=None, **kwargs)[source]

Class decorator to convert a regular class into an AttribClass.

gt4py.cartesian.utils.attrib.attribkwclass(cls_or_none=None, **kwargs)[source]
gt4py.cartesian.utils.attrib.attribute(of, optional=False, **kwargs)[source]
gt4py.cartesian.utils.attrib.attributes_of(an_attribclass)[source]

gt4py.cartesian.utils.base module

Basic utilities for Python programming.

class gt4py.cartesian.utils.base.BaseFrozen[source]

Bases: object

class gt4py.cartesian.utils.base.BaseSingleton(*args, **kwargs)[source]

Bases: object

class gt4py.cartesian.utils.base.ClassProperty(fget=None, fset=None, fdel=None, doc=None)[source]

Bases: object

Like a property, but the wrapped function is a class method.

deleter(fdel)[source]
getter(fget)[source]
setter(fset)[source]
class gt4py.cartesian.utils.base.Registry[source]

Bases: dict

property names
register(name, item=<object object>)[source]
class gt4py.cartesian.utils.base.UniqueIdGenerator(start=1)[source]

Bases: object

property current
property new
gt4py.cartesian.utils.base.classmethod_to_function(class_method, instance=None, owner=<class 'NoneType'>, remove_cls_arg=False)[source]
gt4py.cartesian.utils.base.classproperty

alias of gt4py.cartesian.utils.base.ClassProperty

gt4py.cartesian.utils.base.compose(*functions_or_iterable)[source]

Return a function that chains the input functions.

Derived from: https://mathieularose.com/function-composition-in-python/

gt4py.cartesian.utils.base.flatten(nested_iterables, filter_none=False, *, skip_types=(<class 'str'>, <class 'bytes'>))[source]
gt4py.cartesian.utils.base.flatten_iter(nested_iterables, filter_none=False, *, skip_types=(<class 'str'>, <class 'bytes'>))[source]
gt4py.cartesian.utils.base.get_member(instance, item_name)[source]
gt4py.cartesian.utils.base.is_collection(value, *, optional=False, accept_mapping=True)[source]
gt4py.cartesian.utils.base.is_identifier_name(value, namespaced=True)[source]
gt4py.cartesian.utils.base.is_iterable_of(value, item_class, iterable_class=<class 'collections.abc.Iterable'>, *, optional=False, accept_mapping=True)[source]
gt4py.cartesian.utils.base.is_mapping_of(value, key_class, value_class=None, mapping_class=<class 'collections.abc.Mapping'>, *, optional=False)[source]
gt4py.cartesian.utils.base.jsonify(value, indent=2)[source]
gt4py.cartesian.utils.base.make_dir(dir_name, *, mode=511, is_package=False, is_cache=False)[source]
gt4py.cartesian.utils.base.make_local_dir(dir_name, base_dir=None, *, mode=511, is_package=False, is_cache=False)[source]
gt4py.cartesian.utils.base.make_module_from_file(qualified_name, file_path, *, public_import=False)[source]

Import module from file.

References

https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly https://stackoverflow.com/a/43602645

gt4py.cartesian.utils.base.namespace_from_nested_dict(nested_dict)[source]
gt4py.cartesian.utils.base.normalize_mapping(mapping, key_types=(<class 'object'>, ), *, filter_none=False)[source]
gt4py.cartesian.utils.base.patch_module(module, member, new_value, *, recursive=True)[source]

Monkey patch a module replacing a member with a new value.

gt4py.cartesian.utils.base.restore_module(patch, *, verify=True)[source]

Restore a module patched with the patch_module() function.

gt4py.cartesian.utils.base.shash(*args, hash_algorithm=None)[source]
gt4py.cartesian.utils.base.shashed_id(*args, length=10, hash_algorithm=None)[source]
gt4py.cartesian.utils.base.slugify(value: str, *, replace_spaces=True, valid_symbols='-_.()', invalid_marker='')[source]

gt4py.cartesian.utils.meta module

Utilities for runtime: introspection and bytecode.

class gt4py.cartesian.utils.meta.ASTEvaluator(context: dict)[source]

Bases: gt4py.cartesian.utils.meta.ASTPass

AST_OP_TO_OP = {<class 'ast.UAdd'>: <built-in function pos>, <class 'ast.USub'>: <built-in function neg>, <class 'ast.Add'>: <built-in function add>, <class 'ast.Sub'>: <built-in function sub>, <class 'ast.Mult'>: <built-in function mul>, <class 'ast.Div'>: <built-in function truediv>, <class 'ast.Mod'>: <built-in function mod>, <class 'ast.Pow'>: <built-in function pow>, <class 'ast.Invert'>: <built-in function invert>, <class 'ast.BitOr'>: <built-in function or_>, <class 'ast.BitXor'>: <built-in function xor>, <class 'ast.BitAnd'>: <built-in function and_>, <class 'ast.Not'>: <built-in function not_>, <class 'ast.Eq'>: <built-in function eq>, <class 'ast.NotEq'>: <built-in function ne>, <class 'ast.Lt'>: <built-in function lt>, <class 'ast.LtE'>: <built-in function le>, <class 'ast.Gt'>: <built-in function gt>, <class 'ast.GtE'>: <built-in function ge>}
classmethod apply(ast_root, context, default=None)[source]
generic_visit(node)[source]

Fallback if no explicit visitor function exists for a node.

visit_Attribute(node: ast.Attribute)[source]
visit_BinOp(node: ast.BinOp)[source]
visit_BoolOp(node: ast.BoolOp)[source]
visit_Compare(node: ast.Compare)[source]
visit_Constant(node)[source]
visit_Name(node)[source]
visit_NameConstant(node)[source]
visit_Num(node)[source]
visit_Tuple(node: ast.Tuple)[source]
visit_UnaryOp(node: ast.UnaryOp)[source]
class gt4py.cartesian.utils.meta.ASTPass[source]

Bases: object

Clone of the ast.NodeVisitor that supports forwarding kwargs.

generic_visit(node, **kwargs)[source]

Fallback if no explicit visitor function exists for a node.

visit(node, **kwargs)[source]

Visit a node.

class gt4py.cartesian.utils.meta.ASTTransformPass[source]

Bases: gt4py.cartesian.utils.meta.ASTPass

Clone of the ast.NodeTransformer that supports forwarding kwargs.

generic_visit(node, **kwargs)[source]

Fallback if no explicit visitor function exists for a node.

class gt4py.cartesian.utils.meta.AssignTargetsCollector(*, allow_multiple_targets)[source]

Bases: gt4py.cartesian.utils.meta.ASTPass

__call__(ast_root)[source]

Call self as a function.

classmethod apply(ast_root, *, allow_multiple_targets=True)[source]
visit_Assign(node: ast.Assign)[source]
class gt4py.cartesian.utils.meta.ImportsCollector[source]

Bases: gt4py.cartesian.utils.meta.ASTPass

__call__(ast_root)[source]

Call self as a function.

classmethod apply(ast_root)[source]
visit_Import(node: ast.Import)[source]
visit_ImportFrom(node: ast.ImportFrom)[source]
class gt4py.cartesian.utils.meta.QualifiedNameCollector(prefixes=None, *, skip_decorators=True, skip_annotations=True)[source]

Bases: gt4py.cartesian.utils.meta.ASTPass

__call__(ast_root)[source]

Call self as a function.

classmethod apply(ast_root, prefixes=None, *, skip_decorators=True, skip_annotations=True)[source]
generic_visit(node)[source]

Fallback if no explicit visitor function exists for a node.

visit_Attribute(node: ast.Attribute)[source]
visit_Name(node: ast.Name)[source]
class gt4py.cartesian.utils.meta.SymbolsNameMapper(mapping, template_fmt, skip_names)[source]

Bases: gt4py.cartesian.utils.meta.ASTTransformPass

__call__(ast_root)[source]

Call self as a function.

classmethod apply(ast_root, mapping, template_fmt=None, skip_names=None)[source]
visit_Name(node: ast.Name)[source]
gt4py.cartesian.utils.meta.ast_dump(definition, *, skip_annotations: bool = True, skip_decorators: bool = True, feature_version: Tuple[int, int]) str[source]
gt4py.cartesian.utils.meta.ast_eval(ast_root, context, default=None)
gt4py.cartesian.utils.meta.ast_shash(ast_node, *, skip_decorators=True)[source]
gt4py.cartesian.utils.meta.ast_unparse(ast_node)[source]

Call ast.unparse, but use astunparse for Python prior to 3.9.

gt4py.cartesian.utils.meta.collect_assign_targets(ast_root, *, allow_multiple_targets=True)
gt4py.cartesian.utils.meta.collect_decorators(func_or_source_or_ast)[source]
gt4py.cartesian.utils.meta.collect_imported_symbols(ast_root)
gt4py.cartesian.utils.meta.collect_names(ast_root, prefixes=None, *, skip_decorators=True, skip_annotations=True)
gt4py.cartesian.utils.meta.get_ast(func_or_source_or_ast, *, feature_version: Tuple[int, int])[source]
gt4py.cartesian.utils.meta.get_closure(func, *, include_globals=True, included_nonlocals=True, include_builtins=True)[source]
gt4py.cartesian.utils.meta.get_qualified_name_from_node(name_or_attribute, *, as_list=False)[source]
gt4py.cartesian.utils.meta.get_source(func)[source]
gt4py.cartesian.utils.meta.map_symbol_names(ast_root, mapping, template_fmt=None, skip_names=None)
gt4py.cartesian.utils.meta.remove_decorators(func_or_source_or_ast)[source]
gt4py.cartesian.utils.meta.split_def_decorators(func_or_source)[source]

gt4py.cartesian.utils.text module

Text and templating utilities.

class gt4py.cartesian.utils.text.Joiner(joiner_str)[source]

Bases: object

class Placeholder(joiner, index)[source]

Bases: object

__call__()[source]

Call self as a function.

class gt4py.cartesian.utils.text.TextBlock(indent_level=0, indent_size=4, indent_char=' ', end_line='\n')[source]

Bases: object

append(source_line, indent_steps=0)[source]
dedent(steps=1)[source]
empty_line(steps=1)[source]
extend(source_lines, *, dedent=False)[source]
indent(steps=1)[source]
indented(steps=1)[source]
property text
gt4py.cartesian.utils.text.format_source(source: str, line_length: int) str[source]
gt4py.cartesian.utils.text.get_line_number(text, re_query, re_flags=0)[source]

Return (0-based) line number of the match or None.

Module contents