From ddd9e47a2625b922515c504f67d395f627c81996 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Thu, 25 Feb 2021 13:29:32 -0800 Subject: [PATCH 1/5] Add Get-AllPackageInfoFromRepo --- eng/scripts/Language-Settings.ps1 | 49 +++++++++++++++++++++++++++ eng/scripts/get_package_properties.py | 11 ++++++ 2 files changed, 60 insertions(+) create mode 100644 eng/scripts/get_package_properties.py diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 7dff11c4541c..43cc649ff6bb 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -5,6 +5,55 @@ $packagePattern = "*.zip" $MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv" $BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=python%2F&delimiter=%2F" +function Get-AllPackageInfoFromRepo ($serviceDirectoryName) +{ + $allPackageProps = @() + $searchPath = "sdk/*/*/setup.py" + if ($serviceDirectoryName) + { + $searchPath = "sdk/${serviceDirectoryName}/*/setup.py" + } + Push-Location $RepoRoot + $allSetupProps = $null + try + { + pip install packaging==20.4 -q -I + $allSetupProps = (python -c "import sys; import os; sys.path.append(os.path.join('eng', 'scripts')); \ + import get_package_properties; get_package_properties.get_all_package_properties('$searchPath')") + } + catch + { + # This is soft error and failure is expected for python metapackages + LogError "Failed to get all package properties" + } + Pop-Location + + foreach ($line in $allSetupProps) + { + $setupInfo = $line -Split "," + $packageName = $setupInfo[0].Trim("(' ") + $packageVersion = $setupInfo[1].Trim("' ") + $isNewSdk = $setupInfo[2].Trim() + $setupPyDir = $setupInfo[3].Trim(")' ") + $pkgDirectoryPath = Resolve-Path (Join-Path -Path $RepoRoot $setupPyDir) + $serviceDirectoryName = Split-Path (Split-Path -Path $pkgDirectoryPath -Parent) -Leaf + if ($packageName -match "mgmt") + { + $sdkType = "mgmt" + } + else + { + $sdkType = "client" + } + $pkgProp = [PackageProps]::new($packageName, $packageVersion, $pkgDirectoryPath, $serviceDirectoryName) + $pkgProp.IsNewSdk = $isNewSdk + $pkgProp.SdkType = $sdkType + $pkgProp.ArtifactName = $packageName + $allPackageProps += $pkgProp + } + return $allPackageProps +} + function Get-python-PackageInfoFromRepo ($pkgPath, $serviceDirectory, $pkgName) { $packageName = $pkgName.Replace('_', '-') diff --git a/eng/scripts/get_package_properties.py b/eng/scripts/get_package_properties.py new file mode 100644 index 000000000000..85ff3bf8a78c --- /dev/null +++ b/eng/scripts/get_package_properties.py @@ -0,0 +1,11 @@ +import sys +import glob +import os + +sys.path.append(os.path.join('scripts', 'devops_tasks')) +from common_tasks import get_package_properties + +def get_all_package_properties(search_path): + for p in glob.glob(search_path, recursive=True): + if os.path.basename(os.path.dirname(p)) != 'azure-mgmt' and os.path.basename(os.path.dirname(p)) != 'azure' and os.path.basename(os.path.dirname(p)) != 'azure-storage': + print(get_package_properties(os.path.dirname(p))) \ No newline at end of file From 3bfa025ebc1576c05bd685503b0201ee5ae595fc Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 2 Mar 2021 13:29:26 -0800 Subject: [PATCH 2/5] make get_package_properties.py a script with arguments --- eng/scripts/Language-Settings.ps1 | 13 ++++++++----- eng/scripts/get_package_properties.py | 9 +++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 43cc649ff6bb..e8c485b3fbaa 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -18,8 +18,7 @@ function Get-AllPackageInfoFromRepo ($serviceDirectoryName) try { pip install packaging==20.4 -q -I - $allSetupProps = (python -c "import sys; import os; sys.path.append(os.path.join('eng', 'scripts')); \ - import get_package_properties; get_package_properties.get_all_package_properties('$searchPath')") + $allSetupProps = python "eng\scripts\get_package_properties.py" -s $searchPath } catch { @@ -30,11 +29,15 @@ function Get-AllPackageInfoFromRepo ($serviceDirectoryName) foreach ($line in $allSetupProps) { - $setupInfo = $line -Split "," - $packageName = $setupInfo[0].Trim("(' ") + $setupInfo = ($line -Split ",").Trim("()") + if ($setupInfo.Count < 3) + { + continue + } + $packageName = $setupInfo[0].Trim("' ") $packageVersion = $setupInfo[1].Trim("' ") $isNewSdk = $setupInfo[2].Trim() - $setupPyDir = $setupInfo[3].Trim(")' ") + $setupPyDir = $setupInfo[3].Trim("' ") $pkgDirectoryPath = Resolve-Path (Join-Path -Path $RepoRoot $setupPyDir) $serviceDirectoryName = Split-Path (Split-Path -Path $pkgDirectoryPath -Parent) -Leaf if ($packageName -match "mgmt") diff --git a/eng/scripts/get_package_properties.py b/eng/scripts/get_package_properties.py index 85ff3bf8a78c..aa65f88d9fa2 100644 --- a/eng/scripts/get_package_properties.py +++ b/eng/scripts/get_package_properties.py @@ -1,3 +1,4 @@ +import argparse import sys import glob import os @@ -5,7 +6,11 @@ sys.path.append(os.path.join('scripts', 'devops_tasks')) from common_tasks import get_package_properties -def get_all_package_properties(search_path): - for p in glob.glob(search_path, recursive=True): +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Get package version details from the repo') + parser.add_argument('-s', '--search_path', required=True, help='The scope of the search') + args = parser.parse_args() + + for p in glob.glob(args.search_path, recursive=True): if os.path.basename(os.path.dirname(p)) != 'azure-mgmt' and os.path.basename(os.path.dirname(p)) != 'azure' and os.path.basename(os.path.dirname(p)) != 'azure-storage': print(get_package_properties(os.path.dirname(p))) \ No newline at end of file From a14d969f0684b8a448aa5c58c10e186416ca6a4e Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 2 Mar 2021 21:50:00 -0800 Subject: [PATCH 3/5] handle invalid output from get_package_properties.py --- eng/scripts/Language-Settings.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index e8c485b3fbaa..a757e491313a 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -5,13 +5,13 @@ $packagePattern = "*.zip" $MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv" $BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=python%2F&delimiter=%2F" -function Get-AllPackageInfoFromRepo ($serviceDirectoryName) +function Get-AllPackageInfoFromRepo ($serviceDirectory) { $allPackageProps = @() $searchPath = "sdk/*/*/setup.py" - if ($serviceDirectoryName) + if ($serviceDirectory) { - $searchPath = "sdk/${serviceDirectoryName}/*/setup.py" + $searchPath = "sdk/${serviceDirectory}/*/setup.py" } Push-Location $RepoRoot $allSetupProps = $null @@ -30,7 +30,7 @@ function Get-AllPackageInfoFromRepo ($serviceDirectoryName) foreach ($line in $allSetupProps) { $setupInfo = ($line -Split ",").Trim("()") - if ($setupInfo.Count < 3) + if ($setupInfo.Count -gt 4) { continue } From 54c1fe1195b747830f27b642b97778df157175fe Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 3 Mar 2021 13:37:40 -0800 Subject: [PATCH 4/5] Move Push-Location into try block, add finally block --- eng/scripts/Language-Settings.ps1 | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index a757e491313a..ef1e34f8f9fa 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -13,31 +13,31 @@ function Get-AllPackageInfoFromRepo ($serviceDirectory) { $searchPath = "sdk/${serviceDirectory}/*/setup.py" } - Push-Location $RepoRoot - $allSetupProps = $null + + $allPkgPropLines = $null try { + Push-Location $RepoRoot pip install packaging==20.4 -q -I - $allSetupProps = python "eng\scripts\get_package_properties.py" -s $searchPath + $allPkgPropLines = python "eng\scripts\get_package_properties.py" -s $searchPath } catch { # This is soft error and failure is expected for python metapackages LogError "Failed to get all package properties" } - Pop-Location + finally + { + Pop-Location + } - foreach ($line in $allSetupProps) + foreach ($line in $allPkgPropLines) { - $setupInfo = ($line -Split ",").Trim("()") - if ($setupInfo.Count -gt 4) - { - continue - } - $packageName = $setupInfo[0].Trim("' ") - $packageVersion = $setupInfo[1].Trim("' ") - $isNewSdk = $setupInfo[2].Trim() - $setupPyDir = $setupInfo[3].Trim("' ") + $pkgInfo = ($line -Split ",").Trim("()' ") + $packageName = $pkgInfo[0] + $packageVersion = $pkgInfo[1] + $isNewSdk = $pkgInfo[2] + $setupPyDir = $pkgInfo[3] $pkgDirectoryPath = Resolve-Path (Join-Path -Path $RepoRoot $setupPyDir) $serviceDirectoryName = Split-Path (Split-Path -Path $pkgDirectoryPath -Parent) -Leaf if ($packageName -match "mgmt") From aa9b271fafe7753d00dfd0f811f74948491b6367 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 3 Mar 2021 15:42:52 -0800 Subject: [PATCH 5/5] Ensure isNewSdk resolves to a boolean --- eng/scripts/Language-Settings.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index ef1e34f8f9fa..adf2f3e95ffa 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -36,7 +36,7 @@ function Get-AllPackageInfoFromRepo ($serviceDirectory) $pkgInfo = ($line -Split ",").Trim("()' ") $packageName = $pkgInfo[0] $packageVersion = $pkgInfo[1] - $isNewSdk = $pkgInfo[2] + $isNewSdk = ($pkgInfo[2] -eq "True") $setupPyDir = $pkgInfo[3] $pkgDirectoryPath = Resolve-Path (Join-Path -Path $RepoRoot $setupPyDir) $serviceDirectoryName = Split-Path (Split-Path -Path $pkgDirectoryPath -Parent) -Leaf