Skip to content

Commit

Permalink
Support Python 3.10 (Azure#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli authored Nov 4, 2021
1 parent c4c6065 commit cabbb3e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ disable=
raise-missing-from,
too-few-public-methods,
too-many-arguments,
consider-using-f-string,
unspecified-encoding

[TYPECHECK]
# For Azure CLI extensions, we ignore some import errors as they'll be available in the environment of the CLI
Expand Down
2 changes: 1 addition & 1 deletion azdev/operations/help/refdoc/common/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def make_rst(self): # pylint: disable=too-many-statements, too-many-nested-bloc
group_registry = ArgumentGroupRegistry(
[p.group_name for p in help_file.parameters if p.group_name])

for arg in sorted(help_file.parameters, key=lambda p: group_registry.get_group_priority(p.group_name) + str(not p.required) + p.name): # pylint: disable=line-too-long
for arg in sorted(help_file.parameters, key=lambda p: group_registry.get_group_priority(p.group_name) + str(not p.required) + p.name): # pylint: disable=line-too-long, cell-var-from-loop
yield '{}.. cliarg:: {}'.format(self._INDENT, arg.name)
yield ''
yield '{}:required: {}'.format(self._DOUBLE_INDENT, arg.required)
Expand Down
8 changes: 5 additions & 3 deletions azdev/operations/linter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_exclusions=None,
# filter down to only modules that have changed based on git diff
selected_modules = filter_by_git_diff(selected_modules, git_source, git_target, git_repo)

if not any((selected_modules[x] for x in selected_modules)):
if not any(selected_modules.values()):
logger.warning('No commands selected to check.')

selected_mod_names = list(selected_modules['mod'].keys()) + list(selected_modules['core'].keys()) + \
Expand All @@ -96,7 +96,8 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_exclusions=None,
for path in selected_mod_paths:
exclusion_path = os.path.join(path, 'linter_exclusions.yml')
if os.path.isfile(exclusion_path):
mod_exclusions = yaml.safe_load(open(exclusion_path))
with open(exclusion_path) as f:
mod_exclusions = yaml.safe_load(f)
merge_exclusion(exclusions, mod_exclusions or {})

global_exclusion_paths = [os.path.join(get_cli_repo_path(), 'linter_exclusions.yml')]
Expand All @@ -107,7 +108,8 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_exclusions=None,
pass
for path in global_exclusion_paths:
if os.path.isfile(path):
mod_exclusions = yaml.safe_load(open(path))
with open(path) as f:
mod_exclusions = yaml.safe_load(f)
merge_exclusion(exclusions, mod_exclusions or {})

start = time.time()
Expand Down
14 changes: 10 additions & 4 deletions azdev/operations/linter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def run(self, run_params=None, run_commands=None, run_command_groups=None, run_h

if paths:
ci_exclusions_path = os.path.join(paths[0], 'ci_exclusions.yml')
self._ci_exclusions = yaml.safe_load(open(ci_exclusions_path)) or {}
with open(ci_exclusions_path) as f:
self._ci_exclusions = yaml.safe_load(f) or {}

# find all defined rules and check for name conflicts
found_rules = set()
Expand Down Expand Up @@ -279,10 +280,15 @@ def run(self, run_params=None, run_commands=None, run_command_groups=None, run_h
exclusion_paths = [os.path.join(repo_path, 'linter_exclusions.yml') for repo_path in repo_paths]
for exclusion_path in exclusion_paths:
if not os.path.isfile(exclusion_path):
open(exclusion_path, 'a').close()
exclusions = yaml.safe_load(open(exclusion_path)) or {}
with open(exclusion_path, 'a'):
pass

with open(exclusion_path) as f:
exclusions = yaml.safe_load(f) or {}
exclusions.update(self._violiations)
yaml.safe_dump(exclusions, open(exclusion_path, 'w'))

with open(exclusion_path, 'w') as f:
yaml.safe_dump(exclusions, f)

colorama.deinit()
return self.exit_code
Expand Down
2 changes: 1 addition & 1 deletion azdev/operations/linter/pylint_checkers/show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def visit_call(self, node):
try:
if not (isinstance(node.args[0], astroid.node_classes.Const) and node.args[0].value == 'show'):
return
if node.func.attrname == 'command' or node.func.attrname == 'custom_command':
if node.func.attrname in ('command', 'custom_command'):
self.add_message(
'show-command', node=node,
)
Expand Down
2 changes: 1 addition & 1 deletion azdev/operations/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def check_style(modules=None, pylint=False, pep8=False, git_source=None, git_tar
# filter down to only modules that have changed based on git diff
selected_modules = filter_by_git_diff(selected_modules, git_source, git_target, git_repo)

if not any((selected_modules[x] for x in selected_modules)):
if not any(selected_modules.values()):
raise CLIError('No modules selected.')

mod_names = list(selected_modules['mod'].keys()) + list(selected_modules['core'].keys())
Expand Down
4 changes: 2 additions & 2 deletions azdev/utilities/git_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def filter_by_git_diff(selected_modules, git_source, git_target, git_repo):
to_remove[key].append(name)

# remove the unchanged modules
for key in to_remove:
for name in to_remove[key]:
for key, value in to_remove.items():
for name in value:
selected_modules[key].pop(name)
logger.info('Filtered out: %s', to_remove)

Expand Down
13 changes: 8 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- job: Tox
condition: succeeded()
pool:
vmImage: 'ubuntu-18.04'
vmImage: 'ubuntu-20.04'
strategy:
matrix:
Python36:
Expand All @@ -24,6 +24,9 @@ jobs:
Python39:
python.version: '3.9'
tox_env: 'py39'
Python310:
python.version: '3.10'
tox_env: 'py310'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
Expand All @@ -41,7 +44,7 @@ jobs:
displayName: 'Extract Metadata'
condition: succeeded()
pool:
vmImage: 'ubuntu-18.04'
vmImage: 'ubuntu-20.04'
steps:
- task: Bash@3
displayName: 'Extract Version'
Expand All @@ -61,12 +64,12 @@ jobs:
dependsOn: ExtractMetadata
condition: succeeded()
pool:
vmImage: 'ubuntu-18.04'
vmImage: 'ubuntu-20.04'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.8'
displayName: 'Use Python 3.9'
inputs:
versionSpec: 3.8
versionSpec: 3.9

- task: Bash@3
displayName: 'Run Wheel Build Script'
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9'
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10'
],
keywords='azure',
python_requires='>=3.6',
Expand All @@ -68,7 +69,7 @@
'gitpython',
'jinja2',
'knack',
'pylint==2.8.2',
'pylint==2.11.1',
'pytest-xdist', # depends on pytest-forked
'pytest>=5.0.0',
'pyyaml',
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ envlist =
py36
py37
py38
py39
py310

[testenv]
whitelist_externals =
Expand Down

0 comments on commit cabbb3e

Please sign in to comment.