How to get latest version number of a package

Using Pkg.update(“PackageName”), we can update the package.

I would like to just get latest version number of a package, not update it.

For example
Pkg.get_latest_version() → v0.19.2
like that.

Does someone know how to do it?

1 Like

I just browsed the source code of Pkg.jl a bit

Here is a snippet that might help you

a_path=joinpath(DEPOT_PATH[1],"registries","General","C","CSV")
 @assert isdir(a_path) 
di=Pkg.Operations.load_versions(a_path)
a_verison=maximum(keys(di))

Dict{VersionNumber,Base.SHA1} with 40 entries:
  v"0.1.1"  => SHA1("8b016f7fb9dee7a8baf48792593d26abc93026de")
  v"0.3.0"  => SHA1("38fb8a40079560da5804a280d7d3cf0180b833b1")
  v"0.5.6"  => SHA1("078801ccf5a644df31cef99c9add46107b94aba5")
  v"0.4.0"  => SHA1("b930e548bc4391bd2543b2a109cff711db06a171")
  v"0.5.0"  => SHA1("733d67569d4a3990a372647a44ec7dc1b70d34a0")
  v"0.1.0"  => SHA1("cbb157b71328652a55881ed82e225a981f4145b7")
  v"0.5.5"  => SHA1("239240112fc5f18fb934942a5b6f207a8f9e45d2")
  v"0.2.2"  => SHA1("99c291e15b863d9d4f9748b63debb97b3596d3ef")
  v"0.2.5"  => SHA1("9d62d3d577895a1e0b0bacd211a788be70127165")
  v"0.5.9"  => SHA1("a7df9250dff3aba96436580dd6ac00d712364cab")
  v"0.0.5"  => SHA1("1eb696b149cf5e58a5fd3fead2226540f57dc104")
  v"0.0.14" => SHA1("84667096a79791262d75fac748a4b0a8577b3f82")
  v"0.5.1"  => SHA1("42657742cc25fb5f79e0c906cf29fb8702afdd6e")
  v"0.4.1"  => SHA1("da83cb359d838758adf057719cdbfeffb074aabe")
  v"0.0.7"  => SHA1("09c684044402827b6bb6e7b170976f794de32cbc")
  v"0.0.9"  => SHA1("39e61b053b84bcb45dd5ff36f146967f39b9b46b")
  v"0.1.5"  => SHA1("0afc170e474ab4a6735896b97cefcd595c900fd8")
  v"0.0.2"  => SHA1("56d19428e6ee739505dc01e4c950f9e36698a7f5")
  v"0.0.1"  => SHA1("ab2ceee5ce66df211d60442fc1fd1846f97ccbc4")
  v"0.5.8"  => SHA1("2ea7620282c60902d7f0085d190abe9cf9928981")
  v"0.4.3"  => SHA1("b92c6f626a044cc9619156d54994b94084d40abe")
  v"0.0.8"  => SHA1("5973b52b2dd50abab01d05d2886efda1853d9283")
  v"0.0.6"  => SHA1("b6a664ca8aed44b63adeb8967f487b5eb2186f9c")
  v"0.0.4"  => SHA1("0af2ba3c8a54f00a944f734cec45a8b96594c279")
  v"0.5.4"  => SHA1("557a6b534b1ffc40abf7ddf1c4dec3b37ef05959")
  v"0.5.3"  => SHA1("b3a6be1f575868553dc5b2e1cc5139986affd199")
  v"0.2.3"  => SHA1("cfc7ca2d49f90ebf0a3206aef659901a1b11af78")
  v"0.1.2"  => SHA1("a150c75b9e145c8d431d0463bdd32f1819afa54a")
  v"0.2.0"  => SHA1("a227d0d52defd13747ffb020552ac44c10466fd0")
  v"0.4.2"  => SHA1("6dd974f0da3adb8b610cbbba5c95f5efbfa7a4df")
  v"0.0.13" => SHA1("4e44661aa2a57cb7d410d7cef52efe25f900d248")
  v"0.0.11" => SHA1("01658505f306bb50408f6d0de5e3673b2a7cfed4")
  v"0.0.12" => SHA1("d81bb9426ce11f826c9f761d3336be1d5e69c84d")
  v"0.0.3"  => SHA1("0af2ba3c8a54f00a944f734cec45a8b96594c279")
  v"0.1.4"  => SHA1("a588f46a72e6c0cd2b0302929a55fa139bc86a0c")
  v"0.2.4"  => SHA1("5ee6526af470a815ab666fab824370d7480d1576")
  v"0.2.1"  => SHA1("31b8a99f9afe3ade4de81dbb2856f2eaec5ddf20")
  v"0.5.2"  => SHA1("f64241c9688ae3eb003bce26ffd9ed863cfb824c")
  v"0.3.1"  => SHA1("67134caa06fd033202d89385517e4d8b542f420c")
  v"0.5.7"  => SHA1("f4a8ed808b7ee18638c5f8b278071ce0245e5e85") 
1 Like

You can preview an update

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _ |  |
  | | |_| | | | (_| |  |  Version 1.1.1 (2019-05-16)
 _/ |\___|_|_|\___|  |  Official https://julialang.org/ release
|__/                   |

(v1.1) pkg> preview update
───── Preview mode ─────
[ Info: skipping updating registries in preview mode
[ Info: skipping updating registries in preview mode
  Updating git-repo `https://github.com/GiovineItalia/Compose.jl.git`
 Resolving package versions...
  Updating `~/.julia/environments/v1.1/Project.toml`
 [no changes]
  Updating `~/.julia/environments/v1.1/Manifest.toml`
 [no changes]
  Building skipping building in preview mode
───── Preview mode ─────
4 Likes

Thank you!!. If I get the preview information with Julia script (not in REPL), it is perfect…

Thank you. If I could specify the package name, it is perfect…

well I thought you wanted to do some work yourself.

I have no idea if this works “in general”.
As such I recommend you do some testing in different environments

You possibly want to update the registries prior to running this command

import Pkg 

@warn("this will most likely not work properly for setups that differ from mine")
function findmaxversion(d::String,m::String)
    l=m[1:1]
    a_path=joinpath(d,"registries","General",l,m)
    if isdir(d)&&isdir(a_path)
        di=Pkg.Operations.load_versions(a_path)
        return maximum(keys(di))
    end
    return v"0.0.0"
end

findmaxversion(m::String)=maximum(findmaxversion.(DEPOT_PATH,m))

findmaxversion("CSV")
findmaxversion("DataFrames")
2 Likes

Oh, great!!. That is what I want to do!!