Skip to content

Commit

Permalink
fix: impl. export logic for <PythonWheel /> resource
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-shuliu committed Feb 12, 2025
1 parent caf1a58 commit 3cb3e01
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/cls/IPM/ResourceProcessor/PythonWheel.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Parameter ATTRIBUTES As STRING = "Name,Directory,ExtraPipFlags";

Parameter DESCRIPTION As STRING = "Installs a Python wheel package.";

Property Name As %IPM.DataType.PythonWheelName;
Property Name As %IPM.DataType.PythonWheelName [ Required ];

Property Directory As %IPM.DataType.ResourceDirectory;
Property Directory As %IPM.DataType.ResourceDirectory [ InitialExpression = "wheels" ];

Property ExtraPipFlags As %IPM.DataType.CommandLineArgs;

Expand Down Expand Up @@ -51,4 +51,42 @@ Method OnPhase(pPhase As %String, ByRef pParams, Output pResourceHandled As %Boo
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 = "" {
$$$ThrowStatus($$$ERROR($$$GeneralError, "Empty resource array for PythonWheel resource processor: "_..Name))
}
Set pResourceArray(key, "RelativePath") = ..Directory _"/"_..Name
Quit $$$OK
}

}

0 comments on commit 3cb3e01

Please sign in to comment.