From 657ff0a02466ce44994739e82537973368025fba Mon Sep 17 00:00:00 2001 From: James Brundage <@github.com> Date: Wed, 14 Feb 2024 16:55:53 -0800 Subject: [PATCH] feat: Python Import.py Template ( Fixes #913 ) --- .../Templates/Python-Template-Import.ps.ps1 | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Languages/Python/Templates/Python-Template-Import.ps.ps1 diff --git a/Languages/Python/Templates/Python-Template-Import.ps.ps1 b/Languages/Python/Templates/Python-Template-Import.ps.ps1 new file mode 100644 index 000000000..3c0e4330c --- /dev/null +++ b/Languages/Python/Templates/Python-Template-Import.ps.ps1 @@ -0,0 +1,44 @@ +Template function Import.py { + <# + .SYNOPSIS + Python Import Template + .DESCRIPTION + Template for Import statements in Python + .EXAMPLE + Template.Import.py -ModuleName sys + .EXAMPLE + 'sys','json' | Template.Import.py -As { $_[0] } + #> + [Alias('Import.py','Require.py','Imports.py','Requires.py','Includes.py')] + param( + # The name of one or more libraries to import. + [vbn(ValueFromPipeline)] + [Alias('LibraryName','PackageName')] + [string[]] + $ModuleName, + + # The name of one or more functions to import from the module + [vbn()] + [Alias('From')] + [string] + $Function, + + # The alias for the imported type or function. + [vbn()] + [Alias('Alias')] + [string] + $As + ) + + process { +@" +$(if ($Function) { + "from$($ModuleName -join ',') import $($functionName -join ",")$(if ($As) {" as $As"})" +} elseif ($As) { + "import $($ModuleName -join ',') as $As" +} else { + "import $($ModuleName -join ',')" +}) +"@ + } +}