8000 corrected use of PSModulePath casing to be consistent with Windows PowerShell by SteveL-MSFT · Pull Request #3255 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

corrected use of PSModulePath casing to be consistent with Windows PowerShell #3255

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

Merged
merged 4 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/powershell.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ PowerShell accepts both `-` and `--` prefixed arguments.

These are environment variables used by PowerShell.

* `$PSMODULEPATH`:
* `$PSModulePath`:
A colon (`:`) separated load path for PowerShell modules.

## AUTOMATIC VARIABLES
Expand Down
6 changes: 3 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ function Start-PSPester {
}
else {
try {
$originalModulePath = $env:PSMODULEPATH
$originalModulePath = $env:PSModulePath
if ($Unelevate)
{
Start-UnelevatedProcess -process $powershell -arguments @('-noprofile', '-c', $Command)
Expand Down Expand Up @@ -793,7 +793,7 @@ function Start-PSPester {
& $powershell -noprofile -c $Command
}
} finally {
$env:PSMODULEPATH = $originalModulePath
$env:PSModulePath = $originalModulePath
if ($Unelevate)
{
Remove-Item $outputBufferFilePath
Expand Down Expand Up @@ -1733,7 +1733,7 @@ function Start-DevPowerShell {
if (-not $Command) {
$ArgumentList = @('-NoExit') + $ArgumentList
}
$Command = '$env:PSMODULEPATH = Join-Path $env:DEVPATH Modules; ' + $Command
$Command = '$env:PSModulePath = Join-Path $env:DEVPATH Modules; ' + $Command
}

if ($Command) {
Expand Down
2 changes: 1 addition & 1 deletion demos/Azure/Azure-Demo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
###
### Install-Package -Name AzureRM.NetCore.Preview -Source https://www.powershellgallery.com/api/v2 -ProviderName NuGet -ExcludeVersion -Destination <Folder you want this to be installed>
###
### Ensure $env:PSMODULEPATH is updated with the location you used to install.
### Ensure $env:PSModulePath is updated with the location you used to install.
Import-Module AzureRM.NetCore.Preview

### Supply your Azure Credentials
Expand Down
2 changes: 1 addition & 1 deletion docs/cmdlet-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ This build/restore process should work anywhere .NET Core works, including Windo
Deployment
----------

In PowerShell, check `$env:PSMODULEPATH` and install the new cmdlet in its own
In PowerShell, check `$env:PSModulePath` and install the new cmdlet in its own
module folder, such as, on Linux,
`~/.powershell/Modules/SendGreeting/SendGreeting.dll`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,7 @@ private static string AddUsingPrefixToWorkflowVariablesForFunctionCall(CommandAs
}
else
{
continue; // Something like $env:psmodulepath
continue; // Something like $env:PSModulePath
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

namespace System.Management.Automation
{
internal static class Constants
{
public const string PSModulePathEnvVar = "PSModulePath";
}

/// <summary>
/// Encapsulates the basic module operations for a PowerShell engine instance...
/// </summary>
Expand Down Expand Up @@ -710,7 +715,7 @@ private static string AddToPath(string basePath, string pathToAdd, int insertPos

/// <summary>
/// Check if the current powershell is likely running in following scenarios:
/// - sxs ps started on windows [machine-wide env:psmodulepath will influence]
/// - sxs ps started on windows [machine-wide env:PSModulePath will influence]
/// - sxs ps started from full ps
/// - sxs ps started from inbox nano/iot ps
/// - full ps started from sxs ps
Expand All @@ -734,8 +739,8 @@ private static bool NeedToClearProcessModulePath(string currentProcessModulePath
// so if the current process module path contains any of them, it's likely that the sxs
// ps was started directly on windows, or from full ps. The same goes for the legacy personal
// and shared module paths.
string hklmModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine);
string hkcuModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User);
string hklmModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Machine);
string hkcuModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.User);
string legacyPersonalModulePath = personalModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory);
string legacyProgramFilesModulePath = sharedModulePath.Replace(winSxSModuleDirectory, winLegacyModuleDirectory);

Expand Down Expand Up @@ -824,7 +829,7 @@ public static string GetModulePath(string currentProcessModulePath, string hklmM
NeedToClearProcessModulePath(currentProcessModulePath, personalModulePath, sharedModulePath, runningSxS))
{
// Clear the current process module path in the following cases
// - start sxs ps on windows [machine-wide env:psmodulepath will influence]
// - start sxs ps on windows [machine-wide env:PSModulePath will influence]
// - start sxs ps from full ps
// - start sxs ps from inbox nano/iot ps
// - start full ps from sxs ps
Expand Down Expand Up @@ -971,7 +976,7 @@ public static string GetModulePath(string currentProcessModulePath, string hklmM
/// </summary>
internal static string GetModulePath()
{
string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process);
string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process);
return currentModulePath;
}
/// <summary>
Expand All @@ -981,7 +986,7 @@ internal static string GetModulePath()
/// </summary>
internal static string SetModulePath()
{
string currentModulePath = GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Process);
string currentModulePath = GetExpandedEnvironmentVariable(Constants.PSModulePathEnvVar, EnvironmentVariableTarget.Process);
string systemWideModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.SystemWide);
string personalModulePath = ConfigPropertyAccessor.Instance.GetModulePath(ConfigPropertyAccessor.PropertyScope.CurrentUser);

Expand All @@ -990,7 +995,7 @@ internal static string SetModulePath()
if (!string.IsNullOrEmpty(newModulePathString))
{
// Set the environment variable...
Environment.SetEnvironmentVariable("PSMODULEPATH", newModulePathString);
Environment.SetEnvironmentVariable(Constants.PSModulePathEnvVar, newModulePathString);
}

return newModulePathString;
Expand All @@ -1013,7 +1018,7 @@ internal static string SetModulePath()
/// <returns>The module path as an array of strings</returns>
internal static IEnumerable<string> GetModulePath(bool includeSystemModulePath, ExecutionContext context)
{
string modulePathString = Environment.GetEnvironmentVariable("PSMODULEPATH") ?? SetModulePath();
string modulePathString = Environment.GetEnvironmentVariable(Constants.PSModulePathEnvVar) ?? SetModulePath();

HashSet<string> processedPathSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/PropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ internal override string GetModulePath(PropertyScope scope)
{
if (PropertyScope.CurrentUser == scope)
{
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User);
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSModulePath", EnvironmentVariableTarget.User);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants.PSModulePathEnvVar - right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace changes - add ?w=1 to see the url to see diffs ignoring whitespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a search for "PSModulePath" and I think I got them all

}
else
{
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine);
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSModulePath", EnvironmentVariableTarget.Machine);
}
}

Expand Down
20 changes: 10 additions & 10 deletions test/powershell/Host/Base-Directory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ Describe "Configuration file locations" -tags "CI","Slow" {
}

BeforeEach {
$original_PSMODULEPATH = $env:PSMODULEPATH
$original_PSModulePath = $env:PSModulePath
}

AfterEach {
$env:PSMODULEPATH = $original_PSMODULEPATH
$env:PSModulePath = $original_PSModulePath
}

It @ItArgs "Profile location should be correct" {
& $powershell -noprofile `$PROFILE | Should Be $expectedProfile
}

It @ItArgs "PSMODULEPATH should contain the correct path" {
$env:PSMODULEPATH = ""
$actual = & $powershell -noprofile `$env:PSMODULEPATH
It @ItArgs "PSModulePath should contain the correct path" {
$env:PSModulePath = ""
$actual = & $powershell -noprofile `$env:PSModulePath
$actual | Should Match ([regex]::Escape($expectedModule))
}

Expand Down Expand Up @@ -72,14 +72,14 @@ Describe "Configuration file locations" -tags "CI","Slow" {
}

BeforeEach {
$original_PSMODULEPATH = $env:PSMODULEPATH
$original_PSModulePath = $env:PSModulePath
$original_XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME
$original_XDG_CACHE_HOME = $env:XDG_CACHE_HOME
$original_XDG_DATA_HOME = $env:XDG_DATA_HOME
}

AfterEach {
$env:PSMODULEPATH = $original_PSMODULEPATH
$env:PSModulePath = $original_PSModulePath
$env:XDG_CONFIG_HOME = $original_XDG_CONFIG_HOME
$env:XDG_CACHE_HOME = $original_XDG_CACHE_HOME
$env:XDG_DATA_HOME = $original_XDG_DATA_HOME
Expand All @@ -91,11 +91,11 @@ Describe "Configuration file locations" -tags "CI","Slow" {
& $powershell -noprofile `$PROFILE | Should Be $expected
}

It @ItArgs "PSMODULEPATH should respect XDG_DATA_HOME" {
$env:PSMODULEPATH = ""
It @ItArgs "PSModulePath should respect XDG_DATA_HOME" {
$env:PSModulePath = ""
$env:XDG_DATA_HOME = $TestDrive
$expected = [IO.Path]::Combine($TestDrive, "powershell", "Modules")
$actual = & $powershell -noprofile `$env:PSMODULEPATH
$actual = & $powershell -noprofile `$env:PSModulePath
$actual | Should Match $expected
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ Describe 'use of a module from two runspaces' -Tags "CI" {
}
New-ModuleManifest @manifestParams

if ($env:PSMODULEPATH -notlike "*$TestModulePath*") {
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$TestModulePath"
if ($env:PSModulePath -notlike "*$TestModulePath*") {
$env:PSModulePath += "$([System.IO.Path]::PathSeparator)$TestModulePath"
}
}

$originalPSMODULEPATH = $env:PSMODULEPATH
$originalPSModulePath = $env:PSModulePath
try {

New-TestModule -Name 'Random' -Content @'
Expand Down Expand Up @@ -67,7 +67,7 @@ Import-Module Random
}

} finally {
$env:PSMODULEPATH = $originalPSMODULEPATH
$env:PSModulePath = $originalPSModulePath
}

}
Expand All @@ -76,9 +76,9 @@ Describe 'Module reloading with Class definition' -Tags "CI" {

BeforeAll {
Set-Content -Path TestDrive:\TestModule.psm1 -Value @'
$passedArgs = $args
class Root { $passedIn = $passedArgs }
function Get-PassedArgsRoot { [Root]::new().passedIn }
$passedArgs = $args
class Root { $passedIn = $passedArgs }
function Get-PassedArgsRoot { [Root]::new().passedIn }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't change anything here as PSModulePath isn't here. Not sure why this is showing up in the PR as a change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see any whitespace difference either

function Get-PassedArgsNoRoot { $passedArgs }
'@
$Arg_Hello = 'Hello'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ Describe 'NestedModules' -Tags "CI" {
New-ModuleManifest @manifestParams

$resolvedTestDrivePath = Split-Path ((get-childitem TestDrive:\)[0].FullName)
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
if (-not ($env:PSModulePath -like "*$resolvedTestDrivePath*")) {
$env:PSModulePath += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
}
}

$originalPSMODULEPATH = $env:PSMODULEPATH
$originalPSModulePath = $env:PSModulePath

try {

Expand Down Expand Up @@ -120,7 +120,7 @@ using module WithRoot
}

} finally {
$env:PSMODULEPATH = $originalPSMODULEPATH
$env:PSModulePath = $originalPSModulePath
Get-Module @('ABC', 'NoRoot', 'WithRoot') | Remove-Module
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Describe 'using module' -Tags "CI" {
BeforeAll {
$originalPSMODULEPATH = $env:PSMODULEPATH
$originalPSModulePath = $env:PSModulePath

Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1

Expand All @@ -23,15 +23,15 @@ Describe 'using module' -Tags "CI" {
}

$resolvedTestDrivePath = Split-Path ((get-childitem "${TestDrive}\$ModulePathPrefix")[0].FullName)
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
if (-not ($env:PSModulePath -like "*$resolvedTestDrivePath*")) {
$env:PSModulePath += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
}
}

}

AfterAll {
$env:PSMODULEPATH = $originalPSMODULEPATH
$env:PSModulePath = $originalPSModulePath
}

It 'Import-Module has ImplementedAssembly, when classes are present in the module' {
Expand Down Expand Up @@ -349,7 +349,7 @@ using module Foo

# 'using module' behavior must be aligned with Import-Module.
# Import-Module does the following:
# 1) find the first directory from $env:PSMODULEPATH that contains the module
# 1) find the first directory from $env:PSModulePath that contains the module
# 2) Import highest available version of the module
# In out case TestDrive:\Module is before TestDrive:\Modules2 and so 2.3.0 is the right version
It "uses the last module, if multiple versions are present" {
Expand Down Expand Up @@ -436,12 +436,12 @@ function foo()
}


# here we are back to normal $env:PSMODULEPATH, but all modules are there
# here we are back to normal $env:PSModulePath, but all modules are there
Context "Module by path" {
BeforeAll {
# this is a setup for Context "Module by path"
New-TestModule -Name FooForPaths -Content 'class Foo { [string] GetModuleName() { return "FooForPaths" } }'
$env:PSMODULEPATH = $originalPSMODULEPATH
$env:PSModulePath = $originalPSModulePath

new-item -type directory -Force TestDrive:\FooRelativeConsumer
Set-Content -Path "${TestDrive}\FooRelativeConsumer\FooRelativeConsumer.ps1" -Value @'
Expand All @@ -457,8 +457,8 @@ class Bar : Foo {}
'@
}

It 'use non-modified PSMODULEPATH' {
$env:PSMODULEPATH | Should Be $originalPSMODULEPATH
It 'use non-modified PSModulePath' {
$env:PSModulePath | Should Be $originalPSModulePath
}

It "can be accessed by relative path" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" {
# <Summary>Unit tests for line breakpoints on modules...</Summary>
# </Test>
#
$oldModulePath = $env:PSMODULEPATH
$oldModulePath = $env:PSModulePath
try
{
#
Expand Down Expand Up @@ -560,7 +560,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" {
#
# Load the module
#
$ENV:PSMODULEPATH = $moduleRoot
$ENV:PSModulePath = $moduleRoot

import-module $moduleName

Expand Down Expand Up @@ -594,7 +594,7 @@ Describe "Unit tests for line breakpoints on modules" -Tags "CI" {
}
finally
{
$env:PSMODULEPATH = $oldModulePath
$env:PSModulePath = $oldModulePath
if ($breakpoint1 -ne $null) { Remove-PSBreakpoint $breakpoint1 }
if ($breakpoint2 -ne $null) { Remove-PSBreakpoint $breakpoint2 }
if ($breakpoint3 -ne $null) { Remove-PSBreakpoint $breakpoint3 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "CI" {

AfterAll {
$global:ProgressPreference = $_progressPreference
$env:PSMODULEPATH = $_modulePath
$env:PSModulePath = $_modulePath
}
BeforeAll {
# remove the archive module forcefully, to be sure we get the correct version
Expand All @@ -19,9 +19,9 @@ Describe "Test suite for Microsoft.PowerShell.Archive module" -Tags "CI" {
# Write-Progress not supported yet on Core
$_progressPreference = $ProgressPreference
# we need to be sure that we get the correct archive module
$_modulePath = $env:PSMODULEPATH
$_modulePath = $env:PSModulePath
$powershellexe = (get-process -pid $PID).MainModule.FileName
$env:PSMODULEPATH = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules
$env:PSModulePath = join-path ([io.path]::GetDirectoryName($powershellexe)) Modules
if ( $IsCoreCLR ) { $global:ProgressPreference = "SilentlyContinue" }

Setup -d SourceDir
Expand Down
Loading
0