JuliaLang / Pkg.jl

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

The function `Pkg.Versions.semver_interval` does too much #3743

Closed KeithWM closed 6 months ago

KeithWM commented 6 months ago

The function semver_interval(m::RegexMatch) is poorly designed in the sense that it handles both regex parsing and the splitting of cases based on the content of the version number found. This has led to me duplicating part of the code in an undesirable fashion.

I believe this part

if vertyp === :caret
        if major != 0
            return VersionRange(v0, VersionBound((v0[1],)))
        elseif minor != 0
            return VersionRange(v0, VersionBound((v0[1], v0[2])))
        else
            if n_significant == 1
                return VersionRange(v0, VersionBound((0,)))
            elseif n_significant == 2
                return VersionRange(v0, VersionBound((0, 0,)))
            else
                return VersionRange(v0, VersionBound((0, 0, v0[3])))
            end
        end
    else
        if n_significant == 3 || n_significant == 2
            return VersionRange(v0, VersionBound((v0[1], v0[2],)))
        else
            return VersionRange(v0, VersionBound((v0[1],)))
        end
    end

should be extracted to a separate method semver_interval(v0::VersionNumber, vertyp::Symbol) that can be called by others wanting to implement semantic versioning.

IanButterworth commented 6 months ago

This is clearly an internal function.

I think what you're proposing is exposing an API? Perhaps you could open a feature request with a proposed design?