diff --git a/packages/http-client-python/eng/scripts/ci/run_verifytypes.py b/packages/http-client-python/eng/scripts/ci/run_verifytypes.py new file mode 100644 index 00000000000..de827b2f9dd --- /dev/null +++ b/packages/http-client-python/eng/scripts/ci/run_verifytypes.py @@ -0,0 +1,55 @@ +#!/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. +# -------------------------------------------------------------------------------------------- + +# This script is used to execute verifytypes within a tox environment. Depending on which package is being executed against, +# a failure may be suppressed. + +import os +from subprocess import check_output, CalledProcessError +import logging +import sys +import time +from util import run_check + +logging.getLogger().setLevel(logging.INFO) + + +def _single_dir_verifytypes(mod): + inner_class = next(d for d in mod.iterdir() if d.is_dir() and not str(d).endswith("egg-info")) + retries = 3 + while retries: + try: + check_output( + [ + sys.executable, + "-m", + "pyright", + "--verifytypes", + "-p", + str(inner_class.absolute()), + "--ignoreexternal", + ], + text=True, + ) + return True + except CalledProcessError as e: + logging.exception("{} exited with verifytypes error {}".format(inner_class.stem, e.returncode)) + logging.error(f"Verifytypes stdout:\n{e.stdout}\n===========") + logging.error(f"Verifytypes stderr:\n{e.stderr}\n===========") + # Verifytypes has shown to randomly failed with a 217, retry the same folder 3 times should help + retries -= 1 + time.sleep(5) + + return False + + +if __name__ == "__main__": + if os.name == "nt": + # Before https://github.com/microsoft/typespec/issues/4667 fixed, skip running Verifytypes on Windows + logging.info("Skip running Verifytypes on Windows for now") + sys.exit(0) + run_check("verifytypes", _single_dir_verifytypes, "Verifytypes") diff --git a/packages/http-client-python/generator/test/azure/tox.ini b/packages/http-client-python/generator/test/azure/tox.ini index 980a7808a91..64a6a0e5289 100644 --- a/packages/http-client-python/generator/test/azure/tox.ini +++ b/packages/http-client-python/generator/test/azure/tox.ini @@ -19,6 +19,9 @@ commands = # pyright python ../../../eng/scripts/ci/run_pyright.py -t azure -s "generated" {posargs} + # verifytypes + python ../../../eng/scripts/ci/run_verifytypes.py -t azure -s "generated" {posargs} + # apiview pip install apiview-stub-generator==0.3.13 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs} @@ -48,6 +51,12 @@ deps= commands = python ../../../eng/scripts/ci/run_pyright.py -t azure -s "generated" {posargs} +[testenv:verifytypes] +deps= + -r requirements.txt +commands = + python ../../../eng/scripts/ci/run_verifytypes.py -t azure -s "generated" {posargs} + [testenv:apiview] deps= -r requirements.txt diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 83259db6684..9ff09397412 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -1,12 +1,12 @@ { "name": "@typespec/http-client-python", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@typespec/http-client-python", - "version": "0.11.1", + "version": "0.11.2", "hasInstallScript": true, "license": "MIT", "dependencies": {