[Mlir-commits] [mlir] [mlir][py] Enable loading only specified dialects during creation. (PR #121421)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Dec 31 18:01:18 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 3cc311ab8674eab6b9101cdf3823b55ea23d6535...cebba8e9e795092fbc4a541395d97e704f94c2f4 mlir/python/mlir/_mlir_libs/__init__.py mlir/python/mlir/ir.py mlir/test/python/ir/dialects.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- python/mlir/_mlir_libs/__init__.py	2025-01-01 01:53:35.000000 +0000
+++ python/mlir/_mlir_libs/__init__.py	2025-01-01 02:00:51.744371 +0000
@@ -154,18 +154,24 @@
             for hook in post_init_hooks:
                 hook(self)
             if not disable_multithreading:
                 self.enable_multithreading(True)
             if load_on_create_dialects is not None:
-                logger.debug("Loading all dialects from load_on_create_dialects arg %r", _load_on_create_dialects)
+                logger.debug(
+                    "Loading all dialects from load_on_create_dialects arg %r",
+                    _load_on_create_dialects,
+                )
                 for dialect in load_on_create_dialects:
                     # Load dialect.
                     _ = self.dialects[dialect]
             else:
                 if disable_load_all_available_dialects:
                     if _load_on_create_dialects:
-                        logger.debug("Loading all dialects from global load_on_create_dialects %r", _load_on_create_dialects)
+                        logger.debug(
+                            "Loading all dialects from global load_on_create_dialects %r",
+                            _load_on_create_dialects,
+                        )
                         for dialect in _load_on_create_dialects:
                             # Load dialect.
                             _ = self.dialects[dialect]
                 else:
                     logger.debug("Loading all available dialects")
--- python/mlir/ir.py	2025-01-01 01:53:35.000000 +0000
+++ python/mlir/ir.py	2025-01-01 02:00:51.854127 +0000
@@ -3,11 +3,15 @@
 #  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
 from ._mlir_libs._mlir.ir import *
 from ._mlir_libs._mlir.ir import _GlobalDebug
 from ._mlir_libs._mlir import register_type_caster, register_value_caster
-from ._mlir_libs import get_dialect_registry, append_load_on_create_dialect, get_load_on_create_dialects
+from ._mlir_libs import (
+    get_dialect_registry,
+    append_load_on_create_dialect,
+    get_load_on_create_dialects,
+)
 
 
 # Convenience decorator for registering user-friendly Attribute builders.
 def register_attribute_builder(kind, replace=False):
     def decorator_builder(func):
--- test/python/ir/dialects.py	2025-01-01 01:53:35.000000 +0000
+++ test/python/ir/dialects.py	2025-01-01 02:00:51.905241 +0000
@@ -127,25 +127,24 @@
 @run
 def testDialectLoadOnCreate():
     with Context(load_on_create_dialects=[]) as ctx:
         ctx.emit_error_diagnostics = True
         ctx.allow_unregistered_dialects = True
-        
+
         def callback(d):
             # CHECK: DIAGNOSTIC
             # CHECK-SAME: op created with unregistered dialect
             print(f"DIAGNOSTIC={d.message}")
             return True
 
         handler = ctx.attach_diagnostic_handler(callback)
         loc = Location.unknown(ctx)
         try:
-          op = Operation.create("arith.addi", loc=loc)
-          ctx.allow_unregistered_dialects = False
-          op.verify()
+            op = Operation.create("arith.addi", loc=loc)
+            ctx.allow_unregistered_dialects = False
+            op.verify()
         except MLIRError as e:
-          pass
-  
+            pass
+
     with Context(load_on_create_dialects=["func"]) as ctx:
-      loc = Location.unknown(ctx)
-      fn = Operation.create("func.func", loc=loc)
-
+        loc = Location.unknown(ctx)
+        fn = Operation.create("func.func", loc=loc)

``````````

</details>


https://github.com/llvm/llvm-project/pull/121421


More information about the Mlir-commits mailing list