Skip to content

Commit

Permalink
add GetJuliaScratchspace to JuliaInterface (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBreuer authored Sep 4, 2024
1 parent 71d71f8 commit 35d7fa1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pkg/JuliaInterface/gap/JuliaInterface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,18 @@ DeclareGlobalFunction( "CallJuliaFunctionWithKeywordArguments" );
#TODO: add the cross-references to MatElm, SetMatElm when they are documented

#! @InsertChunk JuliaHelpInGAP

#! @Section Utilities

#! @Arguments key
#! @Returns a string
#! @Description
#! Returns the path of a &Julia; scratchspace associated to the given key.
#! This scratchspace gets created if it did not exist already,
#! one can rely on the fact that the returned path describes a writable
#! directory.
#! Subsequent calls with the same key yield the same result,
#! and calls with different keys yield different results.
#! The directory may be removed by &Julia; as soon as the &Julia; package
#! <C>GAP.jl</C> gets uninstalled.
DeclareGlobalFunction( "GetJuliaScratchspace" );
10 changes: 10 additions & 0 deletions pkg/JuliaInterface/gap/JuliaInterface.gi
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@ InstallGlobalFunction( JuliaModule,
return JuliaPointer( Julia.(name) );
end );


InstallGlobalFunction( GetJuliaScratchspace,
function( key )
if not IsString( key ) then
Error( "GetJuliaScratchspace: <key> must be a string" );
fi;
key:= Julia.Base.string( key );
return JuliaToGAP( IsString,
Julia.GAP.get_scratch_helper\!( key ) );
end );
9 changes: 8 additions & 1 deletion pkg/JuliaInterface/tst/utils.tst
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@ gap> Unbind(Julia.Main.f00bar);
Error, cannot unbind Julia variables

##
gap> STOP_TEST( "utils.tst", 1 );
gap> GetJuliaScratchspace( true);
Error, GetJuliaScratchspace: <key> must be a string
gap> path:= GetJuliaScratchspace( "test_scratch" );;
gap> IsDirectoryPath( path );
true

##
gap> STOP_TEST( "utils.tst" );
8 changes: 8 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ function Base.functionloc(f::GapObj)
return (String(file), ln)
end

import Scratch: get_scratch!

# Return the path of a Julia scratchspace with name `key`.
# This scratchspace gets created if it did not exist already.
# The scratchspace may be removed by Julia as soon as the Julia package GAP.jl
# gets uninstalled.
get_scratch_helper!(key::String) = get_scratch!(GAP, key)

# Allow `InteractiveUtils.edit(GAP.Globals.Group)` and similar for any global
# function. Not (yet?) useful for GAP operations, but better than nothing.
import InteractiveUtils: edit
Expand Down

0 comments on commit 35d7fa1

Please sign in to comment.