Skip to content

Sourcery refactored main branch#7

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#7
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Mar 24, 2022

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

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

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from henryiii March 24, 2022 20:10
if before_build is not None:
if platform_specific:
monkeypatch.setenv("CIBW_BEFORE_BUILD_" + platform.upper(), before_build)
monkeypatch.setenv(f"CIBW_BEFORE_BUILD_{platform.upper()}", before_build)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_before_build refactored with the following changes:

Comment on lines -246 to +250
monkeypatch.setenv("CIBW_BUILD_VERBOSITY_" + platform.upper(), str(build_verbosity))
monkeypatch.setenv(
f"CIBW_BUILD_VERBOSITY_{platform.upper()}",
str(build_verbosity),
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_build_verbosity refactored with the following changes:

Comment on lines -299 to +303
monkeypatch.setenv("CIBW_BEFORE_ALL_" + platform.upper(), before_all)
monkeypatch.setenv(f"CIBW_BEFORE_ALL_{platform.upper()}", before_all)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_before_all refactored with the following changes:

Comment on lines -30 to -42
if name == "setup.py":
if name == "setup.cfg":
s += "✅" if "python_requires" in contents else "❌"
elif name == "setup.py":
if "python_requires" not in contents:
s += "❌"
res = parse(contents)
if res is None:
s += "⚠️ "
elif res:
s += "✅ " + res
s += f"✅ {res}"
elif "python_requires" in contents:
s += "☑️"

elif name == "setup.cfg":
s += "✅" if "python_requires" in contents else "❌"
Copy link
Copy Markdown
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 thread bin/update_pythons.py

urls = [rf["url"] for rf in file_info if file_ident in rf["url"]]
if urls:
if urls := [rf["url"] for rf in file_info if file_ident in rf["url"]]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CPythonVersions.update_version_macos refactored with the following changes:

Comment thread cibuildwheel/__main__.py
Comment on lines -240 to +243
warnings = detect_warnings(options=options, identifiers=identifiers)
if warnings:
if warnings := detect_warnings(options=options, identifiers=identifiers):
print("\nWarnings:")
for warning in warnings:
print(" " + warning)
print(f" {warning}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function print_preamble refactored with the following changes:

Comment on lines -115 to +119
msg = f"Invalid archs option {architectures}. " + msg
msg = f"Invalid archs option {architectures}. {msg}"
raise ValueError(msg)

if not architectures:
msg = "Empty archs option set. " + msg
msg = f"Empty archs option set. {msg}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function allowed_architectures_check refactored with the following changes:

else:
output_io = sys.stdout.buffer

output_io = io.BytesIO() if capture_output else sys.stdout.buffer
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DockerContainer.call refactored with the following changes:

Comment thread cibuildwheel/windows.py
def get_nuget_args(version: str, arch: str, output_directory: Path) -> List[str]:
platform_suffix = {"32": "x86", "64": "", "ARM64": "arm64"}
python_name = "python" + platform_suffix[arch]
python_name = f"python{platform_suffix[arch]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_nuget_args refactored with the following changes:

Comment thread cibuildwheel/windows.py
def _ensure_nuget() -> Path:
nuget = CIBW_CACHE_PATH / "nuget.exe"
with FileLock(str(nuget) + ".lock"):
with FileLock(f'{str(nuget)}.lock'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _ensure_nuget refactored with the following changes:

Comment thread cibuildwheel/windows.py
Comment on lines -93 to +94
installation_path = base_output_dir / (nuget_args[0] + "." + version) / "tools"
with FileLock(str(base_output_dir) + f"-{version}-{arch}.lock"):
installation_path = base_output_dir / f'{nuget_args[0]}.{version}' / "tools"
with FileLock(f"{str(base_output_dir)}-{version}-{arch}.lock"):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_cpython refactored with the following changes:

Comment thread cibuildwheel/windows.py
assert zip_filename.endswith(extension)
installation_path = CIBW_CACHE_PATH / zip_filename[: -len(extension)]
with FileLock(str(installation_path) + ".lock"):
with FileLock(f'{str(installation_path)}.lock'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_pypy refactored with the following changes:


actual_wheels = utils.cibuildwheel_run(project_dir)
expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0")]
expected_wheels = list(utils.expected_wheels("spam", "0.1.0"))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_cpp11 refactored with the following changes:


actual_wheels = utils.cibuildwheel_run(project_dir)
expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0")]
expected_wheels = list(utils.expected_wheels("spam", "0.1.0"))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_cpp14 refactored with the following changes:

return {
package: version for package, version in re.findall(VERSION_REGEX, constraint_file_text)
}
return dict(re.findall(VERSION_REGEX, constraint_file_text))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_versions_from_constraint_file refactored with the following changes:

Comment thread test/utils.py
return "11.0"
else:
return macosx_deployment_target
return "11.0" if version_tuple <= (11, 0) else macosx_deployment_target
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_arm64_macosx_deployment_target refactored with the following changes:

Comment thread test/utils.py
wheels.extend(
f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl"
for platform_tag in platform_tags
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function expected_wheels refactored with the following changes:

# check that environment variables can carry binary data, except null characters
# (https://www.gnu.org/software/libc/manual/html_node/Environment-Variables.html)
binary_data = bytes(n for n in range(1, 256))
binary_data = bytes(range(1, 256))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_binary_output refactored with the following changes:

if test_extras is not None:
if platform_specific:
monkeypatch.setenv("CIBW_TEST_EXTRAS_" + platform.upper(), test_extras)
monkeypatch.setenv(f"CIBW_TEST_EXTRAS_{platform.upper()}", test_extras)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_test_extras refactored with the following changes:

if test_command is not None:
if platform_specific:
monkeypatch.setenv("CIBW_TEST_COMMAND_" + platform.upper(), test_command)
monkeypatch.setenv(f"CIBW_TEST_COMMAND_{platform.upper()}", test_command)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_test_command refactored with the following changes:

if before_build is not None:
if platform_specific:
monkeypatch.setenv("CIBW_BEFORE_BUILD_" + platform.upper(), before_build)
monkeypatch.setenv(f"CIBW_BEFORE_BUILD_{platform.upper()}", before_build)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_before_build refactored with the following changes:

Comment on lines -246 to +250
monkeypatch.setenv("CIBW_BUILD_VERBOSITY_" + platform.upper(), str(build_verbosity))
monkeypatch.setenv(
f"CIBW_BUILD_VERBOSITY_{platform.upper()}",
str(build_verbosity),
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_build_verbosity refactored with the following changes:

Comment on lines -299 to +303
monkeypatch.setenv("CIBW_BEFORE_ALL_" + platform.upper(), before_all)
monkeypatch.setenv(f"CIBW_BEFORE_ALL_{platform.upper()}", before_all)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_before_all refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai Bot commented Mar 24, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 12.25 🙂 12.25 🙂 0.00
Method Length 66.21 🙂 66.08 🙂 -0.13 👍
Working memory 9.92 😞 10.03 😞 0.11 👎
Quality 59.85% 🙂 59.63% 🙂 -0.22% 👎
Other metrics Before After Change
Lines 4122 4109 -13
Changed files Quality Before Quality After Quality Change
bin/inspect_all_known_projects.py 78.65% ⭐ 78.10% ⭐ -0.55% 👎
bin/update_pythons.py 65.04% 🙂 64.35% 🙂 -0.69% 👎
cibuildwheel/main.py 41.91% 😞 41.57% 😞 -0.34% 👎
cibuildwheel/architecture.py 75.63% ⭐ 75.60% ⭐ -0.03% 👎
cibuildwheel/docker_container.py 64.92% 🙂 65.96% 🙂 1.04% 👍
cibuildwheel/environment.py 90.63% ⭐ 91.64% ⭐ 1.01% 👍
cibuildwheel/linux.py 38.48% 😞 38.47% 😞 -0.01% 👎
cibuildwheel/logger.py 77.66% ⭐ 77.67% ⭐ 0.01% 👍
cibuildwheel/macos.py 28.59% 😞 27.69% 😞 -0.90% 👎
cibuildwheel/projectfiles.py 86.47% ⭐ 86.83% ⭐ 0.36% 👍
cibuildwheel/util.py 73.29% 🙂 72.96% 🙂 -0.33% 👎
cibuildwheel/windows.py 40.74% 😞 40.71% 😞 -0.03% 👎
test/test_cpp_standards.py 82.47% ⭐ 83.42% ⭐ 0.95% 👍
test/test_dependency_versions.py 55.29% 🙂 55.50% 🙂 0.21% 👍
test/utils.py 48.31% 😞 47.85% 😞 -0.46% 👎
unit_test/docker_container_test.py 79.77% ⭐ 79.85% ⭐ 0.08% 👍
unit_test/main_tests/main_options_test.py 74.26% 🙂 74.20% 🙂 -0.06% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
cibuildwheel/macos.py build 79 ⛔ 677 ⛔ 18 ⛔ 6.21% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cibuildwheel/windows.py build 32 😞 538 ⛔ 19 ⛔ 13.65% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cibuildwheel/linux.py build_on_docker 28 😞 654 ⛔ 18 ⛔ 16.12% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/utils.py expected_wheels 31 😞 259 ⛔ 16 ⛔ 21.49% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cibuildwheel/main.py main 24 😞 484 ⛔ 12 😞 26.12% 😞 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.

0 participants