From 7964cd5160a71f641631ef60d56a291876408e4e Mon Sep 17 00:00:00 2001 From: Mohamed Barakat Date: Tue, 5 May 2020 19:23:14 +0200 Subject: [PATCH] fixed AvailabilityTest and added ExternalConditions * avoid using IO_FindExecutable in AvailabilityTest as suggested by @alex-konovalov in https://github.com/homalg-project/homalg_project/issues/329#issuecomment-624017698 * added ExternalConditions as suggested by @alex-konovalov in https://github.com/homalg-project/homalg_project/issues/189#issuecomment-623985760 Closes #189 and closes #329. --- 4ti2Interface/PackageInfo.g | 11 ++-- 4ti2Interface/gap/4ti2Interface.gd | 1 + 4ti2Interface/gap/4ti2Interface.gi | 102 ++++++++++------------------- 3 files changed, 40 insertions(+), 74 deletions(-) diff --git a/4ti2Interface/PackageInfo.g b/4ti2Interface/PackageInfo.g index 0c4b8a3c7..caf279500 100644 --- a/4ti2Interface/PackageInfo.g +++ b/4ti2Interface/PackageInfo.g @@ -9,7 +9,7 @@ Version := Maximum( [ ## this line prevents merge conflicts "2018.07.06", ## Kamal's version ## this line prevents merge conflicts - "2020.05.04", ## Mohamed's version + "2020.05.05", ## Mohamed's version ] ), Date := ~.Version{[ 1 .. 10 ]}, @@ -66,9 +66,7 @@ Dependencies := rec( GAP := ">=4.7", NeededOtherPackages := [ [ "io", ">=4.2" ] ], SuggestedOtherPackages := [ [ "AutoDoc", ">=2013.08.22" ] ], - OtherPackagesLoadedInAdvance := [ [ "io", ">=4.2" ] ], - ExternalConditions := [] - + ExternalConditions := [ [ "4ti2", "https://4ti2.github.io/" ] ], ), AvailabilityTest := function() @@ -78,12 +76,13 @@ AvailabilityTest := function() "hilbert", "zsolve", "graver" ]; + Error( ); bool := ForAll( 4ti2_binaries, name -> - ( not ValueGlobal( "IO_FindExecutable" )( name ) = fail ) or - ( not ValueGlobal( "IO_FindExecutable" )( Concatenation( "4ti2-", name ) ) = fail ) ); + ( not Filename(DirectoriesSystemPrograms(), name ) = fail ) or + ( not Filename(DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) ) = fail ) ); if not bool then LogPackageLoadingMessage( PACKAGE_WARNING, diff --git a/4ti2Interface/gap/4ti2Interface.gd b/4ti2Interface/gap/4ti2Interface.gd index 7d85747b1..d6473e118 100644 --- a/4ti2Interface/gap/4ti2Interface.gd +++ b/4ti2Interface/gap/4ti2Interface.gd @@ -27,6 +27,7 @@ #! Copy it in your GAP pkg-directory. #! After this, the package can be loaded via LoadPackage( "4ti2Interface" ); +DeclareGlobalVariable( "4ti2Interface_BINARIES" ); #! @Chapter 4ti2 functions diff --git a/4ti2Interface/gap/4ti2Interface.gi b/4ti2Interface/gap/4ti2Interface.gi index 8dc1529bd..099e0856d 100644 --- a/4ti2Interface/gap/4ti2Interface.gi +++ b/4ti2Interface/gap/4ti2Interface.gi @@ -8,6 +8,26 @@ ## ############################################################################# +InstallValue( 4ti2Interface_BINARIES, + rec( + required_binaries := [ "groebner", "hilbert", "zsolve", "graver" ], + ) ); + +for name in 4ti2Interface_BINARIES.required_binaries do + path := Filename( DirectoriesSystemPrograms(), name ); + if IsStringRep( path ) then + 4ti2Interface_BINARIES.(name) := path; + continue; + fi; + path := Filename( DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) ); + if IsStringRep( path ) then + 4ti2Interface_BINARIES.(name) := path; + continue; + fi; + ## the AvailabilityTest in the PackageInfo will prevent this error from being raised + Error( "4ti2 cannot be found on your system\n" ); +od; + ## InstallGlobalFunction( 4ti2Interface_Cut_Vector, @@ -171,14 +191,8 @@ InstallGlobalFunction( 4ti2Interface_groebner, 4ti2Interface_Write_Matrix_To_File( arg[ 2 ], Concatenation( filename, ".cost" ) ); fi; - - if IO_FindExecutable( "groebner" ) <> fail then - exec := IO_FindExecutable( "groebner" ); - elif IO_FindExecutable( "4ti2-groebner" ) <> fail then - exec := IO_FindExecutable( "4ti2-groebner" ); - else - Error( "4ti2 can not be found" ); - fi; + + exec := 4ti2Interface_BINARIES.groebner; precision := ValueOption( "precision" ); @@ -247,14 +261,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities, sign_list := [ List( matrix[ 1 ], i -> 0 ) ]; 4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) ); - - if IO_FindExecutable( "hilbert" ) <> fail then - exec := IO_FindExecutable( "hilbert" ); - elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then - exec := IO_FindExecutable( "4ti2-hilbert" ); - else - Error( "4ti2 can not be found" ); - fi; + + exec := 4ti2Interface_BINARIES.hilbert; precision := ValueOption( "precision" ); @@ -303,15 +311,9 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities_in_positive_orthant, rel_list := [ List( matrix, i -> ">" ) ]; 4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) ); - - if IO_FindExecutable( "hilbert" ) <> fail then - exec := IO_FindExecutable( "hilbert" ); - elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then - exec := IO_FindExecutable( "4ti2-hilbert" ); - else - Error( "4ti2 can not be found" ); - fi; + exec := 4ti2Interface_BINARIES.hilbert; + precision := ValueOption( "precision" ); if IsInt( precision ) then @@ -360,13 +362,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_in_positive_orthant, 4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) ); - if IO_FindExecutable( "hilbert" ) <> fail then - exec := IO_FindExecutable( "hilbert" ); - elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then - exec := IO_FindExecutable( "4ti2-hilbert" ); - else - Error( "4ti2 can not be found" ); - fi; + exec := 4ti2Interface_BINARIES.hilbert; precision := ValueOption( "precision" ); @@ -422,14 +418,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities, sign_list := [ List( concat_list[ 1 ] , i -> 0 ) ]; 4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) ); - - if IO_FindExecutable( "hilbert" ) <> fail then - exec := IO_FindExecutable( "hilbert" ); - elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then - exec := IO_FindExecutable( "4ti2-hilbert" ); - else - Error( "4ti2 can not be found" ); - fi; + + exec := 4ti2Interface_BINARIES.hilbert; precision := ValueOption( "precision" ); @@ -486,13 +476,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities_in_posi 4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) ); - if IO_FindExecutable( "hilbert" ) <> fail then - exec := IO_FindExecutable( "hilbert" ); - elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then - exec := IO_FindExecutable( "4ti2-hilbert" ); - else - Error( "4ti2 can not be found" ); - fi; + exec := 4ti2Interface_BINARIES.hilbert; precision := ValueOption( "precision" ); @@ -585,14 +569,8 @@ InstallGlobalFunction( 4ti2Interface_zsolve_equalities_and_inequalities, concat_rhs := [ Concatenation( eqs_rhs, ineqs_rhs ) ]; 4ti2Interface_Write_Matrix_To_File( concat_rhs, Concatenation( filename, ".rhs" ) ); - - if IO_FindExecutable( "zsolve" ) <> fail then - exec := IO_FindExecutable( "zsolve" ); - elif IO_FindExecutable( "4ti2-zsolve" ) <> fail then - exec := IO_FindExecutable( "4ti2-zsolve" ); - else - Error( "4ti2 can not be found" ); - fi; + + exec := 4ti2Interface_BINARIES.zsolve; precision := ValueOption( "precision" ); @@ -708,13 +686,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities, 4ti2Interface_Write_Matrix_To_File( signs, Concatenation( filename, ".sign" ) ); - if IO_FindExecutable( "graver" ) <> fail then - exec := IO_FindExecutable( "graver" ); - elif IO_FindExecutable( "4ti2-graver" ) <> fail then - exec := IO_FindExecutable( "4ti2-graver" ); - else - Error( "4ti2 can not be found" ); - fi; + exec := 4ti2Interface_BINARIES.graver; precision := ValueOption( "precision" ); @@ -755,13 +727,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities_in_positive_orthant, 4ti2Interface_Write_Matrix_To_File( eqs, Concatenation( filename, ".mat" ) ); - if IO_FindExecutable( "graver" ) <> fail then - exec := IO_FindExecutable( "graver" ); - elif IO_FindExecutable( "4ti2-graver" ) <> fail then - exec := IO_FindExecutable( "4ti2-graver" ); - else - Error( "4ti2 can not be found" ); - fi; + exec := 4ti2Interface_BINARIES.graver; precision := ValueOption( "precision" );