-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathRubiPackageTools.m
executable file
·72 lines (58 loc) · 2.73 KB
/
RubiPackageTools.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
(* Mathematica Package *)
(* Created by Mathematica Plugin for IntelliJ IDEA, see http://wlplugin.halirutan.de/ *)
(* :Title: RubiPackageTools *)
(* :Context: RubiPackageTools` *)
(* :Author: patrick *)
(* :Date: 2018-06-08 *)
(* :Discussion: This package is only intended for development purpose! It extracts all integration rules from the
* notebooks and zips them together in several packages that are then loaded by Rubi. The structure, i.e. which notebooks
* are packed into one package, is as important as the order in which they are loaded in Rubi.m.
*
* The core function of this package imports the "Code" cells from a notebook and converts them to Expressions which
* are then exported into the .m package file.
* *)
BeginPackage["Rubi`RubiPackageTools`", "PacletManager`"];
BuildIntegrationRules::usage = "BuildIntegrationRules[] creates the .m package files for the rules from the notebooks";
DeployRubi::usage = "DeployRubi[] creates a paclet and zip of the current release and puts it in the parent folder of the Rubi sources.";
Begin["`Private`"];
$dir = DirectoryName@System`Private`$InputFileName;
$ruleDir = FileNameJoin[{$dir, "..", "IntegrationRuleNotebooks"}];
BuildIntegrationRules[] := BuildIntegrationRules[#, FileNameJoin[{$dir, "IntegrationRules"}]]& /@ FileNames["*.nb", {$ruleDir}, Infinity];
BuildIntegrationRules[file_String /; FileExistsQ[file], outDir_String /; DirectoryQ[outDir]] := Module[
{
files,
outputFile,
sectionName,
sourceAsList,
outDir2 = StringReplace[DirectoryName[file], $ruleDir -> outDir]
},
sectionName = FileBaseName[file];
PrintTemporary["Exporting all notebooks from " <> sectionName];
sourceAsList = Prepend[
Map[inputTextToString, NotebookImport[file, "Code" -> "InputText"]],
subSectionComment[FileBaseName[file]]
];
If[Not@DirectoryQ[outDir2],
CreateDirectory[outDir2]
];
outputFile = FileNameJoin[{outDir2, sectionName <> ".m"}];
Export[outputFile, StringRiffle[sourceAsList, {"", "\n", "\n"}], "Text", CharacterEncoding -> "ASCII"]
];
inputTextToString[str_String /; SyntaxQ[str]] := StringReplace[str, {"\\\n" -> " ", Whitespace.. -> " "}];
inputTextToString[args___] := Throw[{args}];
sectionComment[message_String] := TemplateApply["\n(* ::Section:: *)\n(* `` *)", message];
subSectionComment[message_String] := TemplateApply["\n(* ::Subsection::Closed:: *)\n(* `` *)", message];
deleteMXFiles[] := Module[{files = FileNames["*.mx", {FileNameJoin[{$dir, "Kernel"}]}]},
DeleteFile /@ files;
];
DeployRubi[] := Module[{file, paclet},
deleteMXFiles[];
paclet = PackPaclet[$dir];
file = StringReplace[paclet, ".paclet" -> ".zip"];
If[FileExistsQ[file],
DeleteFile[file]
];
CreateArchive[$dir, file];
];
End[]; (* `Private` *)
EndPackage[]