Skip to content

Commit 0d9f2e7

Browse files
fixed AvailabilityTest and added ExternalConditions
* avoid using IO_FindExecutable in AvailabilityTest as suggested by @alex-konovalov in #329 (comment) * added ExternalConditions as suggested by @alex-konovalov in #189 (comment) Closes #189 and closes #329.
1 parent 2ffa65a commit 0d9f2e7

File tree

3 files changed

+39
-74
lines changed

3 files changed

+39
-74
lines changed

Diff for: 4ti2Interface/PackageInfo.g

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Version := Maximum( [
99
## this line prevents merge conflicts
1010
"2018.07.06", ## Kamal's version
1111
## this line prevents merge conflicts
12-
"2020.05.04", ## Mohamed's version
12+
"2020.05.05", ## Mohamed's version
1313
] ),
1414

1515
Date := ~.Version{[ 1 .. 10 ]},
@@ -66,9 +66,7 @@ Dependencies := rec(
6666
GAP := ">=4.7",
6767
NeededOtherPackages := [ [ "io", ">=4.2" ] ],
6868
SuggestedOtherPackages := [ [ "AutoDoc", ">=2013.08.22" ] ],
69-
OtherPackagesLoadedInAdvance := [ [ "io", ">=4.2" ] ],
70-
ExternalConditions := []
71-
69+
ExternalConditions := [ [ "4ti2", "https://4ti2.github.io/" ] ],
7270
),
7371

7472
AvailabilityTest := function()
@@ -82,8 +80,8 @@ AvailabilityTest := function()
8280
bool :=
8381
ForAll( 4ti2_binaries,
8482
name ->
85-
( not ValueGlobal( "IO_FindExecutable" )( name ) = fail ) or
86-
( not ValueGlobal( "IO_FindExecutable" )( Concatenation( "4ti2-", name ) ) = fail ) );
83+
( not Filename(DirectoriesSystemPrograms(), name ) = fail ) or
84+
( not Filename(DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) ) = fail ) );
8785

8886
if not bool then
8987
LogPackageLoadingMessage( PACKAGE_WARNING,

Diff for: 4ti2Interface/gap/4ti2Interface.gd

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#! Copy it in your GAP pkg-directory.
2828
#! After this, the package can be loaded via LoadPackage( "4ti2Interface" );
2929

30+
DeclareGlobalVariable( "4ti2Interface_BINARIES" );
3031

3132
#! @Chapter 4ti2 functions
3233

Diff for: 4ti2Interface/gap/4ti2Interface.gi

+34-68
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
##
99
#############################################################################
1010

11+
InstallValue( 4ti2Interface_BINARIES,
12+
rec(
13+
required_binaries := [ "groebner", "hilbert", "zsolve", "graver" ],
14+
) );
15+
16+
for name in 4ti2Interface_BINARIES.required_binaries do
17+
path := Filename( DirectoriesSystemPrograms(), name );
18+
if IsStringRep( path ) then
19+
4ti2Interface_BINARIES.(name) := path;
20+
continue;
21+
fi;
22+
path := Filename( DirectoriesSystemPrograms(), Concatenation( "4ti2-", name ) );
23+
if IsStringRep( path ) then
24+
4ti2Interface_BINARIES.(name) := path;
25+
continue;
26+
fi;
27+
## the AvailabilityTest in the PackageInfo will prevent this error from being raised
28+
Error( "4ti2 cannot be found on your system\n" );
29+
od;
30+
1131
##
1232
InstallGlobalFunction( 4ti2Interface_Cut_Vector,
1333

@@ -171,14 +191,8 @@ InstallGlobalFunction( 4ti2Interface_groebner,
171191
4ti2Interface_Write_Matrix_To_File( arg[ 2 ], Concatenation( filename, ".cost" ) );
172192

173193
fi;
174-
175-
if IO_FindExecutable( "groebner" ) <> fail then
176-
exec := IO_FindExecutable( "groebner" );
177-
elif IO_FindExecutable( "4ti2-groebner" ) <> fail then
178-
exec := IO_FindExecutable( "4ti2-groebner" );
179-
else
180-
Error( "4ti2 can not be found" );
181-
fi;
194+
195+
exec := 4ti2Interface_BINARIES.groebner;
182196

183197
precision := ValueOption( "precision" );
184198

@@ -247,14 +261,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities,
247261
sign_list := [ List( matrix[ 1 ], i -> 0 ) ];
248262

249263
4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );
250-
251-
if IO_FindExecutable( "hilbert" ) <> fail then
252-
exec := IO_FindExecutable( "hilbert" );
253-
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
254-
exec := IO_FindExecutable( "4ti2-hilbert" );
255-
else
256-
Error( "4ti2 can not be found" );
257-
fi;
264+
265+
exec := 4ti2Interface_BINARIES.hilbert;
258266

259267
precision := ValueOption( "precision" );
260268

@@ -303,15 +311,9 @@ InstallGlobalFunction( 4ti2Interface_hilbert_inequalities_in_positive_orthant,
303311
rel_list := [ List( matrix, i -> ">" ) ];
304312

305313
4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) );
306-
307-
if IO_FindExecutable( "hilbert" ) <> fail then
308-
exec := IO_FindExecutable( "hilbert" );
309-
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
310-
exec := IO_FindExecutable( "4ti2-hilbert" );
311-
else
312-
Error( "4ti2 can not be found" );
313-
fi;
314314

315+
exec := 4ti2Interface_BINARIES.hilbert;
316+
315317
precision := ValueOption( "precision" );
316318

317319
if IsInt( precision ) then
@@ -360,13 +362,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_in_positive_orthant,
360362

361363
4ti2Interface_Write_Matrix_To_File( rel_list, Concatenation( filename, ".rel" ) );
362364

363-
if IO_FindExecutable( "hilbert" ) <> fail then
364-
exec := IO_FindExecutable( "hilbert" );
365-
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
366-
exec := IO_FindExecutable( "4ti2-hilbert" );
367-
else
368-
Error( "4ti2 can not be found" );
369-
fi;
365+
exec := 4ti2Interface_BINARIES.hilbert;
370366

371367
precision := ValueOption( "precision" );
372368

@@ -422,14 +418,8 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities,
422418
sign_list := [ List( concat_list[ 1 ] , i -> 0 ) ];
423419

424420
4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );
425-
426-
if IO_FindExecutable( "hilbert" ) <> fail then
427-
exec := IO_FindExecutable( "hilbert" );
428-
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
429-
exec := IO_FindExecutable( "4ti2-hilbert" );
430-
else
431-
Error( "4ti2 can not be found" );
432-
fi;
421+
422+
exec := 4ti2Interface_BINARIES.hilbert;
433423

434424
precision := ValueOption( "precision" );
435425

@@ -486,13 +476,7 @@ InstallGlobalFunction( 4ti2Interface_hilbert_equalities_and_inequalities_in_posi
486476

487477
4ti2Interface_Write_Matrix_To_File( sign_list, Concatenation( filename, ".sign" ) );
488478

489-
if IO_FindExecutable( "hilbert" ) <> fail then
490-
exec := IO_FindExecutable( "hilbert" );
491-
elif IO_FindExecutable( "4ti2-hilbert" ) <> fail then
492-
exec := IO_FindExecutable( "4ti2-hilbert" );
493-
else
494-
Error( "4ti2 can not be found" );
495-
fi;
479+
exec := 4ti2Interface_BINARIES.hilbert;
496480

497481
precision := ValueOption( "precision" );
498482

@@ -585,14 +569,8 @@ InstallGlobalFunction( 4ti2Interface_zsolve_equalities_and_inequalities,
585569
concat_rhs := [ Concatenation( eqs_rhs, ineqs_rhs ) ];
586570

587571
4ti2Interface_Write_Matrix_To_File( concat_rhs, Concatenation( filename, ".rhs" ) );
588-
589-
if IO_FindExecutable( "zsolve" ) <> fail then
590-
exec := IO_FindExecutable( "zsolve" );
591-
elif IO_FindExecutable( "4ti2-zsolve" ) <> fail then
592-
exec := IO_FindExecutable( "4ti2-zsolve" );
593-
else
594-
Error( "4ti2 can not be found" );
595-
fi;
572+
573+
exec := 4ti2Interface_BINARIES.zsolve;
596574

597575
precision := ValueOption( "precision" );
598576

@@ -708,13 +686,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities,
708686

709687
4ti2Interface_Write_Matrix_To_File( signs, Concatenation( filename, ".sign" ) );
710688

711-
if IO_FindExecutable( "graver" ) <> fail then
712-
exec := IO_FindExecutable( "graver" );
713-
elif IO_FindExecutable( "4ti2-graver" ) <> fail then
714-
exec := IO_FindExecutable( "4ti2-graver" );
715-
else
716-
Error( "4ti2 can not be found" );
717-
fi;
689+
exec := 4ti2Interface_BINARIES.graver;
718690

719691
precision := ValueOption( "precision" );
720692

@@ -755,13 +727,7 @@ InstallGlobalFunction( 4ti2Interface_graver_equalities_in_positive_orthant,
755727

756728
4ti2Interface_Write_Matrix_To_File( eqs, Concatenation( filename, ".mat" ) );
757729

758-
if IO_FindExecutable( "graver" ) <> fail then
759-
exec := IO_FindExecutable( "graver" );
760-
elif IO_FindExecutable( "4ti2-graver" ) <> fail then
761-
exec := IO_FindExecutable( "4ti2-graver" );
762-
else
763-
Error( "4ti2 can not be found" );
764-
fi;
730+
exec := 4ti2Interface_BINARIES.graver;
765731

766732
precision := ValueOption( "precision" );
767733

0 commit comments

Comments
 (0)