-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored relax branch #1
base: relax
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
HARDCODED_ALLOCATIONS = {} | ||
for idx, test in enumerate(_slowest_tests): | ||
HARDCODED_ALLOCATIONS[test] = idx | ||
|
||
HARDCODED_ALLOCATIONS = {test: idx for idx, test in enumerate(_slowest_tests)} |
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 55-58
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
)
if not all(k in os.environ for k in ["CI", "TVM_NUM_SHARDS", "TVM_SHARD_INDEX"]): | ||
if any( | ||
k not in os.environ | ||
for k in ["CI", "TVM_NUM_SHARDS", "TVM_SHARD_INDEX"] | ||
): |
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 pytest_collection_modifyitems
refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all
)
pub_ver = "%s.dev%s" % (dev_version, arr_info[1]) | ||
local_ver = "%s+%s" % (pub_ver, arr_info[2]) | ||
pub_ver = f"{dev_version}.dev{arr_info[1]}" | ||
local_ver = f"{pub_ver}+{arr_info[2]}" |
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 git_describe_version
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
result = re.findall(pattern, l) | ||
if result: | ||
if result := re.findall(pattern, l): | ||
assert len(result) == 1 | ||
hit_counter += 1 | ||
if result[0] != repl: | ||
l = re.sub(pattern, repl, l) | ||
need_update = True | ||
print("%s: %s -> %s" % (file_name, result[0], repl)) | ||
print(f"{file_name}: {result[0]} -> {repl}") | ||
else: | ||
print("%s: version is already %s" % (file_name, repl)) | ||
print(f"{file_name}: version is already {repl}") | ||
|
||
update.append(l) | ||
if hit_counter != 1: | ||
raise RuntimeError("Cannot find version in %s" % file_name) | ||
raise RuntimeError(f"Cannot find version in {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 update
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
)
npm_ver = pub_ver if dev_pos == -1 else "%s.0-%s" % (pub_ver[:dev_pos], pub_ver[dev_pos + 1 :]) | ||
npm_ver = ( | ||
pub_ver | ||
if dev_pos == -1 | ||
else f"{pub_ver[:dev_pos]}.0-{pub_ver[dev_pos + 1:]}" | ||
) | ||
|
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 sync_version
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if target == "metal": | ||
dev = remote.metal(0) | ||
else: | ||
dev = remote.cpu(0) | ||
dev = remote.metal(0) if target == "metal" else remote.cpu(0) |
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 test_mobilenet
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
help="type of RPC connection (default: tracker), possible values: {}".format( | ||
", ".join(MODES.keys()) | ||
), | ||
help=f'type of RPC connection (default: tracker), possible values: {", ".join(MODES.keys())}', | ||
) | ||
|
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 177-179
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
@@ -20,6 +20,7 @@ | |||
And configure the proxy host field as commented. | |||
""" | |||
|
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 36-36
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
help="type of RPC connection (default: tracker), possible values: {}".format( | ||
", ".join(MODES.keys()) | ||
), | ||
help=f'type of RPC connection (default: tracker), possible values: {", ".join(MODES.keys())}', | ||
) | ||
|
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 108-110
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
|
||
|
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 60-80
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
)
all_module_names = [] | ||
for name in metadata["modules"].keys(): | ||
all_module_names.append(name) | ||
|
||
all_module_names = list(metadata["modules"].keys()) | ||
assert all( | ||
metadata["modules"][mod_name]["style"] == "full-model" for mod_name in all_module_names | ||
), "when generating AOT, expect only full-model Model Library Format" | ||
|
||
workspace_size_bytes = 0 | ||
for mod_name in all_module_names: | ||
workspace_size_bytes += metadata["modules"][mod_name]["memory"]["functions"]["main"][0][ | ||
workspace_size_bytes = sum( | ||
metadata["modules"][mod_name]["memory"]["functions"]["main"][0][ | ||
"workspace_size_bytes" | ||
] | ||
for mod_name in all_module_names | ||
) | ||
|
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 Handler._template_model_header
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Convert for loop into call to sum() (
sum-comprehension
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
# Check if line has an include | ||
result = re.search(r"#include\s*[<\"]([^>]*)[>\"]", line_str) | ||
if not result: | ||
dst_file.write(line) | ||
else: | ||
if result := re.search( | ||
r"#include\s*[<\"]([^>]*)[>\"]", line_str | ||
): | ||
new_include = self._find_modified_include_path( | ||
project_dir, filename, result.groups()[0] | ||
) | ||
updated_line = f'#include "{new_include}"\n' | ||
dst_file.write(updated_line.encode("utf-8")) | ||
else: | ||
dst_file.write(line) |
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 Handler._convert_includes
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Swap if/else branches (
swap-if-else-branches
)
This removes the following comments ( why? ):
# Check if line has an include
str_version = re.search(r"Version: ([\.0-9]*)", version_output).group(1) | ||
str_version = re.search(r"Version: ([\.0-9]*)", version_output)[1] |
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 Handler._get_platform_version
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
assert len(column_headers) > 0 | ||
assert column_headers |
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 Handler._parse_connected_boards
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
assert mock_run.call_args_list[1][0][0][0:2] == ["arduino-cli", "upload"] | ||
assert mock_run.call_args_list[1][0][0][:2] == ["arduino-cli", "upload"] |
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 TestGenerateProject.test_flash
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] [×2] (
remove-redundant-slice-index
)
WEST_CMD = default = sys.executable + " -m west" if sys.executable else None | ||
WEST_CMD = default = f"{sys.executable} -m west" if sys.executable else 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.
Lines 70-70
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if len(serial_ports) == 0: | ||
if not serial_ports: | ||
raise Exception(f"No serial port found for board {prop['board']}!") | ||
|
||
if len(serial_ports) != 1: | ||
ports_lst = "" | ||
for port in serial_ports: | ||
ports_lst += f"Serial port: {port.device}, serial number: {port.serial_number}\n" | ||
ports_lst = "".join( | ||
f"Serial port: {port.device}, serial number: {port.serial_number}\n" | ||
for port in serial_ports | ||
) |
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 generic_find_serial_port
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
) - Use str.join() instead of for loop (
use-join
)
if not boards: | ||
return [] | ||
|
||
return ["--snr", boards[0]] | ||
return ["--snr", boards[0]] if boards else [] |
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_nrf_device_args
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
)
for d in (API_SERVER_DIR / "src").iterdir(): | ||
if d.is_dir(): | ||
PROJECT_TYPES.append(d.name) | ||
|
||
PROJECT_TYPES.extend( | ||
d.name for d in (API_SERVER_DIR / "src").iterdir() if d.is_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.
Lines 255-311
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
)
if nrf_board == None: | ||
if nrf_board is 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 ZephyrSerialTransport._find_nrf_serial_port
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
to_return = self._port.read(n) | ||
if not to_return: | ||
if to_return := self._port.read(n): | ||
return to_return | ||
else: | ||
raise server.IoTimeoutError() | ||
|
||
return to_return |
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 ZephyrSerialTransport.read
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
file_path = pathlib.Path(f"{output_path}/" + name).resolve() | ||
file_path = pathlib.Path(f"{output_path}/{name}").resolve() |
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_file
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for _, label in enumerate(labels): | ||
for label in labels: |
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_labels_header
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
)
def main(A: T.Buffer[8, "float32"], B: T.Buffer[8, "float32"]) -> None: | ||
def main(self, B: T.Buffer[8, "float32"]) -> None: | ||
T.func_attr({"global_symbol": "main", "tir.noalias": True}) | ||
for i_0 in T.thread_binding(2, thread="blockIdx.x"): | ||
for i_2 in T.thread_binding(2, thread="threadIdx.x"): | ||
for i_1 in T.serial(2): | ||
with T.block("B"): | ||
vi = T.axis.spatial(8, i_0 * 4 + i_1 * 2 + i_2) | ||
T.reads(A[vi]) | ||
T.reads(self[vi]) | ||
T.writes(B[vi]) | ||
B[vi] = A[vi] + T.float32(1) | ||
B[vi] = self[vi] + T.float32(1) |
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 ModuleGPU.main
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
def main(a: T.handle, b: T.handle): | ||
def main(self, b: T.handle): | ||
# We exchange data between function by handles, which are similar to pointer. | ||
T.func_attr({"global_symbol": "main", "tir.noalias": True}) | ||
# Create buffer from handles. | ||
A = T.match_buffer(a, (8,), dtype="float32") | ||
A = T.match_buffer(self, (8,), dtype="float32") |
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 MyModule.main
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
ptx = nvcc.compile_cuda(code, target_format="ptx") | ||
return ptx | ||
return nvcc.compile_cuda(code, target_format="ptx") |
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 tvm_callback_cuda_compile
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
write_code(code, "perf/%s_generated.cu" % TASK) | ||
write_code(code, f"perf/{TASK}_generated.cu") | ||
if USE_MANUAL_CODE: | ||
code = open("perf/%s_manual.cu" % TASK).read() | ||
code = open(f"perf/{TASK}_manual.cu").read() |
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 tvm_callback_cuda_postproc
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
print("Skip because %s is not enabled" % device) | ||
print(f"Skip because {device} is not enabled") |
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 test_depthwise_conv2d_nchw
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
print("Skip because %s is not enabled" % device) | ||
print(f"Skip because {device} is not enabled") |
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 test_depthwise_conv2d_nhwc
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
ptx = nvcc.compile_cuda(code, target_format="ptx") | ||
return ptx | ||
return nvcc.compile_cuda(code, target_format="ptx") |
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 tvm_callback_cuda_compile
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.19%.
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
relax
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
relax
branch, then run:Help us improve this pull request!