From 3ac11d018233a8e7b4a34e953e43d13007582e52 Mon Sep 17 00:00:00 2001 From: Roman Cattaneo <1116746+romanc@users.noreply.github.com> Date: Fri, 18 Jul 2025 10:19:17 +0200 Subject: [PATCH] Re-enable F401 (no unused imports) Update `__init__.py` files to use populate the `__all__` variable. That way, we don't need to handle `__init__.py` files separately. --- .pre-commit-config.yaml | 8 ----- ndsl/__init__.py | 55 +++++++++++++++++++++++++++++++ ndsl/checkpointer/__init__.py | 11 +++++++ ndsl/comm/__init__.py | 11 +++++++ ndsl/dsl/gt4py/__init__.py | 54 ++++++++++++++++++++++++++++++ ndsl/grid/__init__.py | 14 ++++++++ ndsl/halo/__init__.py | 7 ++++ ndsl/initialization/__init__.py | 5 +++ ndsl/monitor/__init__.py | 6 ++++ ndsl/performance/__init__.py | 3 ++ ndsl/stencils/__init__.py | 7 ++++ ndsl/stencils/testing/__init__.py | 19 +++++++++++ pyproject.toml | 12 ++++++- 13 files changed, 203 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ecc7023..e94527b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,14 +42,6 @@ repos: name: flake8 language_version: python3 additional_dependencies: [Flake8-pyproject] - exclude: | - (?x)^( - .*/__init__.py | - )$ - - id: flake8 - additional_dependencies: [Flake8-pyproject] - name: flake8 __init__.py files - files: "__init__.py" - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks rev: v2.15.0 diff --git a/ndsl/__init__.py b/ndsl/__init__.py index f6bb6117..3f692468 100644 --- a/ndsl/__init__.py +++ b/ndsl/__init__.py @@ -33,3 +33,58 @@ from .testing.dummy_comm import DummyComm from .types import Allocator from .utils import MetaEnumStr + + +__all__ = [ + "dsl", + "CubedSphereCommunicator", + "TileCommunicator", + "LocalComm", + "MPIComm", + "NullComm", + "CubedSpherePartitioner", + "TilePartitioner", + "ConstantVersions", + "FV3CodePath", + "DaceConfig", + "DaCeOrchestration", + "FrozenCompiledSDFG", + "orchestrate", + "orchestrate_function", + "ArrayReport", + "DaCeProgress", + "MaxBandwidthBenchmarkProgram", + "StorageReport", + "WrappedHaloUpdater", + "FrozenStencil", + "GridIndexing", + "StencilFactory", + "TimingCollector", + "CompilationConfig", + "RunMode", + "StencilConfig", + "OutOfBoundsError", + "HaloExchangeSpec", + "HaloUpdater", + "HaloUpdateRequest", + "VectorInterfaceHaloUpdater", + "QuantityFactory", + "GridSizer", + "SubtileGridSizer", + "ndsl_log", + "NetCDFMonitor", + "Namelist", + "NullPerformanceCollector", + "PerformanceCollector", + "NullProfiler", + "Profiler", + "Experiment", + "Report", + "TimeReport", + "Quantity", + "FieldBundle", + "FieldBundleType", + "DummyComm", + "Allocator", + "MetaEnumStr", +] diff --git a/ndsl/checkpointer/__init__.py b/ndsl/checkpointer/__init__.py index 8fee4dc1..22ff634e 100644 --- a/ndsl/checkpointer/__init__.py +++ b/ndsl/checkpointer/__init__.py @@ -7,3 +7,14 @@ ThresholdCalibrationCheckpointer, ) from .validation import ValidationCheckpointer + + +__all__ = [ + "NullCheckpointer", + "SnapshotCheckpointer", + "InsufficientTrialsError", + "SavepointThresholds", + "Threshold", + "ThresholdCalibrationCheckpointer", + "ValidationCheckpointer", +] diff --git a/ndsl/comm/__init__.py b/ndsl/comm/__init__.py index c4a58658..580f881a 100644 --- a/ndsl/comm/__init__.py +++ b/ndsl/comm/__init__.py @@ -6,3 +6,14 @@ CachingRequestWriter, ) from .comm_abc import Comm, Request + + +__all__ = [ + "CachingCommData", + "CachingCommReader", + "CachingCommWriter", + "CachingRequestReader", + "CachingRequestWriter", + "Comm", + "Request", +] diff --git a/ndsl/dsl/gt4py/__init__.py b/ndsl/dsl/gt4py/__init__.py index 7c051fb0..3ae0dbd8 100644 --- a/ndsl/dsl/gt4py/__init__.py +++ b/ndsl/dsl/gt4py/__init__.py @@ -51,3 +51,57 @@ trunc, types, ) + + +__all__ = [ + "BACKWARD", + "FORWARD", + "IJ", + "IJK", + "IK", + "JK", + "PARALLEL", + "Field", + "GlobalTable", + "I", + "J", + "K", + "Sequence", + "abs", + "acos", + "acosh", + "asin", + "asinh", + "atan", + "atanh", + "cbrt", + "ceil", + "compile_assert", + "computation", + "cos", + "cosh", + "exp", + "externals", + "floor", + "function", + "gamma", + "horizontal", + "interval", + "isfinite", + "isinf", + "isnan", + "log", + "log10", + "max", + "min", + "mod", + "region", + "sin", + "sinh", + "sqrt", + "stencil", + "tan", + "tanh", + "trunc", + "types", +] diff --git a/ndsl/grid/__init__.py b/ndsl/grid/__init__.py index fabe72bf..c397a706 100644 --- a/ndsl/grid/__init__.py +++ b/ndsl/grid/__init__.py @@ -9,3 +9,17 @@ HorizontalGridData, VerticalGridData, ) + + +__all__ = [ + "HybridPressureCoefficients", + "GridDefinitions", + "MetricTerms", + "AngleGridData", + "ContravariantGridData", + "DampingCoefficients", + "DriverGridData", + "GridData", + "HorizontalGridData", + "VerticalGridData", +] diff --git a/ndsl/halo/__init__.py b/ndsl/halo/__init__.py index e16177d5..deaead80 100644 --- a/ndsl/halo/__init__.py +++ b/ndsl/halo/__init__.py @@ -3,3 +3,10 @@ HaloDataTransformerCPU, HaloDataTransformerGPU, ) + + +__all__ = [ + "HaloDataTransformer", + "HaloDataTransformerCPU", + "HaloDataTransformerGPU", +] diff --git a/ndsl/initialization/__init__.py b/ndsl/initialization/__init__.py index 8f40c7af..5f3300a4 100644 --- a/ndsl/initialization/__init__.py +++ b/ndsl/initialization/__init__.py @@ -1 +1,6 @@ from .sizer import GridSizer + + +__all__ = [ + "GridSizer", +] diff --git a/ndsl/monitor/__init__.py b/ndsl/monitor/__init__.py index 5d732315..e3f5037f 100644 --- a/ndsl/monitor/__init__.py +++ b/ndsl/monitor/__init__.py @@ -1,2 +1,8 @@ from .protocol import Monitor from .zarr_monitor import ZarrMonitor + + +__all__ = [ + "Monitor", + "ZarrMonitor", +] diff --git a/ndsl/performance/__init__.py b/ndsl/performance/__init__.py index 28e03bc6..359bc761 100644 --- a/ndsl/performance/__init__.py +++ b/ndsl/performance/__init__.py @@ -1,2 +1,5 @@ from .config import PerformanceConfig from .timer import NullTimer, Timer + + +__all__ = ["PerformanceConfig", "NullTimer", "Timer"] diff --git a/ndsl/stencils/__init__.py b/ndsl/stencils/__init__.py index 5115a28e..8a635187 100644 --- a/ndsl/stencils/__init__.py +++ b/ndsl/stencils/__init__.py @@ -1 +1,8 @@ from .corners import CopyCorners, CopyCornersXY, FillCornersBGrid + + +__all__ = [ + "CopyCorners", + "CopyCornersXY", + "FillCornersBGrid", +] diff --git a/ndsl/stencils/testing/__init__.py b/ndsl/stencils/testing/__init__.py index 4be2c60a..a55d8647 100644 --- a/ndsl/stencils/testing/__init__.py +++ b/ndsl/stencils/testing/__init__.py @@ -14,3 +14,22 @@ pad_field_in_j, read_serialized_data, ) + + +__all__ = [ + "Grid", + "ParallelTranslate", + "ParallelTranslate2Py", + "ParallelTranslate2PyState", + "ParallelTranslateBaseSlicing", + "ParallelTranslateGrid", + "SavepointCase", + "Translate", + "assert_same_temporaries", + "TranslateFortranData2Py", + "TranslateGrid", + "pad_field_in_j", + "read_serialized_data", + "dataset_to_dict", + "copy_temporaries", +] diff --git a/pyproject.toml b/pyproject.toml index 155ef409..633cfe19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,17 @@ source_pkgs = ["ndsl"] [tool.flake8] exclude = ["docs"] -extend-ignore = ["E203", "E302", "E704", "F841", "W293", "E501", "W503", "F401"] +extend-ignore = [ + # Redundant with black formatter + "E302", # Blank lines before function + "E501", # Line too long + "E704", # One statement per line + "W293", # Blank line contains whitespace + "W503", # Linebreak before binary operator + # Clashes with NDSL/stencil syntax + "E203", # Space before ":", e.g. `field[1, :]` + "F841" # Local variable assigned but unused +] max-line-length = 88 [tool.isort]