diff --git a/.github/workflows/scripts/post-benchmark-to-github-pr.py b/.github/workflows/scripts/post-benchmark-to-github-pr.py index 285668ae8938d..2749d4a086dca 100755 --- a/.github/workflows/scripts/post-benchmark-to-github-pr.py +++ b/.github/workflows/scripts/post-benchmark-to-github-pr.py @@ -107,8 +107,7 @@ def main(): for item in release: db.execute("INSERT OR IGNORE INTO release VALUES (?, ?)", flatten_metric(item)) - rs = db.execute( - """ + rs = db.execute(""" SELECT c.name AS name, c.value AS cv, @@ -118,8 +117,7 @@ def main(): current c LEFT JOIN release r ON (r.name = c.name) ORDER BY name - """ - ) + """) event = json.loads(Path(options.event).read_text()) sha = event["client_payload"]["pull_request"]["head"]["sha"] diff --git a/.github/workflows/scripts/ti_build/misc.py b/.github/workflows/scripts/ti_build/misc.py index 520b17ae64594..94375a03184cf 100644 --- a/.github/workflows/scripts/ti_build/misc.py +++ b/.github/workflows/scripts/ti_build/misc.py @@ -13,7 +13,6 @@ from .bootstrap import get_cache_home # noqa, this is a re-export from .escapes import escape_codes - # -- code -- options = None diff --git a/.github/workflows/scripts/ti_build/ospkg.py b/.github/workflows/scripts/ti_build/ospkg.py index 974c016000ca6..f7d4719af4316 100644 --- a/.github/workflows/scripts/ti_build/ospkg.py +++ b/.github/workflows/scripts/ti_build/ospkg.py @@ -12,7 +12,6 @@ from .misc import banner, error, info from .tinysh import apt - # -- code -- UBUNTU_PACKAGES = { "git", diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d6d70a6617bce..668f759b8cd67 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,27 +7,27 @@ default_language_version: exclude: ^((tests/python/test_exception)\.py$|external/) repos: - - repo: https://github.com/psf/black - rev: 25.1.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.3.1 hooks: - id: black language_version: python3.12 args: ['-l', '120'] - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v19.1.7 + rev: v22.1.2 hooks: - id: clang-format exclude: .*\.json$ - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/PyCQA/pylint - rev: v3.3.4 + rev: v4.0.5 hooks: - id: pylint args: ['-rn', '-sn'] diff --git a/docs/conftest.py b/docs/conftest.py index 71b4ec0c98e6e..2da955bce6ca4 100644 --- a/docs/conftest.py +++ b/docs/conftest.py @@ -44,9 +44,7 @@ PRELUDES = {} -PRELUDES[ - "init" -] = """ +PRELUDES["init"] = """ import taichi as ti import numpy as np import math diff --git a/misc/copyright.py b/misc/copyright.py index d673ed689cbd8..e731a73bb0e07 100644 --- a/misc/copyright.py +++ b/misc/copyright.py @@ -48,9 +48,7 @@ {file} . {file} --check taichi/common/core.cpp taichi/ir/transforms.h {file} benchmarks cmake docs examples misc python taichi tests -{file} --exts "cpp,py" benchmarks cmake docs examples misc python taichi tests""".format( - file=os.path.relpath(__file__) -) +{file} --exts "cpp,py" benchmarks cmake docs examples misc python taichi tests""".format(file=os.path.relpath(__file__)) class CommentStyle(Enum): diff --git a/python/taichi/aot/module.py b/python/taichi/aot/module.py index b942d6f72dbb2..24015a1ce3f06 100644 --- a/python/taichi/aot/module.py +++ b/python/taichi/aot/module.py @@ -49,7 +49,7 @@ def instantiate(self, **kwargs): for arg in kernel.arguments: if isinstance(arg.annotation, template): - (k, v) = template_args[anno_index] + k, v = template_args[anno_index] key_p += k key_p = self.keygen(v, key_p, self._aot_module._fields.items()) injected_args.append(v) diff --git a/python/taichi/examples/simulation/initial_value_problem.py b/python/taichi/examples/simulation/initial_value_problem.py index 2361b6abbd058..d9b0e9bc0494f 100644 --- a/python/taichi/examples/simulation/initial_value_problem.py +++ b/python/taichi/examples/simulation/initial_value_problem.py @@ -24,7 +24,7 @@ def init(): @ti.kernel def paint(t: float): - (o, p) = locations_np.shape + o, p = locations_np.shape for i in range(0, o): # Parallelized over all pixels x = locations[i, 0] y = locations[i, 1] diff --git a/python/taichi/lang/_wrap_inspect.py b/python/taichi/lang/_wrap_inspect.py index 436e8f98112ac..529d94434ba16 100644 --- a/python/taichi/lang/_wrap_inspect.py +++ b/python/taichi/lang/_wrap_inspect.py @@ -133,10 +133,8 @@ def _Python_IPython_findsource(obj): except ImportError: pass - raise IOError( - f"Cannot find source code for Object: {obj}, it's likely \ -you are not running Taichi from command line or IPython." - ) + raise IOError(f"Cannot find source code for Object: {obj}, it's likely \ +you are not running Taichi from command line or IPython.") def _REPL_findsource(obj): @@ -154,12 +152,10 @@ def _custom_findsource(obj): try: return _blender_findsource(obj) except: - raise IOError( - f"Cannot find source code for Object: {obj}, this \ + raise IOError(f"Cannot find source code for Object: {obj}, this \ is possibly because of you are running Taichi in an environment that Taichi's own \ inspect module cannot find the source. Please report an issue to help us fix: \ -https://github.com/taichi-dev/taichi/issues" - ) +https://github.com/taichi-dev/taichi/issues") class _InspectContextManager: diff --git a/python/taichi/math/mathimpl.py b/python/taichi/math/mathimpl.py index 85fb4565a5629..b777ba242ed2d 100644 --- a/python/taichi/math/mathimpl.py +++ b/python/taichi/math/mathimpl.py @@ -2,6 +2,7 @@ """ Math functions for glsl-like functions and other stuff. """ + import math from taichi.lang import impl, ops diff --git a/python/taichi/tools/vtk.py b/python/taichi/tools/vtk.py index 596ec3c3089a7..9938176dafbde 100644 --- a/python/taichi/tools/vtk.py +++ b/python/taichi/tools/vtk.py @@ -5,10 +5,8 @@ def write_vtk(scalar_field, filename): try: from pyevtk.hl import gridToVTK # pylint: disable=import-outside-toplevel except ImportError: - raise RuntimeError( - "Failed to import pyevtk. Please install it via /\ - `pip install pyevtk` first. " - ) + raise RuntimeError("Failed to import pyevtk. Please install it via /\ + `pip install pyevtk` first. ") scalar_field_np = scalar_field.to_numpy() field_shape = scalar_field_np.shape diff --git a/python/taichi/ui/canvas.py b/python/taichi/ui/canvas.py index 4b265ac0a80a5..b4c678fd48e18 100644 --- a/python/taichi/ui/canvas.py +++ b/python/taichi/ui/canvas.py @@ -66,10 +66,8 @@ def contour(self, scalar_field, cmap_name="plasma", normalize=False): import numpy as np # pylint: disable=import-outside-toplevel from matplotlib import cm # pylint: disable=import-outside-toplevel except ImportError: - raise RuntimeError( - "Failed to import Numpy and Matplotlib. /\ - Please install Numpy and Matplotlib before using contour()." - ) + raise RuntimeError("Failed to import Numpy and Matplotlib. /\ + Please install Numpy and Matplotlib before using contour().") scalar_field_np = scalar_field.to_numpy() field_shape = scalar_field_np.shape diff --git a/python/taichi/ui/gui.py b/python/taichi/ui/gui.py index 1f47496cd9987..0208ff173ec82 100644 --- a/python/taichi/ui/gui.py +++ b/python/taichi/ui/gui.py @@ -356,10 +356,8 @@ def contour(self, scalar_field, normalize=False): try: from matplotlib import cm # pylint: disable=import-outside-toplevel except ImportError: - raise RuntimeError( - "Failed to import Matplotlib. Please install it via /\ - `pip install matplotlib` first. " - ) + raise RuntimeError("Failed to import Matplotlib. Please install it via /\ + `pip install matplotlib` first. ") scalar_field_np = scalar_field.to_numpy() if self.res != scalar_field_np.shape: x, y = np.meshgrid(np.linspace(0, 1, self.res[1]), np.linspace(0, 1, self.res[0])) diff --git a/python/taichi/ui/ui.py b/python/taichi/ui/ui.py index 1f5c4f1261622..59da14fe4aaca 100644 --- a/python/taichi/ui/ui.py +++ b/python/taichi/ui/ui.py @@ -8,7 +8,6 @@ from .utils import check_ggui_availability # pylint: disable=unused-import from .window import Window # pylint: disable=unused-import - # ---------------------- ProjectionMode = _ti_core.ProjectionMode if _ti_core.GGUI_AVAILABLE else None """Camera projection mode, 0 for perspective and 1 for orthogonal. diff --git a/scripts/run_clang_tidy.py b/scripts/run_clang_tidy.py index bead4ccf4f5da..81b8beedcc107 100644 --- a/scripts/run_clang_tidy.py +++ b/scripts/run_clang_tidy.py @@ -112,7 +112,7 @@ def get_tidy_invocation( start.append("-export-fixes") # Get a temporary file. We immediately close the handle so clang-tidy can # overwrite it. - (handle, name) = tempfile.mkstemp(suffix=".yaml", dir=tmpdir) + handle, name = tempfile.mkstemp(suffix=".yaml", dir=tmpdir) os.close(handle) start.append(name) for arg in extra_arg: diff --git a/taichi/rhi/public_device.h b/taichi/rhi/public_device.h index cd7a09753c1f9..3ca1993321060 100644 --- a/taichi/rhi/public_device.h +++ b/taichi/rhi/public_device.h @@ -266,7 +266,11 @@ enum class BufferFormat : uint32_t { #undef PER_BUFFER_FORMAT }; -class RHI_DLL_EXPORT Pipeline{public : virtual ~Pipeline(){}}; +class RHI_DLL_EXPORT Pipeline { + public: + virtual ~Pipeline() { + } +}; using UPipeline = std::unique_ptr; @@ -554,8 +558,11 @@ enum class AllocUsage : int { MAKE_ENUM_FLAGS(AllocUsage) -class RHI_DLL_EXPORT -StreamSemaphoreObject{public : virtual ~StreamSemaphoreObject(){}}; +class RHI_DLL_EXPORT StreamSemaphoreObject { + public: + virtual ~StreamSemaphoreObject() { + } +}; using StreamSemaphore = std::shared_ptr; diff --git a/taichi/ui/gui/cocoa.cpp b/taichi/ui/gui/cocoa.cpp index 67705a48c0987..86aeb59a4c132 100644 --- a/taichi/ui/gui/cocoa.cpp +++ b/taichi/ui/gui/cocoa.cpp @@ -41,7 +41,10 @@ std::string str_tolower(std::string s) { std::optional try_get_alnum(ushort keycode) { // Can someone tell me the reason why Apple didn't make these consecutive... -#define CASE(i) {kVK_ANSI_##i, str_tolower(#i)} +#define CASE(i) \ + { \ + kVK_ANSI_##i, str_tolower(#i) \ + } static const std::unordered_map key2str = { CASE(0), CASE(1), CASE(2), CASE(3), CASE(4), CASE(5), CASE(6), CASE(7), CASE(8), CASE(9), CASE(A), CASE(B), CASE(C), CASE(D), CASE(E), CASE(F), @@ -60,7 +63,10 @@ std::optional try_get_alnum(ushort keycode) { std::optional try_get_fnkey(ushort keycode) { // Or these... #define STRINGIFY(x) #x -#define CASE(i) {kVK_F##i, STRINGIFY(F##i)} +#define CASE(i) \ + { \ + kVK_F##i, STRINGIFY(F##i) \ + } static const std::unordered_map key2str = { CASE(1), CASE(2), CASE(3), CASE(4), CASE(5), CASE(6), CASE(7), CASE(8), CASE(9), CASE(10), CASE(11), CASE(12), diff --git a/tests/pytest_hardtle.py b/tests/pytest_hardtle.py index 68b6bf72e48f6..0b03cca425043 100644 --- a/tests/pytest_hardtle.py +++ b/tests/pytest_hardtle.py @@ -18,13 +18,11 @@ # Modified from pytest-timeout tle_cffi = cffi.FFI() -tle_cffi.cdef( - """ +tle_cffi.cdef(""" void init(void); void set(int seconds, char *message); void cancel(void); -""" -) +""") TLE_WIN32 = r""" #include diff --git a/tests/python/test_assign.py b/tests/python/test_assign.py index 38ea23301ca57..669b478a2ff8d 100644 --- a/tests/python/test_assign.py +++ b/tests/python/test_assign.py @@ -18,7 +18,7 @@ def func_basic(): def test_assign_unpack(): @ti.kernel def func_unpack(): - (a, b) = (1, 2) + a, b = (1, 2) assert a == 1 assert b == 2 @@ -40,7 +40,7 @@ def func_chained(): def test_assign_chained_unpack(): @ti.kernel def func_chained_unpack(): - (a, b) = (c, d) = (1, 2) + a, b = (c, d) = (1, 2) assert a == 1 assert b == 2 assert c == 1