@@ -28,48 +28,63 @@ function Get-NamespacesFromWhlFile {
2828 param (
2929 [Parameter (Mandatory = $true )] [string ]$Library ,
3030 [Parameter (Mandatory = $true )] [string ]$Version ,
31- [Parameter (Mandatory = $false )] [string ]$ExtraIndexUrl = " "
31+ [Parameter (Mandatory = $false )] [string ]$ExtraIndexUrl = " " ,
32+ [Parameter (Mandatory = $false )] [string ]$PythonWhlFile = $null
3233 )
3334
3435 $destination = (Join-Path ([System.IO.Path ]::GetTempPath()) " $Library$Version " )
36+ New-Item $destination - ItemType Directory | Out-Null
3537 $namespaces = @ ()
3638
3739 try {
3840
41+ if ($PythonWhlFile ) {
42+ if (Test-Path $PythonWhlFile - PathType Leaf) {
43+ Write-Host " Copying $PythonWhlFile to $destination "
44+ Copy-Item $PythonWhlFile - Destination $destination
45+ } else {
46+ LogWarning " $PythonWhlFile , does not exist."
47+ }
48+ } else {
49+ $success = Get-WhlFile $Library $Version $destination $ExtraIndexUrl
50+ if (-not $success ) {
51+ LogWarning " Could not download Whl file for $Library $Version "
52+ }
53+ }
3954 # Pulling the whl file generates output, make sure it's sent to null so
4055 # it's not returned as part of this function.
41- $success = Get-WhlFile $Library $Version $destination $ExtraIndexUrl
42- if ( $success ) {
43-
44- # Each library gets its own temporary directory. There should only be one whl
45- # file in the destination directory
46- $whlFile = Get-ChildItem - Path $destination - File - Filter " *.whl " | Select-Object - First 1
47- $unpackDir = Join-Path - Path $destination - ChildPath " $Library -$Version "
48- Expand-Archive - Path $whlFile - DestinationPath $unpackDir
49-
50- # Look for any directory that contains __init__.py with the following exceptions:
51- # 1. *.dist-info directories shouldn't be included in the results.
52- # 2. If any subdirectory starts with "_" it's internal and needs to be skipped
53- # 3. If there's a root level directory named "azure" with an __init__.py file then
54- # needs to be skipped. This doesn't happen with libraries released from the
55- # azure-sdk-for-python repository but there are older libraries that are in the
56- # docs directories which are/were released outside of the repository where this
57- # is true.
58- $rootLevelAzureDir = Join-Path - Path $unpackDir - ChildPath " azure"
59- $namespaceDirs = Get-ChildItem - Path $unpackDir - Recurse - Filter " __init__.py" |
60- Where-Object {$_.DirectoryName -notlike " *.dist-info" } |
61- Where-Object {$_.DirectoryName -notlike " *$ ( [IO.Path ]::DirectorySeparatorChar) _*" } |
62- Where-Object {$_.DirectoryName -ine $rootLevelAzureDir }
63- foreach ($namespaceDir in $namespaceDirs ) {
64- # Strip off the root directy, everything left will be subDir1/subDir2/../subDirN.
65- # The directory separators will be replaced with periods to compute the
66- # namespace
67- $partialDir = $namespaceDir.DirectoryName.Replace ($unpackDir + $ ([IO.Path ]::DirectorySeparatorChar), " " )
68- $namespaces += $partialDir.Replace ([IO.Path ]::DirectorySeparatorChar, " ." )
69- # Since only the primary namespace is being pulled, break out of the loop after
70- # the first one.
71- break
72- }
56+ # Each library gets its own temporary directory. There should only be one whl
57+ # file in the destination directory
58+ $whlFile = Get-ChildItem - Path $destination - File - Filter " *.whl " | Select-Object - First 1
59+ # If we can't download the file or the passed in file doesn't exist then the whlFile
60+ # won't exist, there's nothing to process and an empty namesapces list will be returned
61+ if ( $whlFile ) {
62+ $unpackDir = Join-Path - Path $destination - ChildPath " $Library -$Version "
63+ Expand-Archive - Path $whlFile - DestinationPath $unpackDir
64+
65+ # Look for any directory that contains __init__.py with the following exceptions:
66+ # 1. *.dist-info directories shouldn't be included in the results.
67+ # 2. If any subdirectory starts with "_" it's internal and needs to be skipped
68+ # 3. If there's a root level directory named "azure" with an __init__.py file then
69+ # needs to be skipped. This doesn't happen with libraries released from the
70+ # azure-sdk-for-python repository but there are older libraries that are in the
71+ # docs directories which are/were released outside of the repository where this
72+ # is true.
73+ $rootLevelAzureDir = Join-Path - Path $unpackDir - ChildPath " azure"
74+ $namespaceDirs = Get-ChildItem - Path $unpackDir - Recurse - Filter " __init__.py" |
75+ Where-Object {$_.DirectoryName -notlike " *.dist-info" } |
76+ Where-Object {$_.DirectoryName -notlike " *$ ( [IO.Path ]::DirectorySeparatorChar) _*" } |
77+ Where-Object {$_.DirectoryName -ine $rootLevelAzureDir }
78+ foreach ($namespaceDir in $namespaceDirs ) {
79+ # Strip off the root directy, everything left will be subDir1/subDir2/../subDirN.
80+ # The directory separators will be replaced with periods to compute the
81+ # namespace
82+ $partialDir = $namespaceDir.DirectoryName.Replace ($unpackDir + $ ([IO.Path ]::DirectorySeparatorChar), " " )
83+ $namespaces += $partialDir.Replace ([IO.Path ]::DirectorySeparatorChar, " ." )
84+ # Since only the primary namespace is being pulled, break out of the loop after
85+ # the first one.
86+ break
87+ }
7388 }
7489 }
7590 finally {
0 commit comments