Skip to content

Make all wrapped tools optional dependencies#51

Open
bjarketol wants to merge 7 commits intoEUFLOW:mainfrom
bjarketol:optional-tool-dependencies
Open

Make all wrapped tools optional dependencies#51
bjarketol wants to merge 7 commits intoEUFLOW:mainfrom
bjarketol:optional-tool-dependencies

Conversation

@bjarketol
Copy link
Contributor

@bjarketol bjarketol commented Feb 25, 2026

Summary

  • Move pywake, floris, foxes, wayve, and code_saturne from hard dependencies to optional extras (pip install wifa[pywake], wifa[all], etc.)
  • Add wifa/_optional.py with a require() helper that raises clear ImportError messages with install instructions when a tool is missing
  • Add pytest.importorskip() to each tool's test module so tests skip cleanly when the tool is not installed

Details

All API modules already used lazy imports (tool packages imported inside function bodies), so import wifa works without any tools installed. This PR formalizes that by:

  1. pyproject.toml: Tools moved to [project.optional-dependencies] groups. scipy and pyyaml added as core deps (used at module level by API modules). mpmath moved to the wayve extra.
  2. wifa/_optional.py (new): Central require(package, extra) utility using importlib.util.find_spec().
  3. API modules: Each run_*() function calls require() at its top, giving actionable error messages before any tool import runs.
  4. wifa/wayve_api.py: matplotlib and mpmath moved to lazy imports inside the functions that use them. FoxesWakeModel import moved into the foxes branch of wake_model_setup().
  5. Test files: pytest.importorskip() added before tool imports so entire test modules skip when the tool is absent.
  6. wifa/__init__.py: Added missing run_floris export.

Verified

  • Bare install (pip install wifa): import wifa succeeds; calling any run_* gives a clear error with install instructions
  • Single tool (pip install wifa[pywake]): pywake tests pass, other tools' tests skip
  • All tools (pip install wifa[all]): all tests pass as before

Closes #50

Test plan

  • pip install wifa (bare) — verify import wifa works, run_pywake() etc. raise clear ImportError
  • pip install wifa[pywake] — verify pywake tests pass, other tests skip
  • pip install wifa[all] — verify all tests pass
  • CI pipeline passes

🤖 Generated with Claude Code

bjarketol and others added 7 commits February 25, 2026 15:53
Move pywake, floris, foxes, wayve, and code_saturne from hard
dependencies to optional extras in pyproject.toml. Users can now
install only the tools they need: `pip install wifa[pywake]`,
`pip install wifa[foxes]`, etc., or all at once with `wifa[all]`.

- Add `wifa/_optional.py` with `require()` helper that gives clear
  install instructions when an optional tool is missing
- Add `require()` checks at the top of each `run_*` function
- Add `pytest.importorskip()` to test modules so tests skip cleanly
  when a tool is not installed
- Move matplotlib and mpmath to lazy imports in wayve_api.py
- Move FoxesWakeModel import into the foxes branch of wake_model_setup()
- Add scipy and pyyaml as core dependencies (used at module level)
- Add missing run_floris export in __init__.py

Closes EUFLOW#50

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
np.trapz was removed in numpy 2.0. Use np.trapezoid with fallback
for older numpy versions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
floris uses PEP 604 union types (str | Path) which require Python 3.10+.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also update wayve URL to main branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Make all wrapped tools (pywake, floris, foxes, wayve, code_saturne) optional dependencies

1 participant