@@ -23,7 +23,7 @@ convertVersion[any_PacletObject] := convertVersion[any["Version"]]
23
23
inspectPackages [dir_ String , cbk_ ] := Module [{
24
24
packages
25
25
},
26
- packages = Get /@ FileNames ["PacletInfo.wl" , {dir }, {2 }];
26
+ packages = Get /@ DeleteDuplicatesBy [ FileNames ["PacletInfo.wl" | "PacletInfo.m" , {dir }, {2 }], DirectoryName ];
27
27
28
28
With [{found = SortBy [PacletFind [# ["Name" ] ], convertVersion ]},
29
29
@@ -56,8 +56,6 @@ PacletRepositories[list_List, OptionsPattern[]] := Module[{projectDir, info, rep
56
56
CreateDirectory [projectDir , CreateIntermediateDirectories -> True ];
57
57
If [! FileExistsQ [projectDir ], Echo ["LPM >> Cannot create project directory by path " <> projectDir <> " !!!" ]; Abort [] ];
58
58
];
59
-
60
- Echo ["LPM >> project directory >> " <> projectDir ];
61
59
62
60
63
61
If [FileExistsQ [FileNameJoin [{projectDir , ".wl_timestamp" }] ] && ! OptionValue ["ForceUpdates" ],
@@ -66,27 +64,26 @@ PacletRepositories[list_List, OptionsPattern[]] := Module[{projectDir, info, rep
66
64
skipUpdates = True ;
67
65
68
66
];
69
- Echo [StringJoin ["LPM >> updated last time >> " , time // TextString ] ];
70
67
]
71
68
];
72
69
73
70
(* PASSIVE mode :: skips all checks and just loads wl_package folder *)
74
71
If [skipUpdates ,
75
72
inspectPackages [FileNameJoin [{projectDir , "wl_packages" }], OptionValue ["ConflictResolutionFunction" ] ];
76
- Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ FileNames ["PacletInfo.wl" , {# }, {2 }]& @ FileNameJoin [{projectDir , "wl_packages" }];
73
+ Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ DeleteDuplicatesBy [ FileNames ["PacletInfo.wl" | "PacletInfo.m" , {# }, {2 }], DirectoryName ]& @ FileNameJoin [{projectDir , "wl_packages" }];
77
74
Return [Null , Module ];
78
75
];
79
76
80
- Echo ["LPM >> fetching packages info... " ];
77
+ Echo ["LPM >> fetching packages info" ];
81
78
82
79
If [FailureQ [ URLFetch ["https://github.com" ] ],
83
80
If [! electronConfirmed ,
84
- Echo ["LPM >> ERROR! no internet connection to github.com!" ];
81
+ Echo ["LPM >> ERROR! no connection to github.com!" ];
85
82
86
83
If [! MissingQ [cache ],
87
84
Echo ["LPM >> using stored data" ];
88
85
inspectPackages [FileNameJoin [{projectDir , "wl_packages" }], OptionValue ["ConflictResolutionFunction" ] ];
89
- Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ FileNames ["PacletInfo.wl" , {# }, {2 }]& @ FileNameJoin [{projectDir , "wl_packages" }];
86
+ Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ DeleteDuplicatesBy [ FileNames ["PacletInfo.wl" | "PacletInfo.m" , {# }, {2 }], DirectoryName ]& @ FileNameJoin [{projectDir , "wl_packages" }];
90
87
Return [Null , Module ];
91
88
,
92
89
Echo ["LPM >> ERROR! no cache found ;()" ];
@@ -184,7 +181,7 @@ PacletRepositories[list_List, OptionsPattern[]] := Module[{projectDir, info, rep
184
181
185
182
(* finally load dirs *)
186
183
inspectPackages [FileNameJoin [{projectDir , "wl_packages" }], OptionValue ["ConflictResolutionFunction" ] ];
187
- Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ FileNames ["PacletInfo.wl" , {# }, {2 }]& @ FileNameJoin [{projectDir , "wl_packages" }];
184
+ Map [pacletDirectoryLoad ] @ Map [DirectoryName ] @ DeleteDuplicatesBy [ FileNames ["PacletInfo.wl" | "PacletInfo.m" , {# }, {2 }], DirectoryName ]& @ FileNameJoin [{projectDir , "wl_packages" }];
188
185
]
189
186
190
187
Options [PacletRepositories ] = {"Directory" -> None , "Passive" -> False , "ForceUpdates" -> False , "AutomaticUpdates" -> True , "MaxVersionDiff" -> None , "UpdateInterval" -> Quantity [14 , "Days" ], "ConflictResolutionFunction" -> Function [{conflicting , true },
@@ -212,7 +209,7 @@ convertVersion[str_String] := ToExpression[StringReplace[str, "." -> ""]]
212
209
CheckUpdates [a_ Association , Rule [Github , _ ]] := Module [{package , new , now },
213
210
(* fetch any *)
214
211
package = FetchInfo [a ];
215
- If [! AssociationQ [package ], Echo ["LPM >> cannot check the github! skipping ..." ]; Return [False , Module ]];
212
+ If [! AssociationQ [package ], Echo ["LPM >> cannot check. Skipping ..." ]; Return [False , Module ]];
216
213
217
214
(* a feature on how we can detect on what we are looking at *)
218
215
If [KeyExistsQ [package , "tag_name" ],
@@ -246,14 +243,14 @@ FetchInfo[a_Association, Rule[Github, url_String]] := Module[{new, data},
246
243
(* extracting from given url *)
247
244
new = StringCases [url , RegularExpression [".com\\ /(.*).git" ]-> "$1" ]// First // Quiet ;
248
245
If [! StringQ [new ], new = StringCases [url , RegularExpression [".com\\ /(.*)" ]-> "$1" ]// First ];
249
- Echo ["LPM >> fetching releases info for " <> new <> " on a Github..." ];
246
+ Echo ["LPM >> fetching releases info for " <> new <> " on Github..." ];
250
247
251
248
(* here we FETCH GITHUB API RESPONCE and use releases metadata *)
252
249
data = urlImport ["https://api.github.com/repos/" <> new <> "releases/latest" , "JSON" ] // Association // Quiet ;
253
250
254
251
(* if there is NO RELEASES *)
255
252
If [! StringQ [data ["zipball_url" ]],
256
- Print ["Releases are not available for now... taking a master branch" ];
253
+ Print ["Releases are not available. Taking a master branch" ];
257
254
(* TAKE MASTER Branch *)
258
255
Return [FetchInfo [a , Rule [Github , Rule [url , "master" ]]]];
259
256
];
@@ -268,19 +265,25 @@ Module[{new, data},
268
265
(* extracting from given url *)
269
266
new = StringCases [url , RegularExpression [".com\\ /(.*).git" ]-> "$1" ]// First // Quiet ;
270
267
If [! StringQ [new ], new = StringCases [url , RegularExpression [".com\\ /(.*)" ]-> "$1" ]// First ];
271
- Echo ["LPM >> fetching info for " <> new <> " on a Github..." ];
268
+ Echo ["LPM >> fetching info for " <> new <> " on Github..." ];
272
269
273
270
(* here we FETCH PACLETINFO.WL file and use its metadata *)
274
- data = Check [urlGet ["https://raw.githubusercontent.com/" <> new <> "/" <> ToLowerCase [branch ]<> "/PacletInfo.wl" ], $Failed ];
275
-
271
+ data = urlGet ["https://raw.githubusercontent.com/" <> new <> "/" <> ToLowerCase [branch ]<> "/PacletInfo.wl" ] // Quiet ;
272
+ If [! MatchQ [ToString [Head [data ] ], "PacletObject" | "Paclet" ],
273
+ data = urlGet ["https://raw.githubusercontent.com/" <> new <> "/" <> ToLowerCase [branch ]<> "/PacletInfo.m" ];
274
+ ];
275
+
276
276
(* if failed. we just STOP *)
277
- If [FailureQ [data ],
277
+
278
+ If [! MatchQ [ToString [Head [data ] ], "PacletObject" | "Paclet" ], (* some issue with contexts *)
279
+ Echo ["Failed" ];
280
+ Echo [ToString [data , InputForm ] ];
278
281
Echo ["LPM >> ERROR cannot get " <> new <> "!" ];
279
282
Echo ["LPM >> Aborting" ];
280
283
Abort [];
281
284
];
282
285
283
- Join [a , data // First , < |"git-url" -> new |> ]
286
+ Join [a , Switch [ ToString [ Head [ data ] ], "PacletObject" , data // First , "Paclet" , Association @ KeyValueMap [ Function [{ k , v }, ToString [ k ] -> v ], Association @@ data ] ] , < |"git-url" -> new |> ]
284
287
]
285
288
286
289
(* general function *)
@@ -303,31 +306,31 @@ InstallPaclet[dir_String][a_Association, Rule[Github, url_String]] := Module[{di
303
306
304
307
(* in a case of update, directory will probably be there.. cleaning it! *)
305
308
If [FileExistsQ [dirName ],
306
- Echo ["LPM >> package folder " <> dirName <> " already exists!" ];
309
+ Echo ["LPM >> package folder already exists!" ];
307
310
Echo ["LPM >> purging..." ];
308
311
DeleteDirectory [dirName , DeleteContents -> True ];
309
312
];
310
313
311
314
(* download release *)
312
- Echo ["LPM >> fetching a release... " ];
315
+ Echo ["LPM >> fetching a release" ];
313
316
urlDownload [a ["zipball_url" ], FileNameJoin [{dir , "___temp.zip" }]];
314
317
315
318
(* extract to temporary directory and copy *)
316
- Echo ["LPM >> extracting... " ];
319
+ Echo ["LPM >> extracting" ];
317
320
ExtractArchive [FileNameJoin [{dir , "___temp.zip" }], FileNameJoin [{dir , "___temp" }]];
318
321
DeleteFile [FileNameJoin [{dir , "___temp.zip" }]];
319
322
320
323
(* locate PacletInfo, if it is not there, this is very bad. *)
321
- pacletPath = FileNames ["PacletInfo.wl" , FileNameJoin [{dir , "___temp" }], 2 ] // First ;
324
+ pacletPath = FileNames ["PacletInfo.wl" | "PacletInfo.m" , FileNameJoin [{dir , "___temp" }], 2 ] // First ;
322
325
323
326
If [! FileExistsQ [pacletPath ], Echo ["LPM >> FAILED!!! to fetch by " <> ToString [pacletPath ]]; Abort []];
324
327
pacletPath = DirectoryName [pacletPath ];
325
328
326
- Echo [StringTemplate ["LPM >> copying... from `` to ``" ][pacletPath , dirName ]];
329
+ Echo [StringTemplate ["LPM >> copying from `` to ``" ][pacletPath , dirName ]];
327
330
328
331
CopyDirectory [pacletPath , dirName ];
329
332
DeleteDirectory [FileNameJoin [{dir , "___temp" }], DeleteContents -> True ];
330
- Print ["LPM >> finished! " ];
333
+ Print ["LPM >> finished" ];
331
334
332
335
a
333
336
]
@@ -341,7 +344,7 @@ InstallPaclet[dir_String][a_Association, Rule[Github, Rule[url_String, branch_St
341
344
If [MissingQ [a ["git-url" ]], Echo ["LPM >> ERROR!!! not git-url was found" ]; Abort []];
342
345
343
346
(* construct name of the folder *)
344
- dirName = FileNameJoin [{dirName , StringReplace [a [ "Name" ], "/" -> "_" ]}];
347
+ dirName = FileNameJoin [{dirName , StringReplace [Lookup [ a , "Name" , a [ Name ] ], "/" -> "_" ]}];
345
348
346
349
If [FileExistsQ [dirName ],
347
350
Echo ["LPM >> package folder " <> dirName <> " already exists!" ];
@@ -353,20 +356,20 @@ InstallPaclet[dir_String][a_Association, Rule[Github, Rule[url_String, branch_St
353
356
Echo ["LPM >> fetching a zip archive from the master branch..." ];
354
357
urlDownload ["https://github.com/" <> a ["git-url" ]<> "/zipball/" <> ToLowerCase [branch ], FileNameJoin [{dir , "___temp.zip" }]];
355
358
356
- Echo ["LPM >> extracting... " ];
359
+ Echo ["LPM >> extracting" ];
357
360
ExtractArchive [FileNameJoin [{dir , "___temp.zip" }], FileNameJoin [{dir , "___temp" }]];
358
361
DeleteFile [FileNameJoin [{dir , "___temp.zip" }]];
359
362
360
- pacletPath = FileNames ["PacletInfo.wl" , FileNameJoin [{dir , "___temp" }], 2 ] // First ;
363
+ pacletPath = FileNames ["PacletInfo.wl" | "PacletInfo.m" , FileNameJoin [{dir , "___temp" }], 2 ] // First ;
361
364
362
365
If [! FileExistsQ [pacletPath ], Echo ["LPM >> FAILED!!! to fetch by " <> ToString [pacletPath ]]; Abort []];
363
366
pacletPath = DirectoryName [pacletPath ];
364
367
365
- Echo [StringTemplate ["LPM >> copying... from `` to ``" ][pacletPath , dirName ]];
368
+ Echo [StringTemplate ["LPM >> copying from `` to ``" ][pacletPath , dirName ]];
366
369
367
370
CopyDirectory [pacletPath , dirName ];
368
371
DeleteDirectory [FileNameJoin [{dir , "___temp" }], DeleteContents -> True ];
369
- Print ["LPM >> finished! " ];
372
+ Print ["LPM >> finished" ];
370
373
371
374
a
372
375
]
0 commit comments