-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ImportPSModulesFromPath support #178
base: master
Are you sure you want to change the base?
Conversation
Add parameter `ModulesFromPathToImport` that accepts a single path, from which module(s) will be imported into background runspace jobs. Modules in this path are not required to be listed by name, and the path does not have to exist in `$env:PSModulePath`.
When the '-ModulesFromPathToImport' parameter is passed for 'Start-RSJob', it should handle either a full and relative path name. Also raise an exception if the module(s) path is not found, which means none of the module(s) are imported in the runspace job. An exception prevents the runspace jobs from starting, as any dependent functions referenced inside the 'ScriptBlock' parameter would not be found.
`Resolve-Path` fires a non-terminating error when it can't find a specified path, which means the error isn't caught for handling in a Catch block. Make `Resolve-Path` raise a terminating error, so we can re-throw to add context to the original exception message.
@beargle Any chance you could look at using the method shown here: #177 (comment)? It would be nice to keep all module importing down to a single parameter if possible. If it doesn't work out though, I can move forward to accept this PR. |
@proxb Sure, I saw the comment, but am not sold on readability of pre-processing module paths before passing to It seems more intuitive to be able to pass a single "root" module path, so that everything (properly organized as importable, of course) gets loaded into the runspace jobs. I totally get the usability issue with having two parameters that could be used for module import...do you think it would be confusing to wrap functionality of both InitialSessionState.ImportPSModule and InitialSessionState.ImportPSModulesFromPath into the single |
@beargle I think that would be a better way to go at least to support both the module name and module path requirement even though it will require a little more work to handle both of the possible values being supplied to the parameter. While I get the ease of just supplying a single root math containing all of the modules, I'm just not sure about having multiple module import parameters. |
Remove separate '-ModulesFromPathToImport' parameter, adding this functionality to existing '-ModulesToImport' parameters. This means '-ModulesToImport' can accept a collection containing: - Installed module names - Path (full or relative) containing one or more modules - Path (full or relative) to a module manifest, script module, or binary module file Purpose of consolidation is to simplify module import for the caller; They should have the flexibility to pass a root module path for recursive import, or be able to specify modules similar to `Import-Module`, with minimal preprocessing of the parameter collection.
@proxb Makes sense, I've consolidated the module path import into existing
Start-RSJob -ModulesToImport "PSDeploy"...
Start-RSJob -ModulesToImport ".\PSDeploy\PSDeploy.psd1"...
Start-RSJob -ModulesToImport ".\workspace\Modules"...
Start-RSJob -ModulesToImport "PSDeploy", ".\workspace\Modules"... Let me know your thoughts, thanks! |
Add
Start-RSJob
parameterModulesFromPathToImport
that accepts a single path, from which module(s) will be imported into background runspace jobs. Modules in this path are not required to be listed by name, and the path does not have to exist in$env:PSModulePath
. Fixes #177.Changes proposed in this pull request:
Start-RSJob
parameter-ModulesFromPathToImport
How to test this code:
The snippet below allows manual verification of
Get-Module
output when either a full or relative module path name is passed. I'm relatively new to Pester, but would like to learn if someone has suggestions on how to setup the automated test cases.Has been tested on (remove any that don't apply):