I finally found a good solution (could be a template for other packages as well):
The source of the problem is that (a) there are external Julia “scripts” under ModiaMath/examples and ModiaMath/test that use package ModiaMath to demonstrate/test its features and (b) these “scripts” import other packages (besides ModiaMath) and the versions of these other packages are not defined. It is of course most natural to exactly use the package versions that are also used inside ModiaMath.
A reasonable solution with Julia 1.0.0 is therefore to reference extra packages used in examples
and test via the ModiaMath package:
File: ModiaMath/src/ModiaMath.jl
module ModiaMath
[....]
# Add import clauses used in examples and test (if not yet available here)
import StaticArrays
import Unitful
import DataFrames
@static if VERSION >= v"0.7.0-DEV.2005"
import LinearAlgebra
import Test
end
end
File: ModiaMath/examples/Simulate_FreeBodyRotation.jl
module Simulate_FreeBodyRotation
using ModiaMath
using ModiaMath.StaticArrays
@static if VERSION >= v"0.7.0-DEV.2005"
using ModiaMath.LinearAlgebra
end
[....]
end
File: ModiaMath/test/runtests.jl
module Runtests
@static if VERSION >= v"0.7.0-DEV.2005"
import ModiaMath
using ModiaMath.Test
else
using Base.Test
end
[....]
end
In the project.toml file there is only the [deps]
section, but no longer [extras]
and [targets]
sections.
The only (minor) drawback is that package Test
is loaded always with ModiaMath, even if it is not used (but I guess this overhead is small). The benefit is that individual Julia scripts under ModiaMath/test can be run directly with include
which is the standard way how the tests are developed in ModiaMath and in Modia.
It might be useful to support the pattern above directly in the Julia language. Example:
module MyExample
using ModiaMath
using StaticArrays as_in ModiaMath # use same version of StaticArrays as in ModiaMath
end