Pkg.jl: VersionSpec printed incorrectly

Created on 16 Apr 2019  路  6Comments  路  Source: JuliaLang/Pkg.jl

AFAICT this is the cause of the various issues in the new registry (https://github.com/JuliaRegistries/General/pull/59, https://github.com/JuliaRegistries/General/pull/75) where the a compat entry would look like "[0.7, 1]" instead of the correct ["0.7", "1"].

Repro and possible fix:

julia> using Pkg

julia> Pkg.TOML.print(stdout, Dict("julia" => Pkg.Types.VersionSpec(["0.1", "0.8-1"])))
julia = "[0.1, 0.8-1]"

julia> function Pkg.TOML.printvalue(io::IO, s::Pkg.Types.VersionSpec;sorted=false)
           isempty(s) && return print(io, _empty_symbol)
           length(s.ranges) == 1 && return print(io, s.ranges[1])
           print(io, '[')
           for i = 1:length(s.ranges)
               1 < i && print(io, ", ")
               print(io, '"', s.ranges[i], '"')
           end
           print(io, ']')
       end

julia> Pkg.TOML.print(stdout, Dict("julia" => Pkg.Types.VersionSpec(["0.1", "0.8-1"])))
julia = ["0.1", "0.8-1"]
bug

Most helpful comment

Thanks, @nkottary, that makes sense. I guess this is why we need more tests鈥攕o we can't merge completely broken code to master without realizing it 馃槀

All 6 comments

I am guessing Registrator can just monkey patch that for now. Would of course be nice to add the fix here but won't propagate to julia until 1.2.

Yeah, would be good to get that in asap.

It's not a bug per se since VersionSpec objects can print however they want, the actual bug is that Registrator shouldn't be relying on stringification of VersionSpec objects like this at all, although changing this is one way to fix it. The appropriate fix is to change this logic:

https://github.com/JuliaComputing/Registrator.jl/blob/b539fdd6350fede2/src/regedit/register.jl#L291

It should also be fixed to call compress_versions appropriately. I've tried making this change but I'm unable to run the code which does not seem to be functional since DEFAULT_REGISTRY and REGISTRIES are defined in the top-level Registrator module but used from Registrator.RegEdit without being imported. I can only surmise that the code that's on master is not what's running; perhaps @nkottary can clarify?

The running Registrator is a bunch of commits behind master: https://github.com/JuliaComputing/Registrator.jl/commit/5d26d20c976877aaee6fee6a0e538d4a6fe1d667

...where those definitions are in scope.

Thanks, @nkottary, that makes sense. I guess this is why we need more tests鈥攕o we can't merge completely broken code to master without realizing it 馃槀

Some way to serialize and deserialize VersionSpec instances to/from strings would be really valuable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

innerlee picture innerlee  路  4Comments

cscherrer picture cscherrer  路  3Comments

jlperla picture jlperla  路  3Comments

cossio picture cossio  路  3Comments

omus picture omus  路  4Comments