-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathPythonWheel.cls
More file actions
116 lines (99 loc) · 4.33 KB
/
PythonWheel.cls
File metadata and controls
116 lines (99 loc) · 4.33 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Include %IPM.Formatting
Class %IPM.ResourceProcessor.PythonWheel Extends %IPM.ResourceProcessor.Abstract
{
Parameter ATTRIBUTES As STRING = "Name,Directory,ExtraPipFlags";
Parameter DESCRIPTION As STRING = "Installs a Python wheel package.";
Property Name As %IPM.DataType.PythonWheelName [ Required ];
Property Directory As %IPM.DataType.ResourceDirectory [ InitialExpression = "wheels" ];
Property ExtraPipFlags As %IPM.DataType.CommandLineArgs;
Method OnPhase(
pPhase As %String,
ByRef pParams,
Output pResourceHandled As %Boolean = 0) As %Status
{
if (pPhase = "Clean") {
// Mark as handled to prevent fallback to generic cleanup
// which tries to delete wheels as Studio documents
// TODO: actually cleanup the python wheel. This is non-trivial because we don't want to delete the wheel if it's shared with other modules
set pResourceHandled = 1
quit $$$OK
}
if (pPhase '= "Initialize") {
set pResourceHandled = 0
quit $$$OK
}
try {
set pResourceHandled = 1
set verbose = $get(pParams("Verbose"))
set root = ..ResourceReference.Module.Root
set wheel = ##class(%File).NormalizeDirectory(..Directory, root)
set wheel = ##class(%File).NormalizeFilename(..Name, wheel)
if '##class(%File).Exists(wheel) {
$$$ThrowStatus($$$ERROR($$$GeneralError, "Wheel file """_wheel_""" not found."))
}
if verbose {
write !,"Installing wheel package """_wheel_"""..."
}
set pipCaller = ##class(%IPM.Lifecycle.Base).ResolvePipCaller(.pParams)
set target = ##class(%File).NormalizeDirectory("python", ##class(%File).ManagerDirectory())
set command = pipCaller _ $listbuild("install", wheel, "-t", target) _ $listfromstring(..ExtraPipFlags, " ")
if verbose {
write !,"Running command: ",command
}
$$$ThrowOnError(##class(%IPM.Utils.Module).RunCommand(, command))
} catch ex {
set pResourceHandled = 0
// Special case: we want the installation of IPM to continue, even if the wheel package fails to install
if (..ResourceReference.Module.Name = $$$IPMModuleName) {
set errorText = ##class(%SYSTEM.Status).GetErrorText(ex.AsStatus())
set errMsg = $$$FormatText("Skipping installation of python wheel '%1' due to error: '%2'. ", ..Name, errorText)
set errMsg = errMsg _ "Please verify Python is correctly configured in IRIS. Otherwise you may need to install this wheel manually or from PyPI to use certain features of IPM."
write !, $$$FormattedLine($$$Red, errMsg)
return $$$OK
}
return ex.AsStatus()
}
return $$$OK
}
Method OnExportItem(
pFullExportPath As %String,
pItemName As %String,
ByRef pItemParams,
ByRef pParams,
Output pItemHandled As %Boolean = 0) As %Status
{
set pItemHandled = 0
set verbose = $get(pParams("Verbose"))
set source = ##class(%File).NormalizeDirectory(..Directory, ..ResourceReference.Module.Root)
set source = ##class(%File).NormalizeFilename(..Name, source)
set source = ##class(%File).NormalizeFilenameWithSpaces(source)
set dir = ##class(%File).GetDirectory(pFullExportPath)
if (##class(%File).Exists(dir)) && ('##class(%File).DirectoryExists(dir)) {
return $$$ERROR($$$GeneralError, "File """_dir_""" exists and is not a directory. Failed to export item: "_..Name)
}
if '##class(%File).DirectoryExists(dir) {
if '##class(%File).CreateDirectoryChain(dir, .return) {
return $$$ERROR($$$GeneralError, "Failed to create directory "_dir_", OS returned code: "_-return)
}
}
if verbose {
write !,"Copying wheel item '"_source_"' to '"_pFullExportPath_"'"
}
set pItemHandled = ##class(%File).CopyFile(source, pFullExportPath, 1, .return)
if 'pItemHandled {
return $$$ERROR($$$GeneralError, "Failed to copy "_source_" to "_pFullExportPath_", OS returned code: "_-return)
}
quit $$$OK
}
Method OnResolveChildren(
ByRef pResourceArray,
pCheckModuleOwnership As %Boolean) As %Status
{
set key = $order(pResourceArray(""))
if key = "" {
quit $$$ERROR($$$GeneralError, "Empty resource array for PythonWheel resource processor: "_..Name)
}
set pResourceArray(key, "RelativePath") = ..Directory _"/"_..Name
quit $$$OK
}
}