Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 31, 2022

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

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from jay3332 March 31, 2022 13:46
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.

Comment on lines -49 to +55
if class_first is not None:
if not name.endswith("Last>"):
raise ValueError("Missing Last after First")
if class_first is not None and not name.endswith("Last>"):
raise ValueError("Missing Last after First")

for c in range(prev_codepoint + 1, codepoint):
yield Codepoint(c, class_first)

class_first = None
if name.endswith("First>"):
class_first = class_

class_first = class_ if name.endswith("First>") else 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 get_codepoints refactored with the following changes:

Comment on lines -76 to +72
if len(uppers) == 0 or uppers[-1][0] != upper:
if not uppers or uppers[-1][0] != upper:
Copy link
Author

Choose a reason for hiding this comment

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

Function compress_singletons refactored with the following changes:

if falselen > 0x7f:
entry.append(0x80 | (falselen >> 8))
entry.append(falselen & 0xff)
entry.extend((0x80 | (falselen >> 8), falselen & 0xff))
Copy link
Author

Choose a reason for hiding this comment

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

Function compress_normal refactored with the following changes:

Comment on lines -115 to +114
print("const {}: &[(u8, u8)] = &[".format(uppersname))
print(f"const {uppersname}: &[(u8, u8)] = &[")
for u, c in uppers:
print(" ({:#04x}, {}),".format(u, c))
print("];")
print("#[rustfmt::skip]")
print("const {}: &[u8] = &[".format(lowersname))
print(f"const {lowersname}: &[u8] = &[")
Copy link
Author

Choose a reason for hiding this comment

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

Function print_singletons refactored with the following changes:

Comment on lines -127 to +121
print("const {}: &[u8] = &[".format(normalname))
print(f"const {normalname}: &[u8] = &[")
Copy link
Author

Choose a reason for hiding this comment

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

Function print_normal refactored with the following changes:

Comment on lines -450 to +491
filename = "rust-std-{}-{}{}".format(
rustc_channel, self.build, tarball_suffix)
pattern = "rust-std-{}".format(self.build)
filename = f"rust-std-{rustc_channel}-{self.build}{tarball_suffix}"
pattern = f"rust-std-{self.build}"
self._download_component_helper(filename, pattern, tarball_suffix, stage0)
filename = "rustc-{}-{}{}".format(rustc_channel, self.build,
tarball_suffix)
filename = f"rustc-{rustc_channel}-{self.build}{tarball_suffix}"
self._download_component_helper(filename, "rustc", tarball_suffix, stage0)
# download-rustc doesn't need its own cargo, it can just use beta's.
if stage0:
filename = "cargo-{}-{}{}".format(rustc_channel, self.build,
tarball_suffix)
filename = f"cargo-{rustc_channel}-{self.build}{tarball_suffix}"
self._download_component_helper(filename, "cargo", tarball_suffix)
self.fix_bin_or_dylib("{}/bin/cargo".format(bin_root))
self.fix_bin_or_dylib(f"{bin_root}/bin/cargo")
else:
filename = "rustc-dev-{}-{}{}".format(rustc_channel, self.build, tarball_suffix)
filename = f"rustc-dev-{rustc_channel}-{self.build}{tarball_suffix}"
self._download_component_helper(
filename, "rustc-dev", tarball_suffix, stage0
)

self.fix_bin_or_dylib("{}/bin/rustc".format(bin_root))
self.fix_bin_or_dylib("{}/bin/rustdoc".format(bin_root))
lib_dir = "{}/lib".format(bin_root)
self.fix_bin_or_dylib(f"{bin_root}/bin/rustc")
self.fix_bin_or_dylib(f"{bin_root}/bin/rustdoc")
lib_dir = f"{bin_root}/lib"
for lib in os.listdir(lib_dir):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(lib_dir, lib))
with output(self.rustc_stamp(stage0)) as rust_stamp:
rust_stamp.write(key)

if self.rustfmt() and self.rustfmt().startswith(bin_root) and (
not os.path.exists(self.rustfmt())
or self.program_out_of_date(
self.rustfmt_stamp(),
"" if self.stage0_rustfmt is None else self.stage0_rustfmt.channel()
if (
self.rustfmt()
and self.rustfmt().startswith(bin_root)
and (
not os.path.exists(self.rustfmt())
or self.program_out_of_date(
self.rustfmt_stamp(),
""
if self.stage0_rustfmt is None
else self.stage0_rustfmt.channel(),
)
)
and self.stage0_rustfmt is not None
):
if self.stage0_rustfmt is not None:
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
filename = "rustfmt-{}-{}{}".format(
self.stage0_rustfmt.version, self.build, tarball_suffix,
)
self._download_component_helper(
filename, "rustfmt-preview", tarball_suffix, key=self.stage0_rustfmt.date
)
self.fix_bin_or_dylib("{}/bin/rustfmt".format(bin_root))
self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(bin_root))
with output(self.rustfmt_stamp()) as rustfmt_stamp:
rustfmt_stamp.write(self.stage0_rustfmt.channel())
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
filename = f"rustfmt-{self.stage0_rustfmt.version}-{self.build}{tarball_suffix}"

self._download_component_helper(
filename, "rustfmt-preview", tarball_suffix, key=self.stage0_rustfmt.date
)
self.fix_bin_or_dylib(f"{bin_root}/bin/rustfmt")
self.fix_bin_or_dylib(f"{bin_root}/bin/cargo-fmt")
with output(self.rustfmt_stamp()) as rustfmt_stamp:
rustfmt_stamp.write(self.stage0_rustfmt.channel())
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.download_toolchain refactored with the following changes:

This removes the following comments ( why? ):

# the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`

Comment on lines -577 to +582
if stage0:
key = self.stage0_compiler.date
else:
key = self.rustc_commit
key = self.stage0_compiler.date if stage0 else self.rustc_commit
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild._download_component_helper refactored with the following changes:

Comment on lines -611 to +620
cache_prefix = "llvm-{}-{}".format(llvm_sha, llvm_assertions)
cache_prefix = f"llvm-{llvm_sha}-{llvm_assertions}"
cache_dst = os.path.join(self.build_dir, "cache")
rustc_cache = os.path.join(cache_dst, cache_prefix)
if not os.path.exists(rustc_cache):
os.makedirs(rustc_cache)

base = "https://ci-artifacts.rust-lang.org"
url = "rustc-builds/{}".format(llvm_sha)
url = f"rustc-builds/{llvm_sha}"
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild._download_ci_llvm refactored with the following changes:

Comment on lines -681 to +688
if not any(line.strip() == "ID=nixos" for line in f):
if all(line.strip() != "ID=nixos" 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 RustBuild.fix_bin_or_dylib refactored with the following changes:

Comment on lines -753 to +766
assert download_rustc == "true" or download_rustc == "if-unchanged", download_rustc
assert download_rustc in ["true", "if-unchanged"], download_rustc

# Handle running from a directory other than the top level
rev_parse = ["git", "rev-parse", "--show-toplevel"]
top_level = subprocess.check_output(rev_parse, universal_newlines=True).strip()
compiler = "{}/compiler/".format(top_level)
library = "{}/library/".format(top_level)
compiler = f"{top_level}/compiler/"
library = f"{top_level}/library/"
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.maybe_download_ci_toolchain refactored with the following changes:

@sourcery-ai sourcery-ai bot force-pushed the sourcery/master branch from 2e872ec to a3588a7 Compare March 31, 2022 13:46
Comment on lines -848 to +857
if stage0:
subdir = "stage0"
else:
subdir = "ci-rustc"
subdir = "stage0" if stage0 else "ci-rustc"
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.bin_root refactored with the following changes:

Comment on lines -902 to +912
cur_section = section_match.group(1)
cur_section = section_match[1]

match = re.match(r'^{}\s*=(.*)$'.format(key), line)
match = re.match(f'^{key}\\s*=(.*)$', line)
if match is not None:
value = match.group(1)
value = match[1]
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.get_toml refactored with the following changes:

Comment on lines -921 to +927
if self.stage0_rustfmt is None:
return None
return self.program_config('rustfmt')
return None if self.stage0_rustfmt is None else self.program_config('rustfmt')
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.rustfmt refactored with the following changes:

Comment on lines -942 to +950
config = self.get_toml(program)
if config:
if config := self.get_toml(program):
return os.path.expanduser(config)
return os.path.join(self.bin_root(stage0), "bin", "{}{}".format(
program, self.exe_suffix()))
return os.path.join(
self.bin_root(stage0), "bin", f"{program}{self.exe_suffix()}"
)
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.program_config refactored with the following changes:

Comment on lines -974 to +978
if sys.platform == 'win32':
return '.exe'
return ''
return '.exe' if sys.platform == 'win32' else ''
Copy link
Author

Choose a reason for hiding this comment

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

Function RustBuild.exe_suffix refactored with the following changes:

Comment on lines -448 to +443
if not line.startswith('#' + key + ' = '):
if not line.startswith(f'#{key} = '):
continue
found = True
lines[i] = "{} = {}".format(key, to_toml(value))
lines[i] = f"{key} = {to_toml(value)}"
break
if not found:
# These are used by rpm, but aren't accepted by x.py.
# Give a warning that they're ignored, but not a hard error.
if key in ["infodir", "localstatedir"]:
print("warning: {} will be ignored".format(key))
print(f"warning: {key} will be ignored")
else:
raise RuntimeError("failed to find config line for {}".format(key))
raise RuntimeError(f"failed to find config line for {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 configure_section refactored with the following changes:

This removes the following comments ( why? ):

# Give a warning that they're ignored, but not a hard error.
# These are used by rpm, but aren't accepted by x.py.

Comment on lines -465 to +449
raise RuntimeError("config key {} not in sections".format(section_key))
raise RuntimeError(f"config key {section_key} not in sections")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 465-495 refactored with the following changes:

Comment on lines -57 to +68
"hash mismatch for package " + self.path + ": " +
sha1 + " vs " + self.sha1 + " (known good)"
(
(
(
(f"hash mismatch for package {self.path}: " + sha1)
+ " vs "
)
+ self.sha1
)
+ " (known good)"
)
)

Copy link
Author

Choose a reason for hiding this comment

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

Function Package.download refactored with the following changes:

Comment on lines -63 to +72
return "<Package "+self.path+" at "+self.url+" (sha1="+self.sha1+")"
return f"<Package {self.path} at {self.url} (sha1={self.sha1})"
Copy link
Author

Choose a reason for hiding this comment

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

Function Package.__repr__ refactored with the following changes:

Comment on lines -88 to +97
for dep in dependencies:
deps.append(dep.attrib["path"])

deps.extend(dep.attrib["path"] for dep in dependencies)
Copy link
Author

Choose a reason for hiding this comment

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

Function fetch_repository refactored with the following changes:

Comment on lines -114 to +121
raise NameError("package not found: " + name)
raise NameError(f"package not found: {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 Lockfile.add refactored with the following changes:

Comment on lines -125 to +132
f.write(package.path + " " + package.url + " " + package.sha1 + "\n")
f.write(f'{package.path} {package.url} {package.sha1}' + "\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 Lockfile.save refactored with the following changes:

Comment on lines -138 to +155
subprocess.run([
"aws", "s3", "mv", path,
"s3://" + MIRROR_BUCKET + "/" + MIRROR_BASE_DIR + package.url,
"--profile=" + args.awscli_profile,
], check=True)
subprocess.run(
[
"aws",
"s3",
"mv",
path,
f"s3://{MIRROR_BUCKET}/{MIRROR_BASE_DIR}{package.url}",
f"--profile={args.awscli_profile}",
],
check=True,
)
Copy link
Author

Choose a reason for hiding this comment

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

Function cli_update_mirror refactored with the following changes:

Comment on lines -148 to +165
url = "https://" + MIRROR_BUCKET + ".s3-" + MIRROR_BUCKET_REGION + \
".amazonaws.com/" + MIRROR_BASE_DIR
url = (
f"https://{MIRROR_BUCKET}.s3-{MIRROR_BUCKET_REGION}"
+ ".amazonaws.com/"
) + MIRROR_BASE_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 cli_install refactored with the following changes:

check_generic_bound(bound)
args = ty["inner"]["args"]
if args:
if args := ty["inner"]["args"]:
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_type refactored with the following changes:

Comment on lines -205 to +202
if borrow >= 0:
return "Ref(borrow={})".format(borrow)
else:
return "Ref(borrow_mut={})".format(-borrow)
return f"Ref(borrow={borrow})" if borrow >= 0 else f"Ref(borrow_mut={-borrow})"
Copy link
Author

Choose a reason for hiding this comment

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

Function StdRefProvider.to_string refactored with the following changes:

Comment on lines -223 to +219
return "RefCell(borrow={})".format(borrow)
return f"RefCell(borrow={borrow})"
else:
return "RefCell(borrow_mut={})".format(-borrow)
return f"RefCell(borrow_mut={-borrow})"
Copy link
Author

Choose a reason for hiding this comment

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

Function StdRefCellProvider.to_string refactored with the following changes:

Comment on lines -279 to +273
return "BTreeSet(size={})".format(self.valobj["map"]["length"])
return f'BTreeSet(size={self.valobj["map"]["length"]})'
Copy link
Author

Choose a reason for hiding this comment

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

Function StdBTreeSetProvider.to_string refactored with the following changes:

Comment on lines -284 to +278
yield "[{}]".format(i), child
yield (f"[{i}]", child)
Copy link
Author

Choose a reason for hiding this comment

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

Function StdBTreeSetProvider.children refactored with the following changes:

Comment on lines -296 to +290
return "BTreeMap(size={})".format(self.valobj["length"])
return f'BTreeMap(size={self.valobj["length"]})'
Copy link
Author

Choose a reason for hiding this comment

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

Function StdBTreeMapProvider.to_string refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 31, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.12%.

Quality metrics Before After Change
Complexity 13.29 🙂 12.65 🙂 -0.64 👍
Method Length 56.82 ⭐ 56.98 ⭐ 0.16 👎
Working memory 8.67 🙂 8.73 🙂 0.06 👎
Quality 61.20% 🙂 61.32% 🙂 0.12% 👍
Other metrics Before After Change
Lines 5212 5212 0
Changed files Quality Before Quality After Quality Change
library/core/src/unicode/printable.py 62.37% 🙂 64.36% 🙂 1.99% 👍
src/bootstrap/bootstrap.py 50.22% 🙂 50.69% 🙂 0.47% 👍
src/bootstrap/configure.py 45.58% 😞 45.62% 😞 0.04% 👍
src/ci/docker/scripts/android-sdk-manager.py 75.85% ⭐ 76.59% ⭐ 0.74% 👍
src/etc/check_missing_items.py 35.21% 😞 34.86% 😞 -0.35% 👎
src/etc/dec2flt_table.py 60.43% 🙂 60.90% 🙂 0.47% 👍
src/etc/gdb_lookup.py 50.02% 🙂 52.08% 🙂 2.06% 👍
src/etc/gdb_providers.py 75.44% ⭐ 75.03% ⭐ -0.41% 👎
src/etc/generate-deriving-span-tests.py 73.67% 🙂 72.85% 🙂 -0.82% 👎
src/etc/generate-keyword-tests.py 72.11% 🙂 71.82% 🙂 -0.29% 👎
src/etc/htmldocck.py 61.54% 🙂 61.66% 🙂 0.12% 👍
src/etc/lldb_batchmode.py 63.84% 🙂 64.59% 🙂 0.75% 👍
src/etc/lldb_providers.py 86.55% ⭐ 86.12% ⭐ -0.43% 👎
src/etc/rust_types.py 55.04% 🙂 54.30% 🙂 -0.74% 👎
src/etc/test-float-parse/runtests.py 67.89% 🙂 68.14% 🙂 0.25% 👍
src/test/run-make-fulldeps/rustdoc-map-file/validate_json.py 68.37% 🙂 64.13% 🙂 -4.24% 👎
src/test/run-make-fulldeps/sysroot-crates-are-unstable/test.py 80.26% ⭐ 78.27% ⭐ -1.99% 👎
src/tools/publish_toolstate.py 44.77% 😞 45.23% 😞 0.46% 👍
src/tools/clippy/util/versions.py 80.36% ⭐ 80.12% ⭐ -0.24% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
src/etc/htmldocck.py check_command 53 ⛔ 464 ⛔ 18 ⛔ 8.91% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/bootstrap/bootstrap.py RustBuild.download_toolchain 38 ⛔ 488 ⛔ 18 ⛔ 12.29% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/bootstrap/bootstrap.py default_build_triple 48 ⛔ 494 ⛔ 14 😞 13.85% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/tools/publish_toolstate.py update_latest 28 😞 285 ⛔ 22 ⛔ 17.52% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/etc/check_missing_items.py check_type 75 ⛔ 277 ⛔ 12 😞 17.82% ⛔ 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