From 35d7fa1128757f2adc6c14be810a64a1b668410e Mon Sep 17 00:00:00 2001 From: Thomas Breuer Date: Wed, 4 Sep 2024 13:41:55 +0200 Subject: [PATCH] add `GetJuliaScratchspace` to `JuliaInterface` (#1030) --- pkg/JuliaInterface/gap/JuliaInterface.gd | 15 +++++++++++++++ pkg/JuliaInterface/gap/JuliaInterface.gi | 10 ++++++++++ pkg/JuliaInterface/tst/utils.tst | 9 ++++++++- src/utils.jl | 8 ++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/JuliaInterface/gap/JuliaInterface.gd b/pkg/JuliaInterface/gap/JuliaInterface.gd index bdd5c6cc4..5772cb116 100644 --- a/pkg/JuliaInterface/gap/JuliaInterface.gd +++ b/pkg/JuliaInterface/gap/JuliaInterface.gd @@ -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 +#! GAP.jl gets uninstalled. +DeclareGlobalFunction( "GetJuliaScratchspace" ); diff --git a/pkg/JuliaInterface/gap/JuliaInterface.gi b/pkg/JuliaInterface/gap/JuliaInterface.gi index 169bab92c..5da6d7dc2 100644 --- a/pkg/JuliaInterface/gap/JuliaInterface.gi +++ b/pkg/JuliaInterface/gap/JuliaInterface.gi @@ -166,3 +166,13 @@ InstallGlobalFunction( JuliaModule, return JuliaPointer( Julia.(name) ); end ); + +InstallGlobalFunction( GetJuliaScratchspace, + function( key ) + if not IsString( key ) then + Error( "GetJuliaScratchspace: must be a string" ); + fi; + key:= Julia.Base.string( key ); + return JuliaToGAP( IsString, + Julia.GAP.get_scratch_helper\!( key ) ); +end ); diff --git a/pkg/JuliaInterface/tst/utils.tst b/pkg/JuliaInterface/tst/utils.tst index 702a4d8c2..6100358d6 100644 --- a/pkg/JuliaInterface/tst/utils.tst +++ b/pkg/JuliaInterface/tst/utils.tst @@ -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: must be a string +gap> path:= GetJuliaScratchspace( "test_scratch" );; +gap> IsDirectoryPath( path ); +true + +## +gap> STOP_TEST( "utils.tst" ); diff --git a/src/utils.jl b/src/utils.jl index c37a2c413..be9769cdc 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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