Hi,
I am working with various packages such as Chmy.jl, JustRelax.jl, among others, where we support both CPU, GPU and distributed computing backends.
Mostly for GPU backends and MPI support on servers such as HPC clusters and supercomputers, it may be helpful to have a globally set LocalPreferences.toml
file (and corresponding Project.toml
) as to set some default preferences such as e.g. using system binaires for MPI or local toolkit for GPU libraries (see e.g. Configuration · MPI.jl).
Outside of the test environment, all works as expected, i.e., Julia applications pick up the globally set LocalPreferences. However, I realised that running tests using the Julia testing infrastructure using Pkg; Pkg.test("myPkg")
would pick up local preferences only if a LocalPreferences.toml
file is present within the repo that is being tested while ignoring the preferences set globally.
As I understand, the Julia load path is changed when running test to the tmp folder tests are run into (e.g. "JULIA_LOAD_PATH" => "@:/tmp/jl_n7w8ha"
), which overrides the load path set to reading in the global prefs (e.g. "JULIA_LOAD_PATH" => ":/path/to/global/julia_prefs"
).
Would there be a way to work around this issue and allow the globally set LocalPreferences to be picked up during testing and work as expected in the same fashion as from outside the testing env?
Add your global env back into the LOAD_PATH
within your tests?
Thanks for the suggestion. Unsure tho how to set this up such that it would not interfere with the expected testing configuration.
Also, it would be nice if there could be an approach that would be generic and not having the modify things whether one runs on a system that may have prefs set in a global fashion.
Ultimately preferences are loaded by looking through your load path so either:
- you need to add the environment containing your preferences to the load path; or
- you need to add your preferences into one of the environments already in the load path.
I don’t think there’s anything generic to do this for you - AFAIU tests are intentionally run in an isolated environment.
Do you use the implicit test environment (i.e. test dependencies are in the top Project.toml
) or an explicit one (i.e. you have a test/Project.toml
file)? Maybe the behaviour is different between these but I doubt it.
It’s a known long-standing issue – Preferences.jl doesn’t actually support global preferences, despite the documentation claiming that it does. See Global preferences · Issue #33 · JuliaPackaging/Preferences.jl · GitHub reported 3.5 years ago.
Thanks for the insights provided which are highly appreciated!
From brief scrolling through Preferences.jl I did not bump on the longer lasting issue, but I feel we’re exactly hitting this.
Outside of test
, it seems to work fine though to have the globally set LocalPreferences active and those can be overwritten if a LocalPreferences.toml
file is available in the active project.
Wouldn’t it be possible to propagate this behaviour to testing, Pluto, and others?