Skip to content

Commit

Permalink
Separate git.* and hg.* files
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed Sep 3, 2024
1 parent 64c2dc9 commit 4287f7b
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 310 deletions.
23 changes: 0 additions & 23 deletions gap/PackageManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,6 @@ DeclareGlobalFunction("InstallPackageFromInfo");
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("InstallPackageFromArchive");

#! @Description
#! Attempts to download and install a package from a git repository located at
#! the given URL. Returns <K>false</K> if something went wrong, and
#! <K>true</K> otherwise.
#!
#! If the optional string argument <A>branch</A> is specified, this function
#! will install the branch with this name. Otherwise, the repository's
#! default branch will be used.
#!
#! Certain decisions, such as installing newer versions of packages, will be
#! confirmed by the user via an interactive shell &ndash; to avoid this
#! interactivity and use sane defaults instead, the optional second argument
#! <A>interactive</A> can be set to <K>false</K>.
#! @Arguments url[, interactive][, branch]
#! @Returns
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("InstallPackageFromGit");

# DEPRECATED
DeclareGlobalFunction("InstallPackageFromHg");

#! @Description
#! Attempts to download and install the latest versions of all packages
#! required for &GAP; to run. Currently these packages are
Expand Down Expand Up @@ -228,8 +207,6 @@ DeclareGlobalFunction("GetPackageURLs");
DeclareGlobalFunction("PKGMAN_InstallDependencies");
DeclareGlobalFunction("PKGMAN_CheckPackage");
DeclareGlobalFunction("PKGMAN_Exec");
DeclareGlobalFunction("PKGMAN_NameOfGitRepo");
DeclareGlobalFunction("PKGMAN_NameOfHgRepo");
DeclareGlobalFunction("PKGMAN_PackageDir");
DeclareGlobalFunction("PKGMAN_CreateDirRecursively");
DeclareGlobalFunction("PKGMAN_IsValidTargetDir");
Expand Down
216 changes: 0 additions & 216 deletions gap/PackageManager.gi
Original file line number Diff line number Diff line change
Expand Up @@ -343,194 +343,6 @@ function(url)
return true;
end);

InstallGlobalFunction(InstallPackageFromGit,
function(url, args...)
local interactive, branch, name, dir, allinfo, info, dirs, repo, q, exec;

# Process args
interactive := true;
branch := fail;
if Length(args) = 1 then
if args[1] in [true, false] then
interactive := args[1];
elif IsString(args[1]) then
branch := args[1];
else
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"2nd argument should be true, false, or a string");
fi;
elif Length(args) = 2 then
interactive := args[1];
branch := args[2];
if not interactive in [true, false] then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"<interactive> should be true or false");
elif not IsString(branch) then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"<branch> should be a string");
fi;
elif Length(args) > 2 then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"requires 1, 2 or 3 arguments (not ",
Length(args) + 1, ")");
fi;

name := PKGMAN_NameOfGitRepo(url);
if name = fail then
Info(InfoPackageManager, 1, "Could not find repository name (bad URL?)");
return false;
fi;
dir := Filename(Directory(PKGMAN_PackageDir()), name);

# Check for existing repository
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
dirs := List(info, i -> ShallowCopy(i.InstallationPath));
repo := Filename(List(dirs, Directory), ".git");
if repo <> fail then # TODO: check it's the same remote?
q := Concatenation("Package \"", name,
"\" already installed via git. Update it?");
if interactive and PKGMAN_AskYesNoQuestion(q : default := false) then
return UpdatePackage(name, interactive);
fi;
fi;

if not PKGMAN_IsValidTargetDir(dir) then
return false;
fi;
Info(InfoPackageManager, 2, "Cloning to ", dir, " ...");

if branch = fail then
exec := PKGMAN_Exec(".", "git", "clone", url, dir);
else
exec := PKGMAN_Exec(".", "git", "clone", url, dir, "-b", branch);
fi;

if exec.code <> 0 then
Info(InfoPackageManager, 1, "Cloning unsuccessful");
return false;
fi;
Info(InfoPackageManager, 3, "Package cloned successfully");
PKGMAN_RefreshPackageInfo();

# Check for PackageInfo.g
info := Filename(Directory(dir), "PackageInfo.g");
if not IsReadableFile(info) then
Info(InfoPackageManager, 1, "Could not find PackageInfo.g");
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Install dependencies
if PKGMAN_InstallDependencies(dir) <> true then
Info(InfoPackageManager, 1, "Dependencies not satisfied for ", name);
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Compile, make doc, and check
return PKGMAN_CheckPackage(dir);
end);

InstallGlobalFunction(InstallPackageFromHg,
function(url, args...)
local interactive, branch, name, dir, allinfo, info, dirs, repo, q, exec;

# Process args
interactive := true;
branch := fail;
if Length(args) = 1 then
if args[1] in [true, false] then
interactive := args[1];
elif IsString(args[1]) then
branch := args[1];
else
ErrorNoReturn("PackageManager: InstallPackageFromHg:\n",
"2nd argument should be true, false, or a string");
fi;
elif Length(args) = 2 then
interactive := args[1];
branch := args[2];
if not interactive in [true, false] then
ErrorNoReturn("PackageManager: InstallPackageFromHg:\n",
"<interactive> should be true or false");
elif not IsString(branch) then
ErrorNoReturn("PackageManager: InstallPackageFromHg:\n",
"<branch> should be a string");
fi;
elif Length(args) > 2 then
ErrorNoReturn("PackageManager: InstallPackageFromHg:\n",
"requires 1, 2 or 3 arguments (not ",
Length(args) + 1, ")");
fi;

name := PKGMAN_NameOfHgRepo(url);
if name = fail then
Info(InfoPackageManager, 1, "Could not find repository name (bad URL?)");
return false;
fi;
dir := Filename(Directory(PKGMAN_PackageDir()), name);

# Check for existing repository
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
dirs := List(info, i -> ShallowCopy(i.InstallationPath));
repo := Filename(List(dirs, Directory), ".hg");
if repo <> fail then
q := Concatenation("Package \"", name,
"\" already installed via mercurial. Update it?");
if interactive and PKGMAN_AskYesNoQuestion(q : default := false) then
return UpdatePackage(name, interactive);
fi;
fi;

if not PKGMAN_IsValidTargetDir(dir) then
return false;
fi;
Info(InfoPackageManager, 2, "Cloning to ", dir, " ...");

if branch = fail then
exec := PKGMAN_Exec(".", "hg", "clone", url, dir);
else
exec := PKGMAN_Exec(".", "hg", "clone", url, dir, "-b", branch);
fi;

if exec.code <> 0 then
Info(InfoPackageManager, 1, "Cloning unsuccessful");
return false;
fi;
Info(InfoPackageManager, 3, "Package cloned successfully");
PKGMAN_RefreshPackageInfo();

# Check for PackageInfo.g
info := Filename(Directory(dir), "PackageInfo.g");
if not IsReadableFile(info) then
Info(InfoPackageManager, 1, "Could not find PackageInfo.g");
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Install dependencies
if PKGMAN_InstallDependencies(dir) <> true then
Info(InfoPackageManager, 1, "Dependencies not satisfied for ", name);
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Compile, make doc, and check
return PKGMAN_CheckPackage(dir);
end);

BindGlobal("PKGMAN_GetPackageInfo",
function(dir_or_stream)
local fname, info;
Expand Down Expand Up @@ -955,34 +767,6 @@ function(dir, cmd, args...)
return rec(code := code, output := out);
end);

InstallGlobalFunction(PKGMAN_NameOfGitRepo,
function(url)
local parts, n;
parts := SplitString(url, "", "/:. \n\t\r");
n := Length(parts);
if n <> 0 and parts[n] <> "git" then
return parts[n];
fi;
if parts[n] = "git" and n > 1 then
return parts[n-1];
fi;
return fail;
end);

InstallGlobalFunction(PKGMAN_NameOfHgRepo,
function(url)
local parts, n;
parts := SplitString(url, "", "/:. \n\t\r");
n := Length(parts);
if n <> 0 and parts[n] <> "hg" then
return parts[n];
fi;
if parts[n] = "hg" and n > 1 then
return parts[n-1];
fi;
return fail;
end);

InstallGlobalFunction(PKGMAN_RefreshPackageInfo,
function()
GAPInfo.PackagesInfoInitialized := false;
Expand Down
19 changes: 19 additions & 0 deletions gap/git.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! @Description
#! Attempts to download and install a package from a git repository located at
#! the given URL. Returns <K>false</K> if something went wrong, and
#! <K>true</K> otherwise.
#!
#! If the optional string argument <A>branch</A> is specified, this function
#! will install the branch with this name. Otherwise, the repository's
#! default branch will be used.
#!
#! Certain decisions, such as installing newer versions of packages, will be
#! confirmed by the user via an interactive shell &ndash; to avoid this
#! interactivity and use sane defaults instead, the optional second argument
#! <A>interactive</A> can be set to <K>false</K>.
#! @Arguments url[, interactive][, branch]
#! @Returns
#! <K>true</K> or <K>false</K>
DeclareGlobalFunction("InstallPackageFromGit");

DeclareGlobalFunction("PKGMAN_NameOfGitRepo");
107 changes: 107 additions & 0 deletions gap/git.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
InstallGlobalFunction(InstallPackageFromGit,
function(url, args...)
local interactive, branch, name, dir, allinfo, info, dirs, repo, q, exec;

# Process args
interactive := true;
branch := fail;
if Length(args) = 1 then
if args[1] in [true, false] then
interactive := args[1];
elif IsString(args[1]) then
branch := args[1];
else
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"2nd argument should be true, false, or a string");
fi;
elif Length(args) = 2 then
interactive := args[1];
branch := args[2];
if not interactive in [true, false] then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"<interactive> should be true or false");
elif not IsString(branch) then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"<branch> should be a string");
fi;
elif Length(args) > 2 then
ErrorNoReturn("PackageManager: InstallPackageFromGit:\n",
"requires 1, 2 or 3 arguments (not ",
Length(args) + 1, ")");
fi;

name := PKGMAN_NameOfGitRepo(url);
if name = fail then
Info(InfoPackageManager, 1, "Could not find repository name (bad URL?)");
return false;
fi;
dir := Filename(Directory(PKGMAN_PackageDir()), name);

# Check for existing repository
allinfo := PackageInfo(name);
info := Filtered(allinfo,
x -> StartsWith(x.InstallationPath, PKGMAN_PackageDir()));
dirs := List(info, i -> ShallowCopy(i.InstallationPath));
repo := Filename(List(dirs, Directory), ".git");
if repo <> fail then # TODO: check it's the same remote?
q := Concatenation("Package \"", name,
"\" already installed via git. Update it?");
if interactive and PKGMAN_AskYesNoQuestion(q : default := false) then
return UpdatePackage(name, interactive);
fi;
fi;

if not PKGMAN_IsValidTargetDir(dir) then
return false;
fi;
Info(InfoPackageManager, 2, "Cloning to ", dir, " ...");

if branch = fail then
exec := PKGMAN_Exec(".", "git", "clone", url, dir);
else
exec := PKGMAN_Exec(".", "git", "clone", url, dir, "-b", branch);
fi;

if exec.code <> 0 then
Info(InfoPackageManager, 1, "Cloning unsuccessful");
return false;
fi;
Info(InfoPackageManager, 3, "Package cloned successfully");
PKGMAN_RefreshPackageInfo();

# Check for PackageInfo.g
info := Filename(Directory(dir), "PackageInfo.g");
if not IsReadableFile(info) then
Info(InfoPackageManager, 1, "Could not find PackageInfo.g");
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Install dependencies
if PKGMAN_InstallDependencies(dir) <> true then
Info(InfoPackageManager, 1, "Dependencies not satisfied for ", name);
if ValueOption("keepDirectory") <> true then
PKGMAN_RemoveDir(dir);
fi;
return false;
fi;

# Compile, make doc, and check
return PKGMAN_CheckPackage(dir);
end);

InstallGlobalFunction(PKGMAN_NameOfGitRepo,
function(url)
local parts, n;
parts := SplitString(url, "", "/:. \n\t\r");
n := Length(parts);
if n <> 0 and parts[n] <> "git" then
return parts[n];
fi;
if parts[n] = "git" and n > 1 then
return parts[n-1];
fi;
return fail;
end);
4 changes: 4 additions & 0 deletions gap/hg.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# DEPRECATED
DeclareGlobalFunction("InstallPackageFromHg");

DeclareGlobalFunction("PKGMAN_NameOfHgRepo");
Loading

0 comments on commit 4287f7b

Please sign in to comment.