You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removes automatic formatting (black / clang-format) of generated code from gt4py.next and keeps it only for gt4py.cartesian (and tests), with the formatter reduced to a minimal best-effort module.
New leaf module gt4py.eve.formatting with format_python_source (black; line_length argument, default 100; black's target version pinned to the running interpreter) and format_cpp_source (clang-format, LLVM style); both return the input unchanged when the tool is missing or fails. The executable can still be overridden with CLANG_FORMAT_EXECUTABLE.
Removed the old formatting API from gt4py.eve.codegen (format_source, format_python_source, format_cpp_source, register_formatter, SOURCE_FORMATTERS, FormattingError, FormatterNameError). Importing eve.codegen no longer imports black nor spawns a clang-format subprocess.
gt4py.next: no formatting at all. SourceCodeSpec and subclasses lose formatter_key/formatter_options (specs are now hashable); otf.artifacts.format_source removed; gtfn sources, nanobind bindings and roundtrip debug output are emitted unformatted; formatters.gtfn.format_cpp returns raw C++. Roundtrip: debug removed from the source-cache key and added to the module-cache key (debug runs still write the temp .py file).
gt4py.cartesian: no behaviour change. It only switches its existing formatting calls from eve.codegen.format_source(...) to eve.formatting.format_cpp_source(...) / format_python_source(...); the call sites, the format_source option handling and the line lengths stay as they were.
tach.toml: gt4py.eve.formatting is its own module and only gt4py.cartesian may depend on it.
Dependencies: black is no longer a runtime dependency and clang-format moved out of the standard extra; both are now in the cartesian extra and the test dependency group. This is the only change visible from gt4py.cartesian: a plain pip install gt4py no longer formats cartesian output.
Removed gt4py.eve.codegen formatting API; use gt4py.eve.formatting. Known downstream user: icon4py tools/src/icon4py/tools/py2fgen/_codegen.py (also needs black as its own dependency).
black/clang-format are no longer installed by default (pip install gt4py[cartesian] to get formatted cartesian output).
Generated gtfn C++ include order is no longer sorted by clang-format; CPU is covered by CI, GPU is covered only by CSCS CI.
Requirements
All fixes and/or new features come with corresponding tests. (New tests/eve_tests/unit_tests/test_formatting.py; existing next binding tests updated; new roundtrip module-cache test.)
Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder. (No new ADR needed; one-line note added to ADR 0012.)
If this PR contains code authored by new contributors please make sure:
The PR contains an updated version of the AUTHORS.md file adding the names of all the new contributors. (N/A)
… eve.formatting
Remove automatic formatting (black / clang-format) of generated code from
gt4py.next and keep it only for gt4py.cartesian (and tests).
- New leaf module `gt4py.eve.formatting` with best-effort
`format_python_source` (black) and `format_cpp_source` (clang-format);
both return the input unchanged when the tool is missing or fails.
- Remove the old formatting API from `gt4py.eve.codegen`.
- gt4py.next: no formatting; `SourceCodeSpec` loses
`formatter_key`/`formatter_options`; `otf.artifacts.format_source` removed.
- gt4py.cartesian: C++ formatted once in
`BaseGTBackend._make_extension_sources`; Python backends use
`eve.formatting`.
- tach: only gt4py.cartesian may depend on `gt4py.eve.formatting`.
- Dependencies: black and clang-format moved to the `cartesian` extra and
the `test` dependency group.
The reason will be displayed to describe this comment to others. Learn more.
Added in b657b5d: tests/next_tests/unit_tests/program_processor_tests/runners_tests/test_roundtrip.py loads the same source with debug=False then True, and the reverse. It asserts that separate modules are created, that each is reused from the cache on a second load, and that only the debug module has a real .py__file__.
…odule cache
- cartesian: 'format_source' controls C++ formatting in
'BaseGTBackend._make_extension_sources'.
- cartesian: stencil-definition sources are kept verbatim.
- next: roundtrip module cache is keyed by (source, debug); only debug
modules are backed by a real '.py' file.
gt4py.cartesian keeps its original formatting call sites, options and
line lengths; it only switches from `eve.codegen.format_source` to
`eve.formatting.format_cpp_source` / `format_python_source`. Drop the
cartesian tests covering the reverted behaviour.
`format_python_source` gains a `line_length` argument and pins black's
target version to the running interpreter, as the old formatter did.
Removing debug from the source-cache key is not covered by the new test, which only exercises _MODULE_CACHE. Add a parametrized test that clears _SOURCE_CACHE, generates the same program in both debug orders, and asserts identical source plus a single cache entry; otherwise a future debug-dependent source/cache split can regress unnoticed.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in af4457a: format_python_source now catches any Exception from black.format_str and returns the input unchanged, matching the old format_source(skip_errors=True) path. Added test_format_python_source_black_failure, which monkeypatches black.format_str to raise RuntimeError. It fails with the old except ValueError.
The reason will be displayed to describe this comment to others. Learn more.
Added in af4457a: test_format_python_source_unsupported_interpreter replaces black.TargetVersion with an empty mapping, so the running-version lookup raises KeyError, and checks the input comes back unchanged. The same commit also covers the "previously missed" source-cache point from the review overview. test_generate_source_ignores_debug_flag in test_roundtrip.py generates the same program with both debug orders and asserts identical source, a single transform call and a single _SOURCE_CACHE entry.
Restores the catch-all of the removed codegen.format_source(skip_errors=True)
path used by gt4py.cartesian. Adds tests for unexpected black errors, an
interpreter unknown to black, and the debug-independent roundtrip source cache.
The reason will be displayed to describe this comment to others. Learn more.
The env var is kept for parity with the previous eve.codegen behaviour that cartesian relies on. Availability is now probed once with --version, like before (54b9caf). A missing or failing tool falls back to the unformatted source; see test_format_cpp_source_missing_executable, test_format_cpp_source_failing_executable, test_format_cpp_source_formatting_failure and test_format_cpp_source_probes_executable_once.
Mirror the previous eve.codegen behaviour: check CLANG_FORMAT_EXECUTABLE once with --version (lazily, cached) and skip C++ formatting when the tool is unavailable. Addresses review comment on PR #2927.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Removes automatic formatting (black / clang-format) of generated code from
gt4py.nextand keeps it only forgt4py.cartesian(and tests), with the formatter reduced to a minimal best-effort module.gt4py.eve.formattingwithformat_python_source(black;line_lengthargument, default 100; black's target version pinned to the running interpreter) andformat_cpp_source(clang-format, LLVM style); both return the input unchanged when the tool is missing or fails. The executable can still be overridden withCLANG_FORMAT_EXECUTABLE.gt4py.eve.codegen(format_source,format_python_source,format_cpp_source,register_formatter,SOURCE_FORMATTERS,FormattingError,FormatterNameError). Importingeve.codegenno longer imports black nor spawns a clang-format subprocess.gt4py.next: no formatting at all.SourceCodeSpecand subclasses loseformatter_key/formatter_options(specs are now hashable);otf.artifacts.format_sourceremoved; gtfn sources, nanobind bindings and roundtrip debug output are emitted unformatted;formatters.gtfn.format_cppreturns raw C++. Roundtrip:debugremoved from the source-cache key and added to the module-cache key (debug runs still write the temp.pyfile).gt4py.cartesian: no behaviour change. It only switches its existing formatting calls fromeve.codegen.format_source(...)toeve.formatting.format_cpp_source(...)/format_python_source(...); the call sites, theformat_sourceoption handling and the line lengths stay as they were.tach.toml:gt4py.eve.formattingis its own module and onlygt4py.cartesianmay depend on it.blackis no longer a runtime dependency andclang-formatmoved out of thestandardextra; both are now in thecartesianextra and thetestdependency group. This is the only change visible fromgt4py.cartesian: a plainpip install gt4pyno longer formats cartesian output.Breaking changes / notes
gt4py.eve.codegenformatting API; usegt4py.eve.formatting. Known downstream user: icon4pytools/src/icon4py/tools/py2fgen/_codegen.py(also needsblackas its own dependency).black/clang-formatare no longer installed by default (pip install gt4py[cartesian]to get formatted cartesian output).Requirements
tests/eve_tests/unit_tests/test_formatting.py; existing next binding tests updated; new roundtrip module-cache test.)If this PR contains code authored by new contributors please make sure:
AUTHORS.mdfile adding the names of all the new contributors. (N/A)