Skip to content

Commit

Permalink
Add options to debug package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Aug 21, 2023
1 parent 368aa65 commit 63d828b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
34 changes: 24 additions & 10 deletions src/packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function init_packagemanager()
# put the new method in the first position
meths = Globals.Download_Methods
Wrappers.Add(meths, GapObj(r, recursive=true), 1)

# monkey patch PackageManager so that we can disable removal of
# package directories for debugging purposes
orig_PKGMAN_RemoveDir = Globals.PKGMAN_RemoveDir
replace_global!(:PKGMAN_RemoveDir, function(dir)
Globals.ValueOption(GapObj("debug")) == true && return
orig_PKGMAN_RemoveDir(dir)
end)
end
end

Expand Down Expand Up @@ -186,6 +194,7 @@ end
"""
install(spec::String, version::String = "";
interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
Download and install the GAP package given by `spec` into the `pkgdir`
Expand Down Expand Up @@ -213,19 +222,20 @@ For details, please refer to its documentation.
"""
function install(spec::String, version::String = "";
interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)

if quiet
if quiet || debug
oldlevel = Wrappers.InfoLevel(Globals.InfoPackageManager)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, 0)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, quiet ? 0 : 3)
end
if version == ""
res = Wrappers.InstallPackage(GapObj(spec), interactive)
res = Globals.InstallPackage(GapObj(spec), interactive; debug)
else
res = Wrappers.InstallPackage(GapObj(spec), GapObj(version), interactive)
res = Globals.InstallPackage(GapObj(spec), GapObj(version), interactive; debug)
end
if quiet
Wrappers.SetInfoLevel(Globals.InfoPackageManager, oldlevel)
Expand All @@ -235,6 +245,7 @@ end

"""
update(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
Update the GAP package given by `spec` that is installed in the
Expand All @@ -253,15 +264,16 @@ prevent `PackageManager` from prompting the user for input interactively.
For details, please refer to its documentation.
"""
function update(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)

if quiet
if quiet || debug
oldlevel = Wrappers.InfoLevel(Globals.InfoPackageManager)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, 0)
res = Wrappers.UpdatePackage(GapObj(spec), interactive)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, quiet ? 0 : 3)
res = Globals.UpdatePackage(GapObj(spec), interactive; debug)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, oldlevel)
return res
else
Expand All @@ -274,6 +286,7 @@ end

"""
remove(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = GAP.Packages.DEFAULT_PKGDIR[])
Remove the GAP package with name `spec` that is installed in the
Expand All @@ -288,15 +301,16 @@ prevent `PackageManager` from prompting the user for input interactively.
For details, please refer to its documentation.
"""
function remove(spec::String; interactive::Bool = true, quiet::Bool = false,
debug::Bool = false,
pkgdir::AbstractString = DEFAULT_PKGDIR[])
# point PackageManager to the given pkg dir
Globals.PKGMAN_CustomPackageDir = GapObj(pkgdir)
mkpath(pkgdir)

if quiet
if quiet || debug
oldlevel = Wrappers.InfoLevel(Globals.InfoPackageManager)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, 0)
res = Wrappers.RemovePackage(GapObj(spec), interactive)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, quiet ? 0 : 3)
res = Globals.RemovePackage(GapObj(spec), interactive; debug)
Wrappers.SetInfoLevel(Globals.InfoPackageManager, oldlevel)
return res
else
Expand Down
4 changes: 0 additions & 4 deletions src/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import GAP: @wrap
@wrap IN(x::Any, y::Any)::Bool
@wrap InfoLevel(x::GapObj)::Int
@wrap INT_CHAR(x::Any)::Int
@wrap InstallPackage(x::GapObj, y::Bool)::Bool
@wrap InstallPackage(x::GapObj, y::GapObj, z::Bool)::Bool
@wrap InverseSameMutability(x::Any)::Any
@wrap IS_JULIA_FUNC(x::Any)::Bool
@wrap ISB_LIST(x::Any, i::Int)::Bool
Expand Down Expand Up @@ -68,7 +66,6 @@ import GAP: @wrap
@wrap QUO(x::Any, y::Any)::Any
@wrap Read(x::GapObj)::Nothing
@wrap RecNames(x::Any)::Any
@wrap RemovePackage(x::GapObj, y::Bool)::Bool
@wrap RNamObj(x::Any)::Int
@wrap SetInfoLevel(x::GapObj, y::Int)::Nothing
@wrap SetPackagePath(x::GapObj, y::GapObj)::Nothing
Expand All @@ -79,7 +76,6 @@ import GAP: @wrap
@wrap StructuralCopy(x::Any)::Any
@wrap SUM(x::Any, y::Any)::Any
@wrap UNB_REC(x::GapObj, y::Int)::Nothing
@wrap UpdatePackage(x::GapObj, y::Bool)::Bool
@wrap ZeroSameMutability(x::Any)::Any

end

0 comments on commit 63d828b

Please sign in to comment.