/ resolve.jl
resolve.jl
  1  using Pkg: Pkg
  2  
  3  function recurse_projects(
  4      f,
  5      path=".";
  6      io=stdout,
  7      top=true,
  8      exclude=("test", "docs", "deps", "user", ".conda", ".CondaPkg", ".git"),
  9      include=(),
 10      top_proj=Base.active_project(),
 11      kwargs...,
 12  )
 13      path = realpath(path)
 14      @sync for subpath in readdir(path)
 15          fullpath = joinpath(path, subpath)
 16          if endswith(fullpath, "Project.toml")
 17              f(path, fullpath; io, kwargs...)
 18          elseif isdir(fullpath)
 19              if !startswith(fullpath, ".") && all(!endswith(fullpath, e) for e in exclude)
 20                  recurse_projects(f, fullpath; io, top=false, top_proj, kwargs...)
 21              end
 22          end
 23      end
 24      for path in include
 25          if isdir(path)
 26              fullpath = joinpath(path, "Project.toml")
 27              f(path, fullpath; io, kwargs...)
 28          else
 29              @warn "path does not exist" path
 30          end
 31      end
 32      top && Pkg.activate(top_proj)
 33  end
 34  
 35  function _update_project(path, fullpath; precomp, inst, doupdate, io=stdout)
 36      projpath = dirname(joinpath(path, fullpath))
 37      Pkg.activate(projpath; io)
 38      if doupdate
 39          prev_offline_status = Pkg.OFFLINE_MODE[]
 40          Pkg.offline(false)
 41          Pkg.update()
 42          Pkg.offline(prev_offline_status)
 43      else
 44          Pkg.resolve(; io)
 45      end
 46      if precomp
 47          Pkg.precompile(; io)
 48      end
 49      if inst
 50          Pkg.instantiate(; io)
 51      end
 52  end
 53  
 54  function update_projects(path="."; io=stdout, doupdate=false, inst=false, precomp=false)
 55      recurse_projects(_update_project, path; io, doupdate, inst, precomp, include=("PlanarDev/test",))
 56  end
 57  
 58  function _project_name!(path, fullpath; io, projects)
 59      projpath = dirname(joinpath(path, fullpath))
 60      Pkg.activate(projpath; io)
 61      name = Pkg.project().name
 62      isnothing(name) || push!(projects, name)
 63  end
 64  
 65  function projects_name(path="."; io=stdout)
 66      projects = Set{String}()
 67      recurse_projects(_project_name!, path; io, projects)
 68      projects
 69  end
 70  
 71  function purge_compilecache(path="."; io=stdout)
 72      names = projects_name(path; io)
 73      compiled = joinpath(
 74          homedir(), ".julia", "compiled", "v$(Int(VERSION.major)).$(Int(VERSION.minor))"
 75      )
 76      @info "Purging compiled cache" dir = compiled n = length(names)
 77      sleep(0)
 78      for name in names
 79          pkg_path = joinpath(compiled, name)
 80          if isdir(pkg_path)
 81              rm(pkg_path; recursive=true)
 82          end
 83      end
 84  end
 85  
 86  @doc "List of directories to put into tests.yml julia process coverage action"
 87  function coverage_directories(sep=",")
 88      names = projects_name(; io=devnull)
 89      buf = IOBuffer()
 90      try
 91          for name in sort!([n for n in names])
 92              if name ∈ ("Zarr", "PlanarDev", "Cli", "PlanarInteractive", "Temporal")
 93                  continue
 94              else
 95                  write(buf, joinpath(name, "src"), sep)
 96              end
 97          end
 98          String(take!(buf))
 99      finally
100          close(buf)
101      end
102  end