From d08123eaab93f4b924571478fcabee5bad44a5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunnar=20Farneb=C3=A4ck?= Date: Thu, 2 Dec 2021 20:14:43 +0100 Subject: [PATCH] Adapt to changes in Pkg internals in Julia 1.7. --- Project.toml | 2 +- src/PackageCompatUI.jl | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 5cb5b6b..d6996e0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PackageCompatUI" uuid = "65465c31-362d-417a-a2f0-7fa38ae507b9" authors = ["Gunnar Farnebäck "] -version = "1.0.0" +version = "1.0.1" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/PackageCompatUI.jl b/src/PackageCompatUI.jl index 23717be..fc2cab4 100644 --- a/src/PackageCompatUI.jl +++ b/src/PackageCompatUI.jl @@ -65,15 +65,34 @@ function compat_ui(;pagesize = 20, dates = true) versions["julia"] = get_julia_versions() version_dates["julia"] = Dict{String, String}() packages = vcat("julia", sort(collect(keys(needs_compat)))) - data = MenuData(packages, project.compat, versions, version_dates) + data = MenuData(packages, extract_compat_string(project.compat), + versions, version_dates) menu = Menu(data, pagesize) menu.cursor[] = selected request(menu, cursor = menu.cursor) - project.compat = data.compat + set_project_compat!(project, data.compat) Pkg.Types.write_project(project, Base.active_project()) return end +# Compatibility layer to handle Pkg internals changes between Julia 1.6 +# and Julia 1.7. +extract_compat_string(compat::Dict) = Dict(k => extract_compat_string(v) + for (k, v) in compat) +extract_compat_string(compat::String) = compat +extract_compat_string(compat) = compat.str +set_project_compat!(project_compat::Dict{String, String}, new_compat) = + merge!(empty!(project_compat), new_compat) +function set_project_compat!(project, compat) + if project.compat isa Dict{String, String} + project.compat = compat + else + for (package, compat_string) in compat + Pkg.Operations.set_compat(project, package, compat_string) + end + end +end + function gitcmd(repo) git = Git.git(["-C", repo]) return (x...) -> readlines(`$git $x`)