Skip to content

Commit

Permalink
Add version resolution for patches, breaking and major
Browse files Browse the repository at this point in the history
  • Loading branch information
VarLad committed Mar 14, 2024
1 parent 2916b05 commit 2405658
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/PerfChecker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module PerfChecker

# SECTION - Imports
using Pkg
using Pkg.Types
import TOML
using Profile
import TypedTables: Table
import Distributed: remotecall_fetch, addprocs, rmprocs
Expand Down Expand Up @@ -30,7 +32,7 @@ export @check
export to_table

# SECTION - Includes

include("versions.jl")
include("check.jl")
include("alloc.jl")

Expand Down
83 changes: 67 additions & 16 deletions src/versions.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,74 @@
"""
Finds all versions of a package in all the installed registries and returns it as a vector.
Example:
```julia-repl
julia> get_pkg_versions("ConstraintLearning")
7-element Vector{VersionNumber}:
v"0.1.4"
v"0.1.5"
v"0.1.0"
v"0.1.6"
v"0.1.1"
v"0.1.3"
v"0.1.2"
```
"""
function get_pkg_versions(name::String, regname::Union{Nothing,Vector{String}} = nothing)::Vector{VersionNumber}
regs = Types.Context().registries
indexes = isnothing(regname) ? collect(1:length(regs)) : findall(x -> x.name in regname, regs)

versions::Set{String} = Set([])
for i in indexes
push!(versions, keys(TOML.parse(regs[i].in_memory_registry[join([first(name),name,"Versions.toml"], '/')]))...)
end
return VersionNumber.(versions)
end

const VerConfig = Tuple{Symbol, Vector{VersionNumber}, Bool}

struct PackVer
pack::String
ver::VerConfig
function get_versions(name::String, pkgconf::VerConfig, head::Bool = true, regname::Union{Nothing, Vector{String}} = nothing)
versions = get_pkg_versions(name, regname)
s = pkgconf[1]
f = if s == :patches
arrange_patches
elseif s == :breaking
arrange_breaking
elseif s == :major
arrange_major
else
error("Unknown option provided $(pkgconf[1])")
end
return map(x -> f(x, versions, pkgconf[3]), pkgconf[2])
end

to_version_numbers(x) = to_version_numbers(x...)
to_version_numbers(s::Symbol, x...) = to_version_numbers(Val(s), x...)

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"

"""
Outputs the last patch or first patch of a version.
If the input is 1.2.3, then the output is 1.2.0 or 1.2.9 (assuming both exist, and both are the first and last patch of the version)
"""
function arrange_patches(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.minor == x.minor && a.major == x.major, v)
return maxo ? maximum(a) : minimum(a)
end

findmaxversion(m::String)=maximum(findmaxversion.(DEPOT_PATH,m))
"""
Outputs the last breaking or next breaking version.
If the input is 1.2.3, then the output is 1.2.0 or 1.3.0 (assuming both exist)
"""
function arrange_breaking(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.major == x.major && a.minor == x.minor, v)
b = filter(x -> a.major == x.major && a.minor < x.minor, v)
return maxo ? minimum(b) : minimum(a)
end

function to_version_numbers(ver::VerConfig) end
# I believe breaking and minor are the same?i
"""
Outputs the earlier or next major version.
"""
function arrange_major(a::VersionNumber, v::Vector{VersionNumber}, maxo::Bool)
a = filter(x -> a.major < x.major, v)
b = filter(x -> a.major > x.major, v)
return maxo ? minimum(a) : maximum(b)
end

0 comments on commit 2405658

Please sign in to comment.