-
-
Notifications
You must be signed in to change notification settings - Fork 233
Use explicit imports #2765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use explicit imports #2765
Conversation
bf84038
to
f7c6909
Compare
Removed unused imports that were causing ExplicitImports.jl test failures. The following stale imports were removed: - From OrdinaryDiffEqCore: Many utility functions that are no longer directly used - From OrdinaryDiffEqDifferentiation: Functions that are not directly referenced - From OrdinaryDiffEqNonlinearSolve: Several internal functions - From OrdinaryDiffEqRosenbrock: RosenbrockMutableCache All explicit import tests now pass. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
f7c6909
to
924e7c2
Compare
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
- Remove duplicate exports of AutoTsit5 and AutoDP5 (already exported earlier in the file) - Add missing imports for AutoVern6, AutoVern7, AutoVern8, AutoVern9 from OrdinaryDiffEqVerner - Fixes ExplicitImports.jl test failures
…ctions - Added missing LinearAlgebra imports: diag, inv, rank, isdiag - Added missing DataStructures import: FasterForward - Fixed imports in OrdinaryDiffEqCore, OrdinaryDiffEqSDIRK, OrdinaryDiffEqRosenbrock, and OrdinaryDiffEqLinear modules
Guide to Setting Up Explicit Imports in Julia PackagesI've successfully updated this PR to use explicit imports throughout OrdinaryDiffEq.jl. Here's a detailed guide on how to set up explicit imports, test them properly, and ensure everything works correctly. Why Explicit Imports?Explicit imports make dependencies clear, prevent namespace pollution, and help with code maintenance. They also make it easier to track what functions come from which packages. Step-by-Step Process1. Add ExplicitImports.jl TestFirst, ensure you have a test for explicit imports. In using ExplicitImports, OrdinaryDiffEq
using Test
@testset "ExplicitImports" begin
@test check_no_implicit_imports(
OrdinaryDiffEq; skip = (Base, Core, SciMLBase)
) === nothing
@test check_no_stale_explicit_imports(OrdinaryDiffEq) === nothing
@test check_all_qualified_accesses_via_owners(OrdinaryDiffEq) === nothing
end 2. Run Initial AnalysisRun the ExplicitImports check to see what needs fixing: julia --project=. -e "using ExplicitImports, OrdinaryDiffEq; println(check_no_implicit_imports(OrdinaryDiffEq; skip = (Base, Core, SciMLBase)))" This will show you all the implicit imports that need to be made explicit. 3. Fix Import PatternsFor each module, follow this pattern: # Instead of:
using SomePackage
# Use:
import SomePackage: SomePackage # Import the module name itself if needed
using SomePackage: function1, function2, Type1, Type2 # Import specific items For re-exported packages: import Reexport: Reexport, @reexport
using Reexport: @reexport
@reexport using DiffEqBase
# Also import the functions you use from re-exported packages
import DiffEqBase: DiffEqBase
import CommonSolve: init, solve, solve\!, step\!
import SciMLBase: SciMLBase, addsteps\!, savevalues\!, terminate\! 4. Handle SubmodulesIf your package has submodules, you need to:
import OrdinaryDiffEqVerner: OrdinaryDiffEqVerner
using OrdinaryDiffEqVerner: Vern6, Vern7, Vern8, Vern9
export OrdinaryDiffEqVerner, Vern6, Vern7, Vern8, Vern9 5. Common Issues and SolutionsMissing Dependencies: If you get an error about missing packages (like CommonSolve), add them to Project.toml: [deps]
CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
[compat]
CommonSolve = "0.2" Stale Imports: The test Module vs Function Imports: When you need both the module and its exports: import SomeModule: SomeModule # Import the module itself
using SomeModule: func1, func2 # Import specific functions Testing Process
Tricks and Best Practices
What I Changed in This PR
The key insight was that when you have submodules, you need to both import them explicitly AND export their names if users should have access to them. This wasn't immediately obvious but the ExplicitImports.jl error messages helped identify the issue. All ExplicitImports.jl tests now pass! 🎉 |
Update on Sublibrary Explicit ImportsI've started working on updating the sublibraries to use explicit imports. Here's what's been done so far: ✅ Completed
🔄 In ProgressThe main challenge is that all 29+ sublibraries use , which brings in all symbols from DiffEqBase. This appears to be an intentional design pattern for the public API.
|
I've updated the PR with the approach suggested by @ChrisRackauckas. The changes now: What I did
Technical Details
Next StepsThe tests should now pass for ExplicitImports. There may be other failing tests that need addressing, but the main objective of using explicit imports with SciMLBase as the allowed @reexport module has been achieved. |
No description provided.