Skip to content

Fix NCDatasets extension for Julia 1.12#127

Merged
simone-silvestri merged 4 commits intomainfrom
ss/fix-netcdf-extension
Apr 2, 2026
Merged

Fix NCDatasets extension for Julia 1.12#127
simone-silvestri merged 4 commits intomainfrom
ss/fix-netcdf-extension

Conversation

@simone-silvestri
Copy link
Copy Markdown
Collaborator

Summary

  • Replace __init__ + @eval pattern with a direct import + compile-time method definition for default_output_attributes
  • Bump version to 0.4.7

Motivation

The @eval in __init__ breaks incremental compilation on Julia 1.12 with the error:

Evaluation into the closed module `ClimaSeaIceNCDatasetsExt` breaks incremental compilation
because the side effects will not be permanent.

This caused NumericalEarth (and any package loading both ClimaSeaIce and NCDatasets) to fail precompilation.

Dependencies

Requires CliMA/Oceananigans.jl#5469 — which moves default_output_attributes from the NCDatasets extension to a stub in the main Oceananigans module, so downstream extensions can extend it at compile time.

Test plan

  • ClimaSeaIce precompiles on Julia 1.12
  • NumericalEarth precompiles successfully with ClimaSeaIce + NCDatasets

🤖 Generated with Claude Code

Replace __init__ + @eval pattern with a direct import and compile-time
method definition for default_output_attributes. The old pattern broke
incremental compilation on Julia 1.12 because eval into a closed module
is no longer allowed.

Requires Oceananigans >= 0.106.4 (CliMA/Oceananigans.jl#5469).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines 33 to 37
function default_output_attributes(model::SeaIceModel)
velocity_attrs = default_horizontal_velocity_attributes(model.grid)
tracer_attrs = default_sea_ice_attributes()
return merge(velocity_attrs, tracer_attrs)
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this method defined here? default_output_attributes is from Oceananigans.OutputWriters, and SeaIceModel is defined in the main package, I don't see why it should be defined in the extension with NCDatasets

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it was here because before CliMA/Oceananigans.jl#5469 you couldn't extend it outside this NCDatasets extension. But still, with that PR I believe this method should be defined in the main package, not here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

using Oceananigans
using ClimaSeaIce

import Oceananigans.OutputWriters: default_output_attributes
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import 🥲

@glwagner
Copy link
Copy Markdown
Member

glwagner commented Apr 1, 2026

Duplicate of #126

@glwagner glwagner marked this as a duplicate of #126 Apr 1, 2026
@giordano
Copy link
Copy Markdown

giordano commented Apr 1, 2026

Duplicate of #126

I don't think it's a duplicate, it's a different approach to address the same issue. And I think this PR is better than #126 because it doesn't use get_extension at all, but as I said above and in CliMA/Oceananigans.jl#5469, I really think all this code shouldn't live in the NCDadatasets extensions, these methods really are independent from it.

@glwagner
Copy link
Copy Markdown
Member

glwagner commented Apr 1, 2026

Ah sorry, I just looked at the title.

Duplicate of #126

I don't think it's a duplicate, it's a different approach to address the same issue. And I think this PR is better than #126 because it doesn't use get_extension at all, but as I said above and in CliMA/Oceananigans.jl#5469, I really think all this code shouldn't live in the NCDadatasets extensions, these methods really are independent from it.

ah I see

glwagner and others added 2 commits April 1, 2026 14:54
Address review feedback: move default_output_attributes(::SeaIceModel)
and helper functions from the NCDatasets extension to the main ClimaSeaIce
module. With Oceananigans#5469, default_output_attributes is a stub in
Oceananigans.OutputWriters, so the method can be defined at compile time
without needing the NCDatasets extension. Uses qualified name instead of
import.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The extension has no code left after moving default_output_attributes
to the main module. Remove the extension file, weakdep, and extension
entry from Project.toml. Keep NCDatasets in [extras] for tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@simone-silvestri
Copy link
Copy Markdown
Collaborator Author

Oh sorry I hadn't seen #126 :). Close this in favor of #126

@simone-silvestri
Copy link
Copy Markdown
Collaborator Author

I also had just looked at the title 😅 without reading the comments. I ll reopen it

@simone-silvestri simone-silvestri merged commit 720680c into main Apr 2, 2026
7 checks passed
@simone-silvestri simone-silvestri deleted the ss/fix-netcdf-extension branch April 2, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants