Is there any way to check the installation time of a package?

I can’t remember under what circumstance I installed a certain package. Is there any way to check its installation time to help me recall that? Besides, when the number of packages grows is there any good solution to managing them? For example, can I add some custom comments for each package?

If you manage your code in a git repository, the git history and commit messages answer your questions affirmatively

2 Likes

If you isolate each project you work into his own environment (simple and “cheap” in Julia) you can comment on the Project.toml file to add a note on why/when you installed (added) a certain package, but the project file doesn’t track automatically the installation date.

1 Like

Things you can do:

  • go through the REPL history and search for add ThatPkg
  • look in your .julia folder when the folder for that package was created
2 Likes

This is the most important answer. Julia packages are not meant to be installed in your base environment @v1.9. Instead you should probably use one environment per project, as described in the (very read-worthy) documentation of Pkg.jl.

As an additional thought, Julia developers frequently load packages with using MyPackage, which is not a great idea because it puts every package export into the namespace, the same way from mypackage import * behaves in Python. If you want to keep track of why you use a certain package, a good habit is to always document which functions and types you take from which package: using MyPackage: Type1, Type2, fun1, fun2, fun3

2 Likes

Check your .julia/logs folder. In particular .julia/logs/repl_history.jl.

Here’s an utility function to search through it.

julia> using REPL

julia> function search_repl_hist(query, mode = r".*")
           replhist = REPL.find_hist_file()
           time_line = ""
           mode_line = ""
           result = String[]
           for line in eachline(replhist)
               if startswith(line, "# time")
                   time_line = line
               elseif startswith(line, "# mode")
                   mode_line = line
               elseif contains(line, query)
                   if contains(mode_line, mode) 
                       push!(result, time_line)
                       push!(result, mode_line)
                       push!(result, line)
                   end
               end
           end
           result .|> println
           result
       end

Here’s how to use it.

julia> search_repl_hist("Interpolations");
# time: 2022-06-29 02:29:02 EDT
# mode: julia
	        itp = Interpolations.GriddedInterpolation{
# time: 2022-06-29 02:29:24 EDT
# mode: julia
	        itp = Interpolations.GriddedInterpolation{
# time: 2022-06-29 02:29:42 EDT
# mode: julia
	import Interpolations: tcollect, itpflag, dimension_wis_vec, coefficients, value_weights, shape, tail
# time: 2022-06-29 02:30:21 EDT
# mode: julia
	        itp = Interpolations.GriddedInterpolation{

julia> search_repl_hist(r"^\s+add Interpolations", "pkg");
# time: 2020-04-15 14:40:06 CDT
# mode: pkg
	add Interpolations
# time: 2020-06-17 14:29:14 CDT
# mode: pkg
	add Interpolations
4 Likes

Thanks! That’s a good idea!

Thanks! I am just planning to learn how to manage different environments in Julia. Hope it helps.

Thanks!

Do you know the correct encoding for .julia/logs/repl_history.jl? It shows garbled code:

# time: 2023-05-26 14:18:18 Öйú±ê׼ʱ¼ä
# mode: pkg
	add StableRNGs

The last characters should represent your timezone. The code that generates that line is below.

The Julia code originates from this call.

Libc.strftime("%Y-%m-%d %H:%M:%S %Z", time())

That in turn calls the C routine wcsftime:
https://cplusplus.com/reference/cwchar/wcsftime/

My guess is that GB 18030 is being misinterpreted as UTF-16.

julia> using StringEncodings

julia> decode(UInt8.(transcode(UInt16, "Öйú±ê׼ʱ¼ä")), "GB18030")
"中国标准时间"
1 Like

Thank you very much!