Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Feb 25, 2023

Branch dev refactored 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 dev branch, then run:

git fetch origin sourcery/dev
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from dciborow February 25, 2023 22:06
Copy link
Author

@sourcery-ai sourcery-ai bot left a 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"""

Copy link
Author

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:


for scope in ['cli', 'extension']:
with ArgumentsContext(self, '{} generate-docs'.format(scope)) as c:
with ArgumentsContext(self, f'{scope} generate-docs') as c:
Copy link
Author

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:

Comment on lines -12 to +21
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
)
Copy link
Author

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:

Comment on lines -65 to +67
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`?'
)
Copy link
Author

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:

Comment on lines -77 to +87
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}`')
Copy link
Author

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:

Comment on lines -145 to +150
display('MODULES: {}'.format(', '.join([x[0] for x in modules])))
display(f"MODULES: {', '.join([x[0] for x in modules])}")
Copy link
Author

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:

Comment on lines -184 to +200
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',
)
Copy link
Author

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:

Comment on lines -213 to +221
result = pip_cmd('download {} --no-deps -d {}'.format(mod, root_dir)).result
result = pip_cmd(f'download {mod} --no-deps -d {root_dir}').result
Copy link
Author

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:

Comment on lines -284 to +301
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()))
)
)
Copy link
Author

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:

Comment on lines -304 to +322
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'):
Copy link
Author

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:

Comment on lines -329 to +345
for line in f.readlines():
for line in f:
Copy link
Author

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:

Comment on lines -351 to +367
mismatch[key] = '{} != {}'.format(val, deps2[key])
mismatch[key] = f'{val} != {deps2[key]}'
Copy link
Author

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:

Comment on lines -17 to +26
'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}...',
)
Copy link
Author

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:

Comment on lines -28 to +31
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}'")
Copy link
Author

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:

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.")
Copy link
Author

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:

Comment on lines -305 to +314
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
Copy link
Author

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:

Comment on lines -29 to +31
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}"
)
Copy link
Author

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:

Comment on lines -53 to +55
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
Copy link
Author

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:

Comment on lines -74 to +76
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}")
Copy link
Author

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:

Comment on lines -46 to +65
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.')
Copy link
Author

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:

Comment on lines -67 to +79
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)))
]
Copy link
Author

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:

Comment on lines -93 to +101
display("Docs will be placed in {}.".format(output_dir))
display(f"Docs will be placed in {output_dir}.")
Copy link
Author

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:

Comment on lines -111 to +124
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}")
Copy link
Author

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:

Comment on lines -131 to +141
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}."
)
Copy link
Author

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:

Comment on lines -153 to +164
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"
)
Copy link
Author

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:

self._parameters[command_name] = set()
for name in command.arguments:
self._parameters[command_name].add(name)
self._parameters[command_name] = set(command.arguments)
Copy link
Author

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:

Comment on lines -65 to +63
prefix_name = "{} {}".format(prefix_name, word).strip()
prefix_name = f"{prefix_name} {word}".strip()
Copy link
Author

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:

if deprecate_info:
if deprecate_info := self._command_loader.command_table[
command_name
].deprecate_info:
Copy link
Author

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:

Comment on lines -149 to +148
deprecate_info = group_kwargs.get('deprecate_info', None)
if deprecate_info:
if deprecate_info := group_kwargs.get('deprecate_info', None):
Copy link
Author

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:

Comment on lines -162 to +160
deprecate_info = parameter.get('deprecate_info', None)
if deprecate_info:
if deprecate_info := parameter.get('deprecate_info', None):
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Feb 25, 2023

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.12%.

Quality metrics Before After Change
Complexity 15.45 🙂 15.28 🙂 -0.17 👍
Method Length 88.80 🙂 88.43 🙂 -0.37 👍
Working memory 7.48 🙂 7.51 🙂 0.03 👎
Quality 53.59% 🙂 53.47% 🙂 -0.12% 👎
Other metrics Before After Change
Lines 5018 5083 65
Changed files Quality Before Quality After Quality Change
setup.py 64.44% 🙂 64.58% 🙂 0.14% 👍
azdev/params.py 57.76% 🙂 60.36% 🙂 2.60% 👍
azdev/mod_templates/_validators.py 76.83% ⭐ 77.82% ⭐ 0.99% 👍
azdev/operations/code_gen.py 47.67% 😞 48.06% 😞 0.39% 👍
azdev/operations/legal.py 53.30% 🙂 54.28% 🙂 0.98% 👍
azdev/operations/performance.py 51.19% 🙂 51.29% 🙂 0.10% 👍
azdev/operations/pypi.py 49.38% 😞 49.87% 😞 0.49% 👍
azdev/operations/python_sdk.py 85.46% ⭐ 82.90% ⭐ -2.56% 👎
azdev/operations/setup.py 30.46% 😞 30.09% 😞 -0.37% 👎
azdev/operations/style.py 43.50% 😞 44.26% 😞 0.76% 👍
azdev/operations/extensions/__init__.py 54.88% 🙂 55.95% 🙂 1.07% 👍
azdev/operations/extensions/util.py 65.51% 🙂 65.84% 🙂 0.33% 👍
azdev/operations/help/__init__.py 73.81% 🙂 72.75% 🙂 -1.06% 👎
azdev/operations/help/refdoc/cli_docs/helpgen.py 78.32% ⭐ 78.32% ⭐ 0.00%
azdev/operations/help/refdoc/common/directives.py 51.79% 🙂 52.20% 🙂 0.41% 👍
azdev/operations/linter/__init__.py 17.89% ⛔ 17.90% ⛔ 0.01% 👍
azdev/operations/linter/linter.py 67.88% 🙂 67.51% 🙂 -0.37% 👎
azdev/operations/linter/rule_decorators.py 67.12% 🙂 66.38% 🙂 -0.74% 👎
azdev/operations/linter/util.py 63.56% 🙂 63.16% 🙂 -0.40% 👎
azdev/operations/linter/rules/command_group_rules.py 75.36% ⭐ 75.36% ⭐ 0.00%
azdev/operations/linter/rules/command_rules.py 84.06% ⭐ 84.87% ⭐ 0.81% 👍
azdev/operations/linter/rules/help_rules.py 60.72% 🙂 60.07% 🙂 -0.65% 👎
azdev/operations/linter/rules/parameter_rules.py 71.26% 🙂 70.39% 🙂 -0.87% 👎
azdev/operations/statistics/__init__.py 33.60% 😞 33.64% 😞 0.04% 👍
azdev/operations/statistics/util.py 59.68% 🙂 59.05% 🙂 -0.63% 👎
azdev/operations/tests/test_benchmark.py 78.81% ⭐ 78.81% ⭐ 0.00%
azdev/operations/tests/test_style.py 83.35% ⭐ 83.22% ⭐ -0.13% 👎
azdev/operations/testtool/__init__.py 27.47% 😞 27.51% 😞 0.04% 👍
azdev/operations/testtool/profile_context.py 80.97% ⭐ 81.08% ⭐ 0.11% 👍
azdev/utilities/command.py 68.68% 🙂 68.20% 🙂 -0.48% 👎
azdev/utilities/config.py 90.23% ⭐ 91.59% ⭐ 1.36% 👍
azdev/utilities/display.py 94.88% ⭐ 94.88% ⭐ 0.00%
azdev/utilities/git_util.py 64.19% 🙂 66.25% 🙂 2.06% 👍
azdev/utilities/path.py 47.54% 😞 45.70% 😞 -1.84% 👎
scripts/license_verify.py 77.11% ⭐ 73.41% 🙂 -3.70% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
azdev/operations/setup.py _interactive_setup 76 ⛔ 361 ⛔ 3.94% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
azdev/operations/linter/__init__.py run_linter 44 ⛔ 650 ⛔ 23 ⛔ 7.16% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
azdev/operations/testtool/__init__.py _discover_tests 39 ⛔ 560 ⛔ 9.19% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
azdev/operations/code_gen.py _create_package 34 ⛔ 532 ⛔ 20 ⛔ 12.15% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
azdev/operations/statistics/__init__.py _command_codegen_info 76 ⛔ 369 ⛔ 12 😞 15.25% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant