-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored dev branch #1
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
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
| # ----------------------------------------------------------------------------- | ||
|
|
||
| """Azure Developer Tools package that can be installed using setuptools""" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 19-20 refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
|
|
||
| for scope in ['cli', 'extension']: | ||
| with ArgumentsContext(self, '{} generate-docs'.format(scope)) as c: | ||
| with ArgumentsContext(self, f'{scope} generate-docs') as c: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_arguments refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if namespace.storage_account: | ||
| if not is_valid_resource_id(namespace.RESOURCE): | ||
| namespace.storage_account = resource_id( | ||
| subscription=get_subscription_id(cmd.cli_ctx), | ||
| resource_group=namespace.resource_group_name, | ||
| namespace='Microsoft.Storage', | ||
| type='storageAccounts', | ||
| name=namespace.storage_account | ||
| ) | ||
| if namespace.storage_account and not is_valid_resource_id( | ||
| namespace.RESOURCE | ||
| ): | ||
| namespace.storage_account = resource_id( | ||
| subscription=get_subscription_id(cmd.cli_ctx), | ||
| resource_group=namespace.resource_group_name, | ||
| namespace='Microsoft.Storage', | ||
| type='storageAccounts', | ||
| name=namespace.storage_account | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function example_name_or_id_validator refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| raise CLIError('Unable to find `{}` repo. Have you cloned it and added ' | ||
| 'with `azdev extension repo add`?'.format(repo_name)) | ||
| raise CLIError( | ||
| f'Unable to find `{repo_name}` repo. Have you cloned it and added with `azdev extension repo add`?' | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function create_extension refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| heading('Creation of {} successful!'.format(package_name)) | ||
| heading(f'Creation of {package_name} successful!') | ||
| display('Getting started:') | ||
| display('\n To see your new commands:') | ||
| display(' `az {} -h`'.format(group_name)) | ||
| display(f' `az {group_name} -h`') | ||
| display('\n To discover and run your tests:') | ||
| display(' `azdev test {} --discover`'.format(group_name)) | ||
| display(f' `azdev test {group_name} --discover`') | ||
| display('\n To identify code style issues (there will be some left over from code generation):') | ||
| display(' `azdev style {}`'.format(group_name)) | ||
| display(f' `azdev style {group_name}`') | ||
| display('\n To identify CLI-specific linter violations:') | ||
| display(' `azdev linter {}`'.format(group_name)) | ||
| display(f' `azdev linter {group_name}`') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _display_success_message refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting)
| display('MODULES: {}'.format(', '.join([x[0] for x in modules]))) | ||
| display(f"MODULES: {', '.join([x[0] for x in modules])}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function verify_versions refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| mod = '{}{}'.format(COMMAND_MODULE_PREFIX, mod) | ||
| mod = f'{COMMAND_MODULE_PREFIX}{mod}' | ||
|
|
||
| setup_path = find_files(mod_path, 'setup.py') | ||
| with open(setup_path[0], 'r') as f: | ||
| local_version = 'Unknown' | ||
| for line in f.readlines(): | ||
| if line.strip().startswith('VERSION'): | ||
| local_version = version_pattern.match(line).group('ver') | ||
| break | ||
| local_version = next( | ||
| ( | ||
| version_pattern.match(line)['ver'] | ||
| for line in f | ||
| if line.strip().startswith('VERSION') | ||
| ), | ||
| 'Unknown', | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _get_module_versions refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting) - Use the built-in function
nextinstead of a for-loop (use-next) - Iterate over files directly rather than using readlines() (
use-file-iterator) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups)
| result = pip_cmd('download {} --no-deps -d {}'.format(mod, root_dir)).result | ||
| result = pip_cmd(f'download {mod} --no-deps -d {root_dir}').result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _compare_module_against_pypi refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups) - Swap if/else branches of if expression to remove negation (
swap-if-expression) - Merge nested if conditions (
merge-nested-ifs)
| with open(file1, 'r') as f1, open(file2, 'r') as f2: | ||
| errors.append(os.linesep.join(diff for diff in difflib.context_diff(f1.readlines(), f2.readlines()))) | ||
| with (open(file1, 'r') as f1, open(file2, 'r') as f2): | ||
| errors.append( | ||
| os.linesep.join( | ||
| iter(difflib.context_diff(f1.readlines(), f2.readlines())) | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _diff_files refactored with the following changes:
- Simplify generator expression (
simplify-generator)
| elif len(dirs_cmp.right_only) == 1 and dirs_cmp.right_only[0].endswith('.whl'): | ||
| pass | ||
| else: | ||
| elif len(dirs_cmp.right_only) != 1 or not dirs_cmp.right_only[ | ||
| 0 | ||
| ].endswith('.whl'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _compare_folders refactored with the following changes:
- Remove empty elif clause (
remove-pass-elif) - Replace assignment with augmented assignment (
aug-assign)
| for line in f.readlines(): | ||
| for line in f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _extract_dependencies refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator) - Replace call to format with f-string (
use-fstring-for-formatting)
| mismatch[key] = '{} != {}'.format(val, deps2[key]) | ||
| mismatch[key] = f'{val} != {deps2[key]}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _compare_dependencies refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting)
| 'branch': 'restapi_auto_{}/resource-manager'.format(module) | ||
| 'branch': f'restapi_auto_{module}/resource-manager', | ||
| } | ||
| pip_cmd('install "git+https://github.com/Azure/azure-sdk-for-python{pr}@{branch}' | ||
| '#egg=azure-mgmt-{module}&subdirectory=azure-mgmt-{module}"'.format(**kwargs), | ||
| show_stderr=True, | ||
| message='Installing draft SDK for azure-mgmt-{}...'.format(module)) | ||
| pip_cmd( | ||
| 'install "git+https://github.com/Azure/azure-sdk-for-python{pr}@{branch}' | ||
| '#egg=azure-mgmt-{module}&subdirectory=azure-mgmt-{module}"'.format( | ||
| **kwargs | ||
| ), | ||
| show_stderr=True, | ||
| message=f'Installing draft SDK for azure-mgmt-{module}...', | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function install_draft_sdk refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| raise CLIError('{} is not a valid path.'.format(path)) | ||
| raise CLIError(f'{path} is not a valid path.') | ||
| _check_repo(path) | ||
| if file_name not in os.listdir(path): | ||
| raise CLIError("'{}' does not contain the expected file '{}'".format(path, file_name)) | ||
| raise CLIError(f"'{path}' does not contain the expected file '{file_name}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _check_path refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| def _check_repo(path): | ||
| if not os.path.isdir(os.path.join(path, '.git')): | ||
| raise CLIError("'{}' is not a valid git repository.".format(path)) | ||
| raise CLIError(f"'{path}' is not a valid git repository.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _check_repo refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if not yes: | ||
| if exists: | ||
| if not prompt_y_n( | ||
| "{} already exists. You may need to bump the extension version. Replace?".format(whl_file), | ||
| default='n'): | ||
| logger.warning("Skipping '%s'...", whl_file) | ||
| continue | ||
| if ( | ||
| not yes | ||
| and exists | ||
| and not prompt_y_n( | ||
| f"{whl_file} already exists. You may need to bump the extension version. Replace?", | ||
| default='n', | ||
| ) | ||
| ): | ||
| logger.warning("Skipping '%s'...", whl_file) | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function publish_extensions refactored with the following changes:
- Merge nested if conditions [×2] (
merge-nested-ifs) - Replace call to format with f-string (
use-fstring-for-formatting)
| raise AssertionError("Expected 1 module to load starting with " | ||
| "'{}': got {}".format(EXTENSION_PREFIX, pos_mods)) | ||
| raise AssertionError( | ||
| f"Expected 1 module to load starting with '{EXTENSION_PREFIX}': got {pos_mods}" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _get_extension_modname refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| azext_metadata = _get_azext_metadata(ext_dir) | ||
| if azext_metadata: | ||
| metadata.update(azext_metadata) | ||
| if azext_metadata := _get_azext_metadata(ext_dir): | ||
| metadata |= azext_metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_ext_metadata refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Merge dictionary updates via the union operator (
dict-assign-update-to-union)
| assert r.status_code == 200, "Request to {} failed with {}".format(url, r.status_code) | ||
| assert r.status_code == 200, f"Request to {url} failed with {r.status_code}" | ||
| except AssertionError: | ||
| raise CLIError("unable to download (status code {}): {}".format(r.status_code, url)) | ||
| raise CLIError(f"unable to download (status code {r.status_code}): {url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_whl_from_url refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| if help_files_not_found or help_files_to_add_to_map: | ||
| error_lines = [] | ||
| error_lines.append('Errors whilst verifying {}!'.format(DOC_MAP_NAME)) | ||
| if help_files_not_found: | ||
| error_lines.append('The following files are in {} but do not exist:'.format(DOC_MAP_NAME)) | ||
| error_lines += help_files_not_found | ||
| if help_files_not_found: | ||
| error_lines = [ | ||
| f'Errors whilst verifying {DOC_MAP_NAME}!', | ||
| f'The following files are in {DOC_MAP_NAME} but do not exist:', | ||
| ] | ||
| error_lines += help_files_not_found | ||
| if help_files_to_add_to_map: | ||
| error_lines.append('The following files should be added to {}:'.format(DOC_MAP_NAME)) | ||
| error_lines.append(f'The following files should be added to {DOC_MAP_NAME}:') | ||
| error_lines += help_files_to_add_to_map | ||
| error_msg = '\n'.join(error_lines) | ||
| raise CLIError(error_msg) | ||
| display('Verified {} OK.'.format(DOC_MAP_NAME)) | ||
| elif help_files_to_add_to_map: | ||
| error_lines = [ | ||
| f'Errors whilst verifying {DOC_MAP_NAME}!', | ||
| f'The following files should be added to {DOC_MAP_NAME}:', | ||
| ] | ||
| error_lines += help_files_to_add_to_map | ||
| error_msg = '\n'.join(error_lines) | ||
| raise CLIError(error_msg) | ||
| display(f'Verified {DOC_MAP_NAME} OK.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function check_document_map refactored with the following changes:
- Split conditional into multiple branches (
split-or-ifs) - Merge append into list declaration [×4] (
merge-list-append) - Replace call to format with f-string [×6] (
use-fstring-for-formatting) - Remove redundant conditional [×3] (
remove-redundant-if)
| missing_files = [] | ||
| for path in help_files_in_map: | ||
| if not os.path.isfile(os.path.normpath(os.path.join(cli_repo, path))): | ||
| missing_files.append(path) | ||
| return missing_files | ||
| return [ | ||
| path | ||
| for path in help_files_in_map | ||
| if not os.path.isfile(os.path.normpath(os.path.join(cli_repo, path))) | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _map_help_files_not_found refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| display("Docs will be placed in {}.".format(output_dir)) | ||
| display(f"Docs will be placed in {output_dir}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function generate_cli_ref_docs refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| display("Docs will be placed in {}.".format(output_dir)) | ||
| display(f"Docs will be placed in {output_dir}.") | ||
|
|
||
| display("Generating Docs for public extensions. Installed extensions will not be affected...") | ||
| _generate_ref_docs_for_public_exts(output_type, output_dir) | ||
|
|
||
| display("\nThe {} files are in {}".format(output_type, output_dir)) | ||
| display(f"\nThe {output_type} files are in {output_dir}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function generate_extension_ref_docs refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| raise CLIError("Cannot create output directory {} in non-existent path {}." | ||
| .format(base_dir, existing_path)) | ||
| raise CLIError( | ||
| f"Cannot create output directory {base_dir} in non-existent path {existing_path}." | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _process_ref_doc_output_dir refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| display("\nFinished generating files for profile {} in dir {}\n".format(output_type, profile_output_dir)) | ||
| display( | ||
| f"\nFinished generating files for profile {output_type} in dir {profile_output_dir}\n" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _generate_ref_docs_for_all_profiles refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| self._parameters[command_name] = set() | ||
| for name in command.arguments: | ||
| self._parameters[command_name].add(name) | ||
| self._parameters[command_name] = set(command.arguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Linter.__init__ refactored with the following changes:
- Convert for loop into set comprehension (
set-comprehension) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
| prefix_name = "{} {}".format(prefix_name, word).strip() | ||
| prefix_name = f"{prefix_name} {word}".strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Linter.command_groups refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| if deprecate_info: | ||
| if deprecate_info := self._command_loader.command_table[ | ||
| command_name | ||
| ].deprecate_info: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Linter.command_expired refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| deprecate_info = group_kwargs.get('deprecate_info', None) | ||
| if deprecate_info: | ||
| if deprecate_info := group_kwargs.get('deprecate_info', None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Linter.command_group_expired refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| deprecate_info = parameter.get('deprecate_info', None) | ||
| if deprecate_info: | ||
| if deprecate_info := parameter.get('deprecate_info', None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Linter.parameter_expired refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.12%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
devrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
devbranch, then run:Help us improve this pull request!