From 4ad446cc460c2ed5b8e354dd41b4e3b2afda3ca9 Mon Sep 17 00:00:00 2001 From: praveenkuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Wed, 22 Jul 2020 13:04:39 -0700 Subject: [PATCH] Enable APIStubGen step (#12615) * Enable APIStubGen --- .../templates/jobs/archetype-sdk-client.yml | 1 + eng/pipelines/templates/steps/analyze.yml | 17 ++++-- eng/pipelines/templates/steps/run_apistub.yml | 4 +- eng/tox/run_apistubgen.py | 59 +++++++++++++++++++ eng/tox/tox.ini | 9 +-- 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 eng/tox/run_apistubgen.py diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 3435fac571ac..8124bca8ac2f 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -73,6 +73,7 @@ jobs: ServiceDirectory: ${{ parameters.ServiceDirectory }} BuildTargetingString: ${{ parameters.BuildTargetingString }} TestMarkArgument: ${{ parameters.TestMarkArgument }} + AdditionalTestArgs: '--wheel_dir="$(Build.ArtifactStagingDirectory)"' - job: 'Test' condition: and(succeededOrFailed(), ne(variables['Skip.Test'], 'true')) diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index 55461845c5fe..eae12578bda1 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -2,6 +2,7 @@ parameters: BuildTargetingString: 'azure-*' ServiceDirectory: '' TestMarkArgument: '' + AdditionalTestArgs: '' steps: - task: UsePythonVersion@0 @@ -9,6 +10,11 @@ steps: inputs: versionSpec: '$(PythonVersion)' + - task: DownloadPipelineArtifact@0 + inputs: + artifactName: 'artifacts' + targetPath: $(Build.ArtifactStagingDirectory) + - script: | pip install -r eng/ci_tools.txt ward scan -d $(Build.SourcesDirectory) -c $(Build.SourcesDirectory)/eng/.docsettings.yml @@ -91,8 +97,9 @@ steps: BuildTargetingString: ${{ parameters.BuildTargetingString }} TestMarkArgument: ${{ parameters.TestMarkArgument }} - # - template: ../steps/run_apistub.yml - # parameters: - # ServiceDirectory: ${{ parameters.ServiceDirectory }} - # BuildTargetingString: ${{ parameters.BuildTargetingString }} - # TestMarkArgument: ${{ parameters.TestMarkArgument }} + - template: ../steps/run_apistub.yml + parameters: + ServiceDirectory: ${{ parameters.ServiceDirectory }} + BuildTargetingString: ${{ parameters.BuildTargetingString }} + TestMarkArgument: ${{ parameters.TestMarkArgument }} + AdditionalTestArgs: ${{parameters.AdditionalTestArgs}} diff --git a/eng/pipelines/templates/steps/run_apistub.yml b/eng/pipelines/templates/steps/run_apistub.yml index d66f7cafb551..a8691c39d809 100644 --- a/eng/pipelines/templates/steps/run_apistub.yml +++ b/eng/pipelines/templates/steps/run_apistub.yml @@ -2,6 +2,7 @@ parameters: BuildTargetingString: 'azure-*' ServiceDirectory: '' TestMarkArgument: '' + AdditionalTestArgs: '' steps: - task: UsePythonVersion@0 @@ -21,7 +22,8 @@ steps: inputs: scriptPath: 'scripts/devops_tasks/setup_execute_tests.py' arguments: >- - "${{ parameters.BuildTargetingString }}" + "${{ parameters.BuildTargetingString }}" + ${{ parameters.AdditionalTestArgs }} --mark_arg="${{ parameters.TestMarkArgument }}" --service="${{ parameters.ServiceDirectory }}" --toxenv="apistub" diff --git a/eng/tox/run_apistubgen.py b/eng/tox/run_apistubgen.py new file mode 100644 index 000000000000..0e37243cd16f --- /dev/null +++ b/eng/tox/run_apistubgen.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. + +from subprocess import check_call +import argparse +import os +import logging + +from tox_helper_tasks import find_whl, get_package_details + +logging.getLogger().setLevel(logging.INFO) + +root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..")) + + +def get_package_wheel_path(pkg_root): + # parse setup.py to get package name and version + pkg_name, _, version = get_package_details(os.path.join(pkg_root, "setup.py")) + # Check if wheel is already built and available for current package + prebuilt_dir = os.getenv("PREBUILT_WHEEL_DIR") + if prebuilt_dir: + prebuilt_package_path = find_whl(prebuilt_dir, pkg_name, version) + else: + return None + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Run apistubgen against target folder. " + ) + + parser.add_argument( + "-t", + "--target", + dest="target_package", + help="The target package directory on disk.", + required=True, + ) + + parser.add_argument( + "-w", + "--work_dir", + dest="work_dir", + help="Working directory to run apistubgen", + required=True, + ) + + args = parser.parse_args() + + # Check if a wheel is already built for current package and install from wheel when available + # If wheel is not available then install package from source + pkg_path = get_package_wheel_path(args.target_package) + if not pkg_path: + pkg_path = args.target_package + + check_call(["apistubgen", "--pkg-path", pkg_path,], cwd=args.work_dir) diff --git a/eng/tox/tox.ini b/eng/tox/tox.ini index f9ab076ca8cc..c279af3e0426 100644 --- a/eng/tox/tox.ini +++ b/eng/tox/tox.ini @@ -227,11 +227,12 @@ commands = [testenv:apistub] skipsdist = false skip_install = false -usedevelop = true -changedir = {toxinidir} +usedevelop = false +changedir = {envtmpdir} deps = {[base]deps} commands = # install API stub generator - {envbindir}/python -m pip install "git+https://github.com/Azure/azure-sdk-tools.git#subdirectory=packages/python-packages/api-stub-generator&egg=api-stub-generator" - apistubgen --pkg-path {toxinidir} --temp-path {envtmpdir} --out-path {envtmpdir} + {envbindir}/python -m pip install "git+https://github.com/azure/azure-sdk-tools.git#subdirectory=packages/python-packages/api-stub-generator&egg=api-stub-generator" + {envbindir}/python -m pip freeze + {envbindir}/python {toxinidir}/../../../eng/tox/run_apistubgen.py -t {toxinidir} -w {envtmpdir} \ No newline at end of file