Skip to content

fortran bindings: split py2fgen and bindings#1185

Merged
havogt merged 6 commits intomainfrom
split_py2fgen_from_bindings
Apr 15, 2026
Merged

fortran bindings: split py2fgen and bindings#1185
havogt merged 6 commits intomainfrom
split_py2fgen_from_bindings

Conversation

@havogt
Copy link
Copy Markdown
Contributor

@havogt havogt commented Mar 30, 2026

The actual Fortran bindings of diffusion and dycore where part of the tools/py2fgen package. However py2fgen is actually a standalone tool.

We introduce a new package icon4py.bindings which depends on py2fgen and the atmosphere packages that it's generating bindings for.

Longer term it might be better to make the bindings part of their respective packages as optionals.

@havogt havogt requested review from egparedes and jcanton March 30, 2026 13:48
Copy link
Copy Markdown
Contributor

@egparedes egparedes left a comment

Choose a reason for hiding this comment

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

A couple of comments but in general LGTM

Comment thread pyproject.toml Outdated
Comment thread pyproject.toml Outdated
Comment thread bindings/tests/conftest.py Outdated
Comment on lines +88 to +90
yield click_testing.CliRunner()
os.environ["FLOAT_PRECISION"] = type_alias.DEFAULT_PRECISION
type_alias.set_precision(type_alias.DEFAULT_PRECISION)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not completely sure if I understand this correctly, but if the idea is to restore default settings after testing the CLI, shouldn't the actual original values be saved beforehand and restored later?

Suggested change
yield click_testing.CliRunner()
os.environ["FLOAT_PRECISION"] = type_alias.DEFAULT_PRECISION
type_alias.set_precision(type_alias.DEFAULT_PRECISION)
old_env = os.environ["FLOAT_PRECISION"]
old_precision_alias = type_alias.precision
yield click_testing.CliRunner()
os.environ["FLOAT_PRECISION"] = old_env
type_alias.set_precision(old_precision_alias)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it was just copied over from tools. delete now as it's unused I think.

Comment thread bindings/pyproject.toml
Copy link
Copy Markdown
Contributor

@jcanton jcanton left a comment

Choose a reason for hiding this comment

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

looks good other than one/two small edits:
maybe better to move bindings in model/ to better separate?

Comment thread .github/workflows/icon4py-test-tools-and-bindings.yml
Comment thread .github/workflows/icon4py-test-tools-and-bindings.yml
Comment thread noxfile.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR separates the Fortran wrapper modules (previously living under icon4py.tools.py2fgen) into a new workspace package, icon4py.bindings, so that py2fgen remains a standalone tool while bindings become a dedicated, model-dependent package.

Changes:

  • Introduce the new icon4py-bindings package (source + tests) and update imports from icon4py.tools.py2fgen.wrappers.* to icon4py.bindings.*.
  • Update workspace/configuration (uv workspace, extras, mypy/pytest paths, tach modules) and CI to run bindings + tool tests.
  • Move/refresh codegen reference artifacts under bindings/tests/bindings/references/.

Reviewed changes

Copilot reviewed 29 out of 43 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
uv.lock Adds icon4py-bindings to workspace/extras; adjusts deps
tools/tests/tools/py2fgen/wrappers/__init__.py Removes old wrappers test package init
tools/tests/tools/py2fgen/test_generator.py Updates wrapper module path to icon4py.bindings.*
tools/tests/tools/py2fgen/test_cli.py Uses icon4py.bindings.simple + new plugin path
tools/tests/tools/conftest.py Removes previously shared fixtures/hooks
tools/pyproject.toml Drops model deps; adjusts ruff excludes
tach.toml Adds bindings/src; updates module graph
pyproject.toml Adds bindings to workspace, mypy/pytest paths, and fortran extra
noxfile.py Reworks tools session into tools+bindings session
model/standalone_driver/pyproject.toml Drops pytest from runtime deps
bindings/tests/conftest.py New bindings-level conftest with fixtures + pytest hooks
bindings/tests/bindings/utils.py Adds test comparison helpers
bindings/tests/bindings/test_icon4py_export.py Updates export import to bindings
bindings/tests/bindings/test_grid_init.py Updates wrapper imports to bindings
bindings/tests/bindings/test_dycore_wrapper.py Updates wrapper imports to bindings
bindings/tests/bindings/test_diffusion_wrapper.py Updates wrapper imports to bindings
bindings/tests/bindings/test_codegen_references.py Updates reference module paths to bindings
bindings/tests/bindings/references/grid/grid.py Updates embedded imports to bindings
bindings/tests/bindings/references/grid/grid.h New generated C header reference
bindings/tests/bindings/references/grid/grid.f90 New generated Fortran module reference
bindings/tests/bindings/references/dycore/dycore.py Updates embedded imports to bindings
bindings/tests/bindings/references/dycore/dycore.h New generated C header reference
bindings/tests/bindings/references/dycore/dycore.f90 New generated Fortran module reference
bindings/tests/bindings/references/diffusion/diffusion.py Updates embedded imports to bindings
bindings/tests/bindings/references/diffusion/diffusion.h New generated C header reference
bindings/tests/bindings/references/diffusion/diffusion.f90 New generated Fortran module reference
bindings/tests/bindings/.gitignore Ignores compiled reference artifacts
bindings/tests/bindings/__init__.py Adds test package init/header
bindings/src/icon4py/bindings/viztracer_plugin.py Moves plugin to bindings; updates imports
bindings/src/icon4py/bindings/simple.py Uses bindings export hook
bindings/src/icon4py/bindings/muphys_wrapper.py Moves wrapper to bindings; tweaks typing comment
bindings/src/icon4py/bindings/icon4py_export.py New bindings export hooks for GT4Py annotations
bindings/src/icon4py/bindings/grid_wrapper.py Moves grid wrapper to bindings package
bindings/src/icon4py/bindings/dycore_wrapper.py Moves dycore wrapper to bindings package
bindings/src/icon4py/bindings/diffusion_wrapper.py Moves diffusion wrapper to bindings package
bindings/src/icon4py/bindings/debug_utils.py New debug logging utilities
bindings/src/icon4py/bindings/config.py Adds env-driven config flag
bindings/src/icon4py/bindings/common.py New shared helpers/types for bindings
bindings/src/icon4py/bindings/all_bindings.py Aggregates exported binding functions
bindings/src/icon4py/bindings/__init__.py New bindings package metadata
bindings/pyproject.toml Defines new icon4py-bindings package
.pre-commit-config.yaml Updates excludes to new references location
.github/workflows/icon4py-test-tools-and-bindings.yml CI runs updated nox session for tools+bindings
Comments suppressed due to low confidence (1)

tools/tests/tools/conftest.py:17

  • The nox session runs pytest ... --datatest-only/--datatest-skip in the tools/ directory, but this conftest.py no longer loads icon4py.model.testing.pytest_hooks that define these custom CLI options. As a result, pytest will error with “unrecognized arguments” when these flags are used. Either re-add the hook import here (as before) or stop passing the datatest flags when running the tools test suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread noxfile.py
@havogt
Copy link
Copy Markdown
Contributor Author

havogt commented Apr 13, 2026

cscs-ci run default

@havogt
Copy link
Copy Markdown
Contributor Author

havogt commented Apr 13, 2026

cscs-ci run distributed

@havogt
Copy link
Copy Markdown
Contributor Author

havogt commented Apr 14, 2026

cscs-ci run default

Copy link
Copy Markdown
Contributor

@jcanton jcanton left a comment

Choose a reason for hiding this comment

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

LGTM now

@havogt
Copy link
Copy Markdown
Contributor Author

havogt commented Apr 14, 2026

cscs-ci run default

@github-actions
Copy link
Copy Markdown

Mandatory Tests

Please make sure you run these tests via comment before you merge!

  • cscs-ci run default
  • cscs-ci run distributed

Optional Tests

To run benchmarks you can use:

  • cscs-ci run benchmark-bencher

To run tests and benchmarks with the DaCe backend you can use:

  • cscs-ci run dace

To run test levels ignored by the default test suite (mostly simple datatest for static fields computations) you can use:

  • cscs-ci run extra

For more detailed information please look at CI in the EXCLAIM universe.

@havogt
Copy link
Copy Markdown
Contributor Author

havogt commented Apr 14, 2026

cscs-ci run distributed

@havogt havogt merged commit 8f7d900 into main Apr 15, 2026
54 checks passed
@havogt havogt deleted the split_py2fgen_from_bindings branch April 15, 2026 09:44
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.

4 participants