Skip to content

Commit

Permalink
[Packaging] Support Python 3.11 (#26923)
Browse files Browse the repository at this point in the history
  • Loading branch information
bebound authored Oct 8, 2023
1 parent 2e81a4a commit a5198b5
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 79 deletions.
24 changes: 12 additions & 12 deletions azure-pipelines-full-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -44,8 +44,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -63,8 +63,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand Down Expand Up @@ -107,8 +107,8 @@ jobs:
fullTest: true
jobName: 'FullTest'

- job: AutomationFullTestPython310ProfileLatest
displayName: Automation Full Test Python310 Profile Latest
- job: AutomationFullTestPython311ProfileLatest
displayName: Automation Full Test Python311 Profile Latest
timeoutInMinutes: 9999
strategy:
maxParallel: 8
Expand All @@ -134,7 +134,7 @@ jobs:
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
pythonVersion: '3.10'
pythonVersion: '3.11'
profile: 'latest'
instance_cnt: '8'
instance_idx: '$(Instance_idx)'
Expand All @@ -147,16 +147,16 @@ jobs:
- AutomationTest20190301
- AutomationTest20180301
- AutomationFullTestPython39ProfileLatest
- AutomationFullTestPython310ProfileLatest
- AutomationFullTestPython311ProfileLatest
condition: and(failed(), in(variables['Build.Reason'], 'BatchedCI'))
displayName: Notify CI Errors
pool:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- task: AzureCLI@2
inputs:
azureSubscription: 'Azure CLI'
Expand Down
66 changes: 33 additions & 33 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ jobs:

steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11

- bash: ./scripts/ci/dependency_check.sh
displayName: 'Verify src/azure-cli/requirements.py3.Linux.txt'
Expand All @@ -145,9 +145,9 @@ jobs:

steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11

- bash: ./scripts/ci/dependency_check.sh
displayName: 'Verify src/azure-cli/requirements.py3.Darwin.txt'
Expand All @@ -160,9 +160,9 @@ jobs:

steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11

- task: BatchScript@1
inputs:
Expand All @@ -177,9 +177,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- template: .azure-pipelines/templates/azdev_setup.yml
- bash: |
set -ev
Expand Down Expand Up @@ -349,9 +349,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11


- script: |
Expand Down Expand Up @@ -411,9 +411,9 @@ jobs:
--rm -v $PYPI_FILES:/mnt/pypi python:3.9 \
/bin/bash -c "cd /mnt/pypi && ls && pip install --find-links ./ azure_cli-$CLI_VERSION*whl && az self-test && az --version && sleep 5"
echo "== Testing pip install on Python 3.10 =="
echo "== Testing pip install on Python 3.11 =="
docker run \
--rm -v $PYPI_FILES:/mnt/pypi python:3.10 \
--rm -v $PYPI_FILES:/mnt/pypi python:3.11 \
/bin/bash -c "cd /mnt/pypi && ls && pip install --find-links ./ azure_cli-$CLI_VERSION*whl && az self-test && az --version && sleep 5"
displayName: 'Test pip Install'
Expand All @@ -427,8 +427,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -444,8 +444,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- template: .azure-pipelines/templates/automation_test.yml
parameters:
Expand All @@ -464,8 +464,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
Expand All @@ -485,8 +485,8 @@ jobs:
name: ${{ variables.ubuntu_pool }}
strategy:
matrix:
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
Expand Down Expand Up @@ -530,7 +530,7 @@ jobs:
-e CLI_VERSION=$CLI_VERSION \
-e HOMEBREW_UPSTREAM_URL=$HOMEBREW_UPSTREAM_URL \
--name azurecli \
python:3.10 \
python:3.11 \
/mnt/scripts/run.sh
# clean up
Expand Down Expand Up @@ -954,9 +954,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- template: .azure-pipelines/templates/azdev_setup.yml
- bash: |
set -ev
Expand All @@ -970,9 +970,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- template: .azure-pipelines/templates/azdev_setup.yml
- bash: |
set -ev
Expand All @@ -987,8 +987,8 @@ jobs:
matrix:
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
Python311:
python.version: '3.11'
pool:
name: ${{ variables.ubuntu_pool }}
steps:
Expand Down Expand Up @@ -1016,9 +1016,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- template: .azure-pipelines/templates/azdev_setup.yml
- bash: |
set -ev
Expand All @@ -1039,9 +1039,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- template: .azure-pipelines/templates/azdev_setup.yml
- bash: |
set -ev
Expand Down Expand Up @@ -1126,9 +1126,9 @@ jobs:
name: ${{ variables.ubuntu_pool }}
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
displayName: 'Use Python 3.11'
inputs:
versionSpec: 3.10
versionSpec: 3.11
- task: AzureCLI@2
inputs:
azureSubscription: 'Azure CLI'
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ CLASSIFIERS = [
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'License :: OSI Approved :: MIT License',
]
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _get_azure_cli_properties(self):
lambda: _get_config().get('core', 'output', fallback='unknown'))
set_custom_properties(result, 'EnvironmentVariables', _get_env_string)
set_custom_properties(result, 'Locale',
lambda: '{},{}'.format(locale.getdefaultlocale()[0], locale.getdefaultlocale()[1]))
lambda: '{},{}'.format(locale.getlocale()[0], locale.getlocale()[1]))
set_custom_properties(result, 'StartTime', str(self.start_time))
set_custom_properties(result, 'EndTime', str(self.end_time))
set_custom_properties(result, 'InitTimeElapsed', str(self.init_time_elapsed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ def _check_index():
loader.load_command_table(["hello", "mod-only"])
_check_index()

with mock.patch("azure.cli.core.__version__", "2.7.0"), mock.patch.object(cli.cloud, "profile", "2019-03-01-hybrid"):
with mock.patch.object(cli.cloud, "profile", "2019-03-01-hybrid"):
def update_and_check_index():
loader.load_command_table(["hello", "mod-only"])
self.assertEqual(INDEX[CommandIndex._COMMAND_INDEX_VERSION], "2.7.0")
self.assertEqual(INDEX[CommandIndex._COMMAND_INDEX_VERSION], __version__)
self.assertEqual(INDEX[CommandIndex._COMMAND_INDEX_CLOUD_PROFILE], "2019-03-01-hybrid")
self.assertDictEqual(INDEX[CommandIndex._COMMAND_INDEX], self.expected_command_index)

Expand Down Expand Up @@ -395,6 +395,7 @@ def update_and_check_index():
@mock.patch('azure.cli.core.extension.get_extension_modname', _mock_get_extension_modname)
@mock.patch('azure.cli.core.extension.get_extensions', _mock_get_extensions)
def test_command_index_always_loaded_extensions(self):
import azure
from azure.cli.core import CommandIndex

cli = DummyCli()
Expand All @@ -403,14 +404,14 @@ def test_command_index_always_loaded_extensions(self):
index.invalidate()

# Test azext_always_loaded is loaded when command index is rebuilt
with mock.patch('azure.cli.core.ALWAYS_LOADED_EXTENSIONS', ['azext_always_loaded']):
with mock.patch.object(azure.cli.core,'ALWAYS_LOADED_EXTENSIONS', ['azext_always_loaded']):
loader.load_command_table(["hello", "mod-only"])
self.assertEqual(TestCommandRegistration.test_hook, "FAKE_HANDLER")

TestCommandRegistration.test_hook = []

# Test azext_always_loaded is loaded when command index is used
with mock.patch('azure.cli.core.ALWAYS_LOADED_EXTENSIONS', ['azext_always_loaded']):
with mock.patch.object(azure.cli.core,'ALWAYS_LOADED_EXTENSIONS', ['azext_always_loaded']):
loader.load_command_table(["hello", "mod-only"])
self.assertEqual(TestCommandRegistration.test_hook, "FAKE_HANDLER")

Expand Down
2 changes: 0 additions & 2 deletions src/azure-cli-core/azure/cli/core/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def test_help_loads(self):
except SystemExit:
pass
cmd_tbl = cli.invocation.commands_loader.command_table
cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
for cmd in cmd_tbl:
try:
cmd_tbl[cmd].loader.command_name = cmd
Expand All @@ -140,7 +139,6 @@ def test_help_loads(self):
cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_global_subscription_argument)
cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_ids_argument)
cli.raise_event(events.EVENT_INVOKER_CMD_TBL_LOADED, command_table=cmd_tbl)
cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
_store_parsers(cli.invocation.parser, parser_dict)

# TODO: do we want to update this as it doesn't actually load all help.
Expand Down
19 changes: 12 additions & 7 deletions src/azure-cli-core/azure/cli/core/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def load_command_table(self, args):
@mock.patch('azure.cli.core.extension.get_extension_modname', _mock_extension_modname)
@mock.patch('azure.cli.core.extension.get_extensions', _mock_get_extensions)
def test_parser_error_spellchecker(self):
import logging
import azure
cli = DummyCli()
main_loader = MainCommandsLoader(cli)
cli.loader = main_loader
Expand Down Expand Up @@ -224,8 +226,8 @@ def mock_add_extension(*args, **kwargs):
pass

# run multiple faulty commands and save error logs, as well as close matches
with mock.patch('logging.Logger.error', mock_log_error), \
mock.patch('difflib.get_close_matches', mock_get_close_matches):
with mock.patch.object(logging.Logger, 'error', mock_log_error), \
mock.patch.object(difflib, 'get_close_matches', mock_get_close_matches):
faulty_cmd_args = [
'test module1 --opt enum_1',
'test extension1 --opt enum_1',
Expand Down Expand Up @@ -256,11 +258,14 @@ def mock_add_extension(*args, **kwargs):
self.assertIn(choice, choices)

# test dynamic extension install
with mock.patch('logging.Logger.error', mock_log_error), \
mock.patch('azure.cli.core.extension.operations.add_extension', mock_add_extension), \
mock.patch('azure.cli.core.extension.dynamic_install._get_extension_command_tree', mock_ext_cmd_tree_load), \
mock.patch('azure.cli.core.extension.dynamic_install._get_extension_use_dynamic_install_config', return_value='yes_without_prompt'), \
mock.patch('azure.cli.core.extension.dynamic_install._get_extension_run_after_dynamic_install_config', return_value=False):
with mock.patch.object(logging.Logger, 'error', mock_log_error), \
mock.patch.object(azure.cli.core.extension.operations, 'add_extension', mock_add_extension), \
mock.patch.object(azure.cli.core.extension.dynamic_install, '_get_extension_command_tree',
mock_ext_cmd_tree_load), \
mock.patch.object(azure.cli.core.extension.dynamic_install, '_get_extension_use_dynamic_install_config',
return_value='yes_without_prompt'), \
mock.patch.object(azure.cli.core.extension.dynamic_install,
'_get_extension_run_after_dynamic_install_config', return_value=False):
with self.assertRaises(SystemExit):
parser.parse_args('test new-ext create --opt enum_2'.split())
self.assertIn("Extension new-ext-name installed. Please rerun your command.", logger_msgs[5])
Expand Down
10 changes: 2 additions & 8 deletions src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,8 @@ def in_cloud_console():

def get_arg_list(op):
import inspect

try:
# only supported in python3 - falling back to argspec if not available
sig = inspect.signature(op)
return sig.parameters
except AttributeError:
sig = inspect.getargspec(op) # pylint: disable=deprecated-method
return sig.args
sig = inspect.signature(op)
return sig.parameters


def is_track2(client_class):
Expand Down
Loading

0 comments on commit a5198b5

Please sign in to comment.