Skip to content

Commit

Permalink
Updated FeynOnium installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsht committed May 4, 2020
1 parent 60bf400 commit 62486e8
Showing 1 changed file with 173 additions and 69 deletions.
242 changes: 173 additions & 69 deletions install.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@

(*
This software is covered by the GNU General Public License 3.
Copyright (C) 2015-2020 Vladyslav Shtabovenko
Copyright (C) 2014-2020 Vladyslav Shtabovenko
*)

(* :Summary: Installs FeynOnium *)

(* ------------------------------------------------------------------------ *)

If[ !FreeQ[$ContextPath,"WolframLanguageForJupyter`"],
Print["It seems that your are trying to install FeynOnium from a ",
"Wolfram Language kernel for Jupyter notebooks.",
"Unfortunately, graphical installation using a Jupyter frontend is currently not possible.",
"If you only have access to the Free Wolfram Engine, please start the kernel with a text-based interface",
"and run the installer again.", "\n\nInstallation aborted!"];
Abort[]
];

$FeynCalcStartupMessages = False;

BeginPackage["FeynOniumInstaller`",{"FeynCalc`"}];

InstallFeynOnium::usage =
"Installs FeynOnium.";

InstallFeynOnium::nofc =
"Looks like you don't have FeynCalc installed. FeynOnium cannot work without FeynCalc, so please \
install it first.";
Expand Down Expand Up @@ -38,99 +54,187 @@
InstallFeynOniumTo::usage="InstallFeynOniumTo is an option of InstallFeynOnium. It specifies, the full path \
to the directory where FeynOnium will be installed.";

If[ $VersionNumber == 8,
(*To use FetchURL in MMA8 we need to load URLTools first *)
Needs["Utilities`URLTools`"];
Begin["`Private`"]

testConnection::usage="";
packageDir::usage="";
packageName::usage="";
strOverwriteFC::usage="";

If[ $VersionNumber < 8,
Message[InstallFeynCalc::notcomp];
Abort[]
];

If [Needs["FeynCalc`"]===$Failed,
Message[InstallFeynOnium::nofc];
Abort[]
];

Options[InstallFeynOnium]={
AutoOverwriteFeynOniumDirectory->None,
FeynOniumDevelopmentVersionLink->"https://github.com/FeynCalc/feynonium/archive/master.zip",
(* For now there is no stable version *)
FeynOniumStableVersionLink->"https://github.com/FeynCalc/feynonium/archive/master.zip",
InstallFeynOniumDevelopmentVersion->False,
InstallFeynOniumTo->FileNameJoin[{$FeynCalcDirectory, "AddOns","FeynOnium"}]
};
If[ 8.0 <=$VersionNumber < 9.0,
(*To use FetchURL in MMA8 we need to load URLTools first *)
Needs["Utilities`URLTools`"];
];

Which[
(*Mma 8*)
8.0 <=$VersionNumber < 9.0,
(*To use FetchURL we need to load URLTools first *)
FCGetUrl[x_, opts:OptionsPattern[]]:= Utilities`URLTools`FetchURL[x,opts],
(*Mma 9 or 10 *)
9.0 <=$VersionNumber < 11.0,
FCGetUrl[x_, opts:OptionsPattern[]]:= URLSave[x,CreateTemporary[],opts],
(*Mma 11 and above *)
$VersionNumber >= 11.0,
FCGetUrl[x_, opts:OptionsPattern[]]:= URLSave[x,CreateTemporary[],opts]
(*FCGetUrl[x_, opts:OptionsPattern[]]:= First[URLDownload[x,CreateTemporary[],opts]]*)
];

InstallFeynOnium[OptionsPattern[]]:=
Module[{ unzipDir, tmpzip, gitzip, packageName, packageDir,
FCGetUrl, strOverwriteFCdit, zipDir},

If[OptionValue[InstallFeynOniumDevelopmentVersion],
gitzip = OptionValue[FeynOniumDevelopmentVersionLink];
zipDir = "feynonium-master",
(* For now there is no stable version *)
gitzip = OptionValue[FeynOniumStableVersionLink];
zipDir = "feynonium-master"
(*Test that we can access the FeynCalc repository*)
Quiet[testConnection = FCGetUrl["https://github.com/FeynCalc/feyncalc"];];
If[ testConnection===$Failed || !FileExistsQ[testConnection],
WriteString["stdout",
"It seems that your Mathematica version is unable to ",
"connect to the FeynCalc repository on GitHub.\n",
"This might be a network connectivity problem or an issue with Mathematica.\n",
"Especially some older versions of Mathematica (8, 9 or 10) and known to cause such problems\n",
"on recent versions of Linux, MacOS and Windows when accessing SSL-encrypted urls.\n\n",
"Please check the wiki <https://github.com/FeynCalc/feyncalc/wiki/Installation> for ",
"possible workarounds.\n",
"Notice that it is also possible to download all the necessary files by hand and install FeynCalc\n",
"without an existing internet connection. The required steps are described in the wiki.", "\n\nInstallation aborted!"
];
Abort[]
];

fancyText[Column[li_List]] :=
Column[(TextCell[#, "Text"] & /@ li)] /; $Notebooks

fancyText[x_] :=
x /; !$Notebooks;

choiceDialog2[x__] :=
ChoiceDialog[x]/; $Notebooks;

choiceDialog2[text_,rest__] :=
(
WriteString["stdout","\n\n"];
MessageDialog[text];
ChoiceDialog["",rest]
)/; !$Notebooks;

strOverwriteFC :=
Column[{
"Looks like you already have a version of "<> packageName <> " installed in " <> packageDir,
"",
"The installer can overwrite the content of this directory with the downloaded version of " <> packageName<>".",
"",
"However, in this case all custom configuration files or add-ons located there will be lost.",
"",
"How should we proceed?"
}
];

packageName = "FeynOnium";
packageDir = OptionValue[InstallFeynOniumTo];

strOverwriteFCdit="Looks like FeynOnium is already installed. Do you want to replace the content \
of " <> packageDir <> " with the downloaded version of FeynOnium? If you are using any custom configuration \
files or add-ons that are located in that directory, please backup them in advance.";

If[$VersionNumber < 8,
Message[InstallFeynOnium::notcomp];
Abort[]
];
(*Greeter*)
Print["Welcome to the automatic FeynOnium installer!"];
Print[" \[Bullet] To install the current stable version of FeynOnium (recommended for productive use), please evaluate"];
Print["\t", If[$Notebooks,TextCell["InstallFeynOnium[]", "Code"],"InstallFeynOnium[]"]];
Print[" \[Bullet] To install the development version of FeynOnium (only for experts or beta testers), please evaluate "];
Print["\t", If[$Notebooks,TextCell["InstallFeynOnium[InstallFeynOniumDevelopmentVersion->True]", "Code"],
"InstallFeynOnium[InstallFeynOniumDevelopmentVersion->True]" ]];
Print[" \[Bullet] If you are already using the development version of FeynCalc you must also install the development verson of FeynOnium!"];

If[$VersionNumber == 8,
(*To use FetchURL in MMA8 we need to load URLTools first *)
FCGetUrl[x_]:= Utilities`URLTools`FetchURL[x],
FCGetUrl[x_]:= URLSave[x,CreateTemporary[]]
];

Options[InstallFeynOnium] = {
AutoOverwriteFeynOniumDirectory -> None,
FeynOniumDevelopmentVersionLink -> "https://github.com/FeynCalc/feynonium/archive/master.zip",
FeynOniumStableVersionLink -> "https://github.com/FeynCalc/feynonium/archive/master.zip",
InstallFeynOniumDevelopmentVersion -> False,
InstallFeynOniumTo -> FileNameJoin[{$FeynCalcDirectory, "AddOns","FeynOnium"}]
};


InstallFeynOnium[OptionsPattern[]]:=
Module[ {unzipDir, tmpzip, zip, fullPath,
xInstalled, fireInstalled, zipDir},

If[OptionValue[InstallFeynOniumDevelopmentVersion],
zip = OptionValue[FeynOniumDevelopmentVersionLink];
zipDir = "feynhelpers-master",
zip = OptionValue[FeynOniumStableVersionLink];
zipDir = "feynhelpers-stable"
];

xInstalled = False;
fireInstalled = False;
packageName = "FeynOnium";
packageDir = OptionValue[InstallFeynOniumTo];

(* If the package directory already exists, ask the user about overwriting *)
If[ DirectoryQ[packageDir],

If[ OptionValue[AutoOverwriteFeynOniumDirectory],

Quiet@DeleteDirectory[packageDir, DeleteContents -> True],

Null,
If[ ChoiceDialog[strOverwriteFCdit,{"Yes, overwrite the " <> packageName <>" directory"->True,
"No! I need to do a backup first."->False}],
(* If the package directory already exists, ask the user about overwriting *)
If[ DirectoryQ[packageDir],

If[ OptionValue[AutoOverwriteFeynOniumDirectory],

Quiet@DeleteDirectory[packageDir, DeleteContents -> True],
Abort[]

Null,
If[ choiceDialog2[fancyText[strOverwriteFC],{"Yes, overwrite the " <> packageName <> " directory"->True,
"No, I need to do a backup first. Abort installation."->False}, WindowFloating->True, WindowTitle->"Existing "<>packageName<>" installation detected"],
Quiet@DeleteDirectory[packageDir, DeleteContents -> True],
Abort[]
]
]
]
];
];

(* Download FeynOnium tarball *)
WriteString["stdout", "Downloading FeynOnium from ", gitzip," ..."];
tmpzip=FCGetUrl[gitzip];
unzipDir= tmpzip<>".dir";
WriteString["stdout", "done! \n"];
(* Download FeynOnium tarball *)
WriteString["stdout", "Downloading " <> packageName <>" from ", zip," ..."];
tmpzip = FCGetUrl[zip];
unzipDir = tmpzip<>".dir";
fullPath = FileNameJoin[{unzipDir,zipDir}];

(* Extract to the content *)
WriteString["stdout", "FeynOnium zip file was saved to ", tmpzip,".\n"];
WriteString["stdout", "Extracting FeynOnium zip file to ", unzipDir, " ..."];
ExtractArchive[tmpzip, unzipDir];
WriteString["stdout", "done! \n"];
WriteString["stdout", "done! \n"];

(* Delete the downloaded file *)
Quiet@DeleteFile[tmpzip];
(* Extract to the content *)
WriteString["stdout", packageName <> " zip file was saved to ", tmpzip,".\n"];
WriteString["stdout", "Extracting " <> packageName <> " zip file to ", unzipDir, " ..."];

(* Move the files to the final destination *)
WriteString["stdout", "Copying "<>packageName<>" to ", packageDir, " ..."];
Print[FileNameJoin[{unzipDir,zipDir}]];
CopyDirectory[FileNameJoin[{unzipDir,zipDir}],packageDir];
WriteString["stdout", "done! \n"];
(* Delete the extracted archive *)
Quiet@DeleteDirectory[unzipDir, DeleteContents -> True];
If[ ExtractArchive[tmpzip, unzipDir]===$Failed,
WriteString["stdout", "\nFailed to extract the "<>packageName<>" zip. The file might be corrupted.\nInstallation aborted!"];
Abort[],
WriteString["stdout", "done! \n"];
(* Delete the downloaded file *)
Quiet@DeleteFile[tmpzip]
];

WriteString["stdout", "done! \n"];
(* Move the files to the final destination *)
WriteString["stdout", "Copying "<> packageName <>" to ", packageDir, " ..."];

WriteString["stdout","\nInstallation complete! To load FeynOnium, restart Mathematica \
and evaluate \n\n $LoadAddOns={\"FeynOnium\"}; \n\n before you load FeynCalc; \n"];
If[ CopyDirectory[fullPath, packageDir]===$Failed,
WriteString["stdout", "\nFailed to copy " <> fullPath <> " to ", packageDir <>". \nInstallation aborted!"];
Abort[],
WriteString["stdout", "done! \n"];
(* Delete the extracted archive *)
Quiet@DeleteDirectory[unzipDir, DeleteContents -> True];
];

];
(* Delete the downloaded file *)
Quiet@DeleteFile[tmpzip];

(* Delete the extracted archive *)
Quiet@DeleteDirectory[unzipDir, DeleteContents -> True];

WriteString["stdout","\nInstallation complete!"];
WriteString["stdout","\nTo load FeynOnium, restart Mathematica and evaluate"];
WriteString["stdout","\n\n $LoadAddOns={\"FeynOnium\"}; \n\n before you load FeynCalc; \n"];

];


End[];

EndPackage[];

0 comments on commit 62486e8

Please sign in to comment.