Skip to content

Commit

Permalink
ReadPackage now raises a warning if file is missing / cannot be read
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Nov 8, 2024
1 parent 81659b1 commit bb7887e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/package.gd
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ DeclareGlobalFunction( "DirectoriesPackageLibrary" );
## package to be loaded.)
## <P/>
## If the file is readable then <K>true</K> is returned,
## otherwise <K>false</K>.
## otherwise a warning is displayed (for <Ref Func="ReadPackage"/>)
## or <K>false</K> is returned (for <Ref Func="RereadPackage"/>).
## <P/>
## Each of <A>name</A> and <A>file</A> should be a string.
## The <A>name</A> argument is case insensitive.
Expand Down
21 changes: 13 additions & 8 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ end );
#F ReadPackage( [<name>, ]<file> )
#F RereadPackage( [<name>, ]<file> )
##
InstallGlobalFunction( ReadPackage, function( arg )
BindGlobal( "_ReadPackage", function( arg, error )
local pos, relpath, pkgname, namespace, filename;

# Note that we cannot use `ReadAndCheckFunc' because this calls
Expand All @@ -1329,16 +1329,16 @@ InstallGlobalFunction( ReadPackage, function( arg )
if pos = fail then
ErrorNoReturn(arg[1], " is not a filename in the form 'package/filepath'");
fi;
pkgname:= arg[1]{ [ 1 .. pos-1 ] };
relpath:= arg[1]{ [ pos+1 .. Length( arg[1] ) ] };
pkgname:= LowercaseString( arg[1]{ [ 1 .. pos-1 ] } );
namespace := GAPInfo.PackagesInfo.(pkgname)[1].PackageName;
elif Length( arg ) = 2 then
pkgname:= LowercaseString( arg[1] );
namespace := GAPInfo.PackagesInfo.(pkgname)[1].PackageName;
pkgname:= arg[1];
relpath:= arg[2];
else
Error( "expected 1 or 2 arguments" );
fi;
pkgname:= LowercaseString( pkgname );
namespace := GAPInfo.PackagesInfo.(pkgname)[1].PackageName;

# Note that `DirectoriesPackageLibrary' finds the file relative to the
# installation path of the info record chosen in `LoadPackage'.
Expand All @@ -1348,9 +1348,14 @@ InstallGlobalFunction( ReadPackage, function( arg )
Read( filename );
LEAVE_NAMESPACE();
return true;
else
return false;
elif error then
Info(InfoWarning, 1, "ReadPackage could not read <", pkgname, ">/", relpath, "\n");

Check warning on line 1352 in lib/package.gi

View check run for this annotation

Codecov / codecov/patch

lib/package.gi#L1352

Added line #L1352 was not covered by tests
fi;
return false;
end );

InstallGlobalFunction( ReadPackage, function( arg )
return _ReadPackage( arg, true );
end );

InstallGlobalFunction( RereadPackage, function( arg )
Expand All @@ -1359,7 +1364,7 @@ InstallGlobalFunction( RereadPackage, function( arg )
MakeReadWriteGlobal( "REREADING" );
REREADING:= true;
MakeReadOnlyGlobal( "REREADING" );
res:= CallFuncList( ReadPackage, arg );
res:= _ReadPackage( arg, false );
MakeReadWriteGlobal( "REREADING" );
REREADING:= false;
MakeReadOnlyGlobal( "REREADING" );
Expand Down

0 comments on commit bb7887e

Please sign in to comment.