JuliaLang / Pkg.jl

Pkg - Package manager for the Julia programming language
https://pkgdocs.julialang.org
Other
621 stars 261 forks source link

Weak dependency compat not respected #3814

Closed yha closed 6 months ago

yha commented 7 months ago

With this Project.toml file

[deps]
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"

[weakdeps]
WebSockets = "104b5d7c-a370-577a-8038-80a2059c5097"

[compat]
WebSockets = "~1.5"

WebSockets 1.6 ends up being installed. This seems like the simplest possible use case of weak dependencies as described here: https://pkgdocs.julialang.org/v1/creating-packages/#Weak-dependencies

A weak dependency is a dependency that will not automatically install when the package is installed but you can still control what versions of that package are allowed to be installed by setting compatibility on it

so I find it quite surprising that it doesn't work.

Example:

(@v1.10) pkg> activate --temp
  Activating new project at `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns`

(jl_iiJvns) pkg> add WebIO
   Resolving package versions...
    Updating `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Project.toml`
  [0f1e0344] + WebIO v0.8.21
    Updating `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Manifest.toml`
[...]
  [104b5d7c] + WebSockets v1.6.0
[...]

(jl_iiJvns) pkg> # edit Project.toml to add `weakdeps` and `compat` section

(jl_iiJvns) pkg> status
Status `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Project.toml`
  [0f1e0344] WebIO v0.8.21
Warning The project dependencies or compat requirements have changed since the manifest was last resolved. It is recommended to `Pkg.resolve()` or consider `Pkg.update()` if necessary.

(jl_iiJvns) pkg> up
    Updating registry at `C:\Users\sternlab\.julia\registries\General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
  No Changes to `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Project.toml`
  No Changes to `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Manifest.toml`

(jl_iiJvns) pkg> resolve
ERROR: empty intersection between WebSockets@1.6.0 and project compatibility 1.5

(jl_iiJvns) pkg> status -m WebSockets
Status `C:\Users\sternlab\AppData\Local\Temp\jl_iiJvns\Manifest.toml`
  [104b5d7c] WebSockets v1.6.0

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × Intel(R) Core(TM) i7-9800X CPU @ 3.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake-avx512)
  Threads: 1 on 16 virtual cores
KristofferC commented 6 months ago

I think the bug here is that weak deps are not collected if the active project is not a package.

https://github.com/JuliaLang/Pkg.jl/blob/6859d68579e7970daf00720901cf487563dca0da/src/Operations.jl#L312-L314