Pkg.jl icon indicating copy to clipboard operation
Pkg.jl copied to clipboard

Can't specify a prerelease tag in the `compat` sectiion of a Project.toml File

Open MarkNahabedian opened this issue 2 years ago • 0 comments

This is in Julia 1.6.0.

versioninfo()
Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, haswell)

I first raised this issue in a Julia Discourse topic but got no response. Perhaps I should have picked a better title.

TLDR:

One can't specify a prerelease tag in the compat sectiion of a Project.toml file. Version strings lik 1.2.3-dev in the compat section fail to parse.

Motivation

I have some changes to registered Julia packages that have not yet been incorporated into the registered versions. For example, I have some small changes to NativeSVG.jl that make it more flexible.

To distinguish my version of NativeSVG.jl from version numbers in the main stream, I put

version = "0.1.0-naha"

in the Project.toml file.

I have other projects that depend on my changes to NativeSVG, but if I specify that dependency in the compat section of that Project.toml file I get an error.

I would up having to removethe prerelease tag to avoid the error.

This is not ideal.

Analasys

vn = VersionNumber("0.1.0-naha")
v"0.1.0-naha"

is a valid VersionNumber with a prerelease tag:

vn.prerelease
("naha",)

but it does not parse as a VersionSpec:

Pkg.Types.VersionSpec("0.1.0-naha")
ERROR: ArgumentError: invalid base 10 digit 'n' in "naha"
Stacktrace:
 [1] tryparse_internal(#unused#::Type{Int64}, s::SubString{String}, startpos::Int64, endpos::Int64, base_::Int64, raise::Bool)
   @ Base .\parse.jl:137
 [2] parse(::Type{Int64}, s::SubString{String}; base::Nothing)
   @ Base .\parse.jl:241
 [3] parse
   @ .\parse.jl:241 [inlined]
 [4] Pkg.Types.VersionBound(s::SubString{String})
   @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\versions.jl:99
 [5] Pkg.Types.VersionRange(s::String)
   @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\versions.jl:146
 [6] Pkg.Types.VersionSpec(s::String)
   @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\versions.jl:227
 [7] top-level scope
   @ none:1

This is not the error I get when Julia tries to parse my "offending" compat entry. That error was

Pkg.add(; url="https://github.com/MarkNahabedian/ShaperOriginDesignLib")
    Updating git-repo `https://github.com/MarkNahabedian/ShaperOriginDesignLib`
ERROR: Could not parse compatibility version for dependency `NativeSVG`
Stacktrace:
  [1] pkgerror(msg::String)
    @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\Types.jl:55
  [2] read_project_compat(raw::Dict{String, Any}, project::Pkg.Types.Project)
    @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\project.jl:66
  [3] Pkg.Types.Project(raw::Dict{String, Any})
    @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\project.jl:121
  [4] read_project(f_or_io::String)
    @ Pkg.Types C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\Pkg\src\project.jl:136

I believe this error is because my version string doesn't match the regular expressions at the end of Julia-1.6.0/share/julia/stdlib/v1.6/Pkg/src/versions.jl.

Note that these regular expressions do not incorporate the regular expression Base.VERSION_REGEX (used to parse a VersionNumber). It seems to me poor practtice that there are two different definitions of the syntax of a version number which could diverge under future development.

Note that a VersionSpec can be constructed from such a VersionNumber though:

Pkg.Types.VersionSpec(VersionNumber("0.1.0-naha"))
VersionSpec("0.1.0")

though the prerelease tag is lost in the process.

I don't know what the formal specification is meant to be, but I infer or observe that

  • one should be able to determine if a VersionNumber falls within a VersionRange;

  • a VersionSpec represents a set of VersionRanges;

SemVer provides a BNF.

It appears that Julia's VersionNumber corresponds to the <valid semver> nonterminal in that BNF.

I don't see anything in the BNF that corresponds to VersionRange.

The problem with the VersionRange syntax implemented in JUlia is that - can either separate the two extrema of a VersionRange or introduce the prerelease identifier of a VersionNumber.

The colon character : is not a terminal in the SemVer BNF. Perhaps it should be used to separate the extrema of a VersionRange. This is consistent with the use of : as Julia's range operator.

Alternatively, one might want to specify open or closed ends of a VersionRange. In that case, perhaps the separators <, =<, <= and =<= might be a way to specify that.

This would be an incompatible change.

MarkNahabedian avatar Oct 21 '21 15:10 MarkNahabedian