Skip to content

Conversation

@staticfloat
Copy link
Member

When calling Pkg.test("Foo"), some information from the calling
environment is incorporated into the tests of Foo; for example, if the
calling environment places restrictions on the package versions of
Bar, a dependency of Foo, those restrictions will be honored when
resolving the dependencies of the test environment for Foo.
Similarly, we should honor preferences set within the calling
environment. The easiest way to do this is to layer the test
environment onto the end of the current LOAD_PATH instead of wholesale
replacing it, as we were doing when copying preferences over for the
test environment.

With this change it is now viable to test alternate configurations of a
package without dev'ing it out and modifying it directly. If a package
Foo uses preference to alter its behavior, previously you would need
to dev it out and insert an override into its LocalPreferneces.toml
(or test/LocalPreferences.toml, if it had a separate test project) in
order for the preference to be read during test time. Now, one can
simply set the preference in an environment that has Foo added, then
run Pkg.test("Foo"), and as long as the package itself doesn't define
the preference within its own testing environment, it will pick up the
default from the environment.

We allow the package to override values coming in from the environment,
as there may be rather sensitive preferences that it is best to not
allow easy overriding from. For these cases, there is of course still
the dev-and-edit method available for tests.

@staticfloat staticfloat requested a review from vchuravy April 20, 2022 02:37
@staticfloat staticfloat force-pushed the sf/preferences_stacking branch from 8b2685f to e4b476c Compare April 20, 2022 02:39
@staticfloat
Copy link
Member Author

I think this may require JuliaPackaging/Preferences.jl#37

@staticfloat staticfloat reopened this Apr 20, 2022
@staticfloat staticfloat force-pushed the sf/preferences_stacking branch 4 times, most recently from 94a57d0 to c1d7564 Compare April 21, 2022 04:25
When calling `Pkg.test("Foo")`, some information from the calling
environment is incorporated into the tests of `Foo`; for example, if the
calling environment places restrictions on the package versions of
`Bar`, a dependency of `Foo`, those restrictions will be honored when
resolving the dependencies of the test environment for `Foo`.
Similarly, we should honor preferences set within the calling
environment.  The easiest way to do this is to layer the test
environment onto the end of the current `LOAD_PATH` instead of wholesale
replacing it, as we were doing when copying preferences over for the
test environment.

With this change it is now viable to test alternate configurations of a
package without dev'ing it out and modifying it directly.  If a package
`Foo` uses preference to alter its behavior, previously you would need
to `dev` it out and insert an override into its `LocalPreferneces.toml`
(or `test/LocalPreferences.toml`, if it had a separate test project) in
order for the preference to be read during test time.  Now, one can
simply set the preference in an environment that has `Foo` added, then
run `Pkg.test("Foo")`, and as long as the package itself doesn't define
the preference within its own testing environment, it will pick up the
default from the environment.

We allow the package to override values coming in from the environment,
as there may be rather sensitive preferences that it is best to not
allow easy overriding from.  For these cases, there is of course still
the `dev`-and-edit method available for tests.
@staticfloat staticfloat force-pushed the sf/preferences_stacking branch from c1d7564 to 5e5189b Compare April 21, 2022 04:50
@staticfloat
Copy link
Member Author

@vchuravy is it possible for you to test this with MPIPreferences to ensure that it's actually sufficient for your usecase?

@vchuravy
Copy link
Member

Will try to give it a go today!

@giordano
Copy link
Member

giordano commented Apr 22, 2022

Doesn't seem to work for me:

% ZES_ENABLE_SYSMAN=1 julia-master --project=/tmp --startup-file=no -q
julia> using MPIPreferences; MPIPreferences.use_jll_binary()
┌ Warning: The underlying MPI implementation has changed. You will need to restart Julia for this change to take effect
│   binary = "MPICH_jll"
└ @ MPIPreferences ~/.julia/packages/MPIPreferences/uArzO/src/MPIPreferences.jl:65

(tmp) pkg> test MPI
[...]
     Testing Running tests...
┌ Info: Running MPI tests
│   ArrayType = Array
│   nprocs = 4
│   MPIPreferences.abi = "MPICH"
└   MPIPreferences.binary = "MPICH_jll"
[...]

julia> using MPIPreferences; MPIPreferences.use_system_binary()
┌ Info: MPI implementation
│   libmpi = "libmpi"
│   version_string = "Open MPI v4.1.2, package: Open MPI builduser@arojas Distribution, ident: 4.1.2, repo rev: v4.1.2, Nov 24, 2021\0"
│   impl = "OpenMPI"
│   version = v"4.1.2"
└   abi = "OpenMPI"
┌ Warning: The underlying MPI implementation has changed. You will need to restart Julia for this change to take effect
│   libmpi = "libmpi"
│   abi = "OpenMPI"
│   mpiexec = "mpiexec"
└ @ MPIPreferences ~/.julia/packages/MPIPreferences/uArzO/src/MPIPreferences.jl:119

(tmp) pkg> test MPI
[...]
     Testing Running tests...
┌ Info: Running MPI tests
│   ArrayType = Array
│   nprocs = 4
│   MPIPreferences.abi = "MPICH"
└   MPIPreferences.binary = "MPICH_jll"

Edit: meh, I don't think this is using the right Pkg: I deved Pkg with the changed UUID in this environment, but when running the tests I still see [44cfe95a] Pkg v1.8.0 @stdlib/Pkg``

Edit 2: I guess it's because of https://github.com/JuliaParallel/MPI.jl/blob/e4479cfe16f1fdbbdab7423eca03c98764b0c671/test/Project.toml#L6. I'll edit this line and try again.

Edit 3: either changing the UUID in the test project file wasn't enough, or I need to rebuild julia against this branch to make sure this is used everywhere (can't do it right now), but it's still not working for me.

@vchuravy
Copy link
Member

(mpitemp) pkg> add MPI#master
...
  [da04e1cc] + MPI v0.20.0-dev `https://github.com/JuliaParallel/MPI.jl.git#master`
  [3da0fdf6] + MPIPreferences v0.1.1
...
┌ Info: Running MPI tests
│   ArrayType = Array
│   nprocs = 4
│   MPIPreferences.abi = "MPICH"
└   MPIPreferences.binary = "MPICH_jll"
...
julia> MPI.use_jll_binary("OpenMPI_jll")
┌ Warning: The underlying MPI implementation has changed. You will need to restart Julia for this change to take effect
│   binary = "OpenMPI_jll"
└ @ MPIPreferences ~/.julia/packages/MPIPreferences/uArzO/src/MPIPreferences.jl:65
(mpitemp) pkg> test MPI
     Testing Running tests...
┌ Info: Running MPI tests
│   ArrayType = Array
│   nprocs = 4
│   MPIPreferences.abi = "OpenMPI"
└   MPIPreferences.binary = "OpenMPI_jll"

So that looks right to me! I built Julia with

diff --git a/stdlib/Pkg.version b/stdlib/Pkg.version
index a595ed0213..c1f14c1982 100644
--- a/stdlib/Pkg.version
+++ b/stdlib/Pkg.version
@@ -1,4 +1,4 @@
 PKG_BRANCH = master
-PKG_SHA1 = 7676431149332ae400a805632082b12263c20269
+PKG_SHA1 = 5e5189b84523a41c67e3ade44fe774e69b66cea5
 PKG_GIT_URL := https://github.com/JuliaLang/Pkg.jl.git
 PKG_TAR_URL = https://api.github.com/repos/JuliaLang/Pkg.jl/tarball/$1

@staticfloat
Copy link
Member Author

Looks good Valentin! With that, I'm going to merge!

@staticfloat staticfloat merged commit e0ad102 into master Apr 22, 2022
@staticfloat staticfloat deleted the sf/preferences_stacking branch April 22, 2022 15:04
@omlins
Copy link

omlins commented Apr 22, 2022

@staticfloat , @vchuravy : how about having in the loadpath a default location where the default preferences are looked up - analogue to @stdlib? It would be nice if we could be 100% sure that preferences defined in the Julia installation by cluster administrators are taken always into account if not explicitly and intentionally overwritten by the user- even in cases where the Pkg manager wants to create a "clean" environment etc.

@staticfloat
Copy link
Member Author

staticfloat commented Apr 22, 2022

It would be nice if we could be 100% sure that preferences defined in the Julia installation by cluster administrators are taken always into account if not explicitly and intentionally overwritten by the user- even in cases where the Pkg manager wants to create a "clean" environment etc.

This can be done by having users define a default JULIA_DEPOT_PATH that includes a system-wide depot. I don't suggest using @stdlib as this, since @stdlib has kind of a special meaning; it doesn't act like a true "depot". Let's open a new issue about the best way for system administrators to provide defaults (preferences, packages, etc...) for their users: #3067

@omlins
Copy link

omlins commented Apr 24, 2022

I don't suggest using @StdLib as this, since @StdLib has kind of a special meaning; it doesn't act like a true "depot".

My suggestion is not to abuse @stdlib for preferences, but to create in Pkg.jl an analogue to @stdlib for preferences, e.g. @stdprefs, which points to the standard location of preferences in the Julia installation.

@omlins
Copy link

omlins commented May 9, 2022

@vchuravy , @staticfloat, what do you think about the above comment?

@vchuravy
Copy link
Member

vchuravy commented May 9, 2022

Please add it as a comment to #3067, I don't have any strong opinions, but we need to build community consensus around it.

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.

5 participants