Skip to content
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

Enable APIStubGen step #12615

Merged
merged 14 commits into from
Jul 22, 2020
1 change: 1 addition & 0 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
17 changes: 12 additions & 5 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ parameters:
BuildTargetingString: 'azure-*'
ServiceDirectory: ''
TestMarkArgument: ''
AdditionalTestArgs: ''

steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(PythonVersion)'
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
Expand Down Expand Up @@ -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}}
4 changes: 3 additions & 1 deletion eng/pipelines/templates/steps/run_apistub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ parameters:
BuildTargetingString: 'azure-*'
ServiceDirectory: ''
TestMarkArgument: ''
AdditionalTestArgs: ''

steps:
- task: UsePythonVersion@0
Expand All @@ -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"
Expand Down
59 changes: 59 additions & 0 deletions eng/tox/run_apistubgen.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions eng/tox/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}