Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ReadPackage to print a warning if specified file cannot be read (e.g. because it is missing) #5762

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
#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 @@
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 @@
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 @@
MakeReadWriteGlobal( "REREADING" );
REREADING:= true;
MakeReadOnlyGlobal( "REREADING" );
res:= CallFuncList( ReadPackage, arg );
res:= _ReadPackage( arg, false );
MakeReadWriteGlobal( "REREADING" );
REREADING:= false;
MakeReadOnlyGlobal( "REREADING" );
Expand Down
Loading