Skip to content

Commit

Permalink
User PKGMAN_UserPackageInfo more widely
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed Sep 5, 2024
1 parent d389649 commit f2bf481
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
8 changes: 4 additions & 4 deletions gap/PackageManager.gi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function(name, interactive...)
fi;

# Locate the package
info := PKGMAN_UserPackageInfo(name : expectUnique);
info := PKGMAN_UserPackageInfo(name : warnIfNone, warnIfMultiple);

# Need precisely one version
if Length(info) <> 1 then
Expand All @@ -97,8 +97,8 @@ end);

InstallGlobalFunction(UpdatePackage,
function(name, interactive...)
local user_pkg_dir, allinfo, info, dirs, vc, repo, dir, status, pull, line,
urls, newest, old, oldVer, olddir, q;
local user_pkg_dir, info, dirs, vc, repo, dir, status, pull, line, urls,
newest, old, oldVer, olddir, q;

# Check input
if not IsString(name) then
Expand All @@ -123,7 +123,7 @@ function(name, interactive...)
name := LowercaseString(name);

# Locate the package
info := PKGMAN_UserPackageInfo(name);
info := PKGMAN_UserPackageInfo(name : warnIfNone);

# Package not installed
if Length(info) = 0 then
Expand Down
4 changes: 2 additions & 2 deletions gap/compile.gi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
InstallGlobalFunction(CompilePackage,
function(name)
local user_pkg_dir, allinfo, info;
local info;

# Check input
if not IsString(name) then
Expand All @@ -10,7 +10,7 @@ function(name)

# Locate the package
name := LowercaseString(name);
info := PKGMAN_UserPackageInfo(name : expectUnique);
info := PKGMAN_UserPackageInfo(name : warnIfNone, warnIfMultiple);

# Package not installed
if Length(info) = 0 then
Expand Down
10 changes: 3 additions & 7 deletions gap/distro.gi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
InstallGlobalFunction(InstallPackageFromName,
function(name, args...)
local version, interactive, urls, allinfo, info, current, dirs, vc, q, newest;
local version, interactive, urls, info, current, dirs, vc, q, newest;

# Handle version condition and interactivity
version := true;
Expand Down Expand Up @@ -49,9 +49,7 @@ function(name, args...)
fi;

# Check for already-installed versions
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
info := PKGMAN_UserPackageInfo(name);
if not IsEmpty(info) then # Already installed
# Does the installed version already satisfy the prescribed version?
current := info[1]; # Highest-priority installation in user pkg directory
Expand Down Expand Up @@ -191,9 +189,7 @@ function(dir)
dep_infos := [];
for dep in to_install do
# Already installed, but needs recompiling?
current := Filtered(PackageInfo(dep[1]),
x -> StartsWith(x.InstallationPath,
PKGMAN_PackageDir()));
current := PKGMAN_UserPackageInfo(dep[1]);
if not IsEmpty(current) then
current := current[1];
if CompareVersionNumbers(current.Version, dep[2]) then
Expand Down
6 changes: 2 additions & 4 deletions gap/git.gi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
InstallGlobalFunction(InstallPackageFromGit,
function(url, args...)
local interactive, branch, name, dir, allinfo, info, dirs, repo, q, exec;
local interactive, branch, name, dir, info, dirs, repo, q, exec;

# Process args
interactive := true;
Expand Down Expand Up @@ -38,9 +38,7 @@ function(url, args...)
dir := Filename(Directory(PKGMAN_PackageDir()), name);

# Check for existing repository
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
info := PKGMAN_UserPackageInfo(name);
dirs := List(info, i -> ShallowCopy(i.InstallationPath));
repo := Filename(List(dirs, Directory), ".git");
if repo <> fail then # TODO: check it's the same remote?
Expand Down
6 changes: 2 additions & 4 deletions gap/hg.gi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
InstallGlobalFunction(InstallPackageFromHg,
function(url, args...)
local interactive, branch, name, dir, allinfo, info, dirs, repo, q, exec;
local interactive, branch, name, dir, info, dirs, repo, q, exec;

# Process args
interactive := true;
Expand Down Expand Up @@ -38,9 +38,7 @@ function(url, args...)
dir := Filename(Directory(PKGMAN_PackageDir()), name);

# Check for existing repository
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
info := PKGMAN_UserPackageInfo(name);
dirs := List(info, i -> ShallowCopy(i.InstallationPath));
repo := Filename(List(dirs, Directory), ".hg");
if repo <> fail then
Expand Down
11 changes: 5 additions & 6 deletions gap/packageinfo.gi
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,18 @@ function(info)
end);

# Return package info records for all packages installed with this name in the
# user package directory, and warn if there are none.
# expectUnique option: warn if there are multiple.
# user package directory.
# Use warnIfNone and warnIfMultiple options to print info warnings.
InstallGlobalFunction(PKGMAN_UserPackageInfo,
function(name)
local user_pkg_dir, allinfo, userinfo;

user_pkg_dir := PKGMAN_PackageDir();
allinfo := PackageInfo(name);
userinfo := Filtered(allinfo,
x -> IsMatchingSublist(x.InstallationPath, user_pkg_dir));
userinfo := Filtered(allinfo, i -> StartsWith(i.InstallationPath, user_pkg_dir));

# Package not found
if Length(userinfo) = 0 then
if ValueOption("warnIfNone") = true and Length(userinfo) = 0 then
Info(InfoPackageManager, 1, "Package \"", name, "\" not installed in user package directory");
Info(InfoPackageManager, 2, "(currently set to ", PKGMAN_PackageDir(), ")");
if not IsEmpty(allinfo) then
Expand All @@ -98,7 +97,7 @@ function(name)
fi;

# Multiple versions found
if ValueOption("expectUnique") = true and Length(userinfo) > 1 then
if ValueOption("warnIfMultiple") = true and Length(userinfo) > 1 then
Info(InfoPackageManager, 1, "Multiple versions of package ", name, " installed");
Info(InfoPackageManager, 2, "at ", List(userinfo, i -> i.InstallationPath));
fi;
Expand Down

0 comments on commit f2bf481

Please sign in to comment.