Skip to content

Commit

Permalink
feat: Python Import.py Template ( Fixes #913 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Feb 15, 2024
1 parent bbd354f commit 657ff0a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Languages/Python/Templates/Python-Template-Import.ps.ps1
Original file line number Diff line number Diff line change
@@ -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 ',')"
})
"@
}
}

0 comments on commit 657ff0a

Please sign in to comment.