{Core} Stop importing pkg_resources when getting versions#14905
{Core} Stop importing pkg_resources when getting versions#14905
Conversation
Side-notesIn PyCharm, setting a breakpoint at to However, when directly executing The Instead, you may put in Full callstack for `python -m azure.cli version`Then if you start debugging in PyCharm, the output shows how PyCharm imports Full callstack for debugging in PyCharm |
|
Core |
| # return [d for d in list(working_set) if d.key == CLI_PACKAGE_NAME or d.key.startswith(COMPONENT_PREFIX)] | ||
|
|
||
| # Use the hard-coded version instead of querying all modules under site-packages. | ||
| from azure.cli.__main__ import __version__ as azure_cli_version |
There was a problem hiding this comment.
From azure-cli-core perspective, we should not assume there is a azure-cli repo. That is to say, azure.cli.__main__ may not exist.
There was a problem hiding this comment.
Good catch! As now azure-cli and azure-cli-core have the same version, we don't need this dependency anymore.
Also importing azure.cli.__main__ will cause __main__ to be executed, thus causing CI failure:
=====================
| Discovering Tests |
=====================
az: 'test' is not in the 'az' command group. See 'az --help'. If the command is from an extension, please make sure the corresponding extension is installed. To learn more about extensions, please visit https://docs.microsoft.com/en-us/cli/azure/azure-cli-extensions-overview
The most similar choice to 'test' is:
rest
Description
az versionand the version check introduced in #14803 query the local versions of Azure CLI modules:azure-cliazure-cli-command-modules-nspkgazure-cli-coreazure-cli-nspkgazure-cli-telemetryThe current implementation uses
pkg_resources.working_setwhich takes ~200ms to load:This is outstanding compared to
az version's 500ms running time.This PR uses the hard-coded version instead of querying all modules under
site-packagesusingpkg_resources.Removal of
azure-cli-dev-toolsandazure-cli-testsdkThis PR removes
azure-cli-dev-toolsandazure-cli-testsdk. The removal only applies to dev CLI, and won't affect the released CLI (they are not present at all). It is safe for public users.After the change, the dev CLI and released CLI have the same output.
Performance
The performance improvement is significant - from ~500ms to ~300ms:
site-packagesis not imported anymore:Testing Guide
az version Measure-Command {az version}