-
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 main branch #2
base: main
Are you sure you want to change the base?
Conversation
for p in _DENY_PATH_LIST: | ||
if p in path: | ||
return False | ||
return True | ||
return all(p not in path for p in _DENY_PATH_LIST) |
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 path_filter
refactored with the following changes:
- Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
if e.errno == errno.EEXIST: | ||
os.remove(link_name) | ||
os.symlink(target, link_name) | ||
else: | ||
if e.errno != errno.EEXIST: | ||
raise e | ||
os.remove(link_name) | ||
os.symlink(target, link_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 symlink_force
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var))) | ||
write_to_bazelrc(f'build --action_env {var_name}="{str(var)}"') |
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 write_action_env_to_bazelrc
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
paths = [] | ||
for path in all_paths: | ||
if os.path.isdir(path): | ||
paths.append(path) | ||
return paths | ||
return [path for path in all_paths if os.path.isdir(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 get_python_path
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
checked_python_lib_path = check_safe_python_lib_path(python_lib_path) | ||
else: | ||
print('Found possible Python library paths:') | ||
print(python_lib_paths) | ||
print('\n') | ||
default_python_lib_path = check_safe_python_lib_path(python_lib_paths[0]) | ||
python_lib_path = default_python_lib_path | ||
checked_python_lib_path = check_safe_python_lib_path(python_lib_path) | ||
checked_python_lib_path = check_safe_python_lib_path(python_lib_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 setup_python
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
batch = {k: np.array(v) for k, v in batch.items()} | ||
|
||
yield batch | ||
yield {k: np.array(v) for k, v in batch.items()} |
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 eval_data_collator
refactored with the following changes:
- Inline variable that is immediately yielded (
inline-immediately-yielded-variable
)
and not any(p["offsets"] == (0, 0) for p in predictions) | ||
and all(p["offsets"] != (0, 0) for p in predictions) |
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 postprocess_qa_predictions
refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all
)
with open(str(current_path) + "/prompt.json") as f: | ||
with open(f"{str(current_path)}/prompt.json") as 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.
Lines 72-72
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
gen_tokens = model.generate(input_ids, max_new_tokens=max_new_tokens, **generate_kwargs) | ||
return gen_tokens | ||
return model.generate( | ||
input_ids, max_new_tokens=max_new_tokens, **generate_kwargs | ||
) |
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 run_model
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print("Accuracy = {}".format(acc)) | ||
print(f"Accuracy = {acc}") |
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 144-144
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
match = re.match(r"#define %s +(\d+)" % name, line) | ||
if match: | ||
if match := re.match(r"#define %s +(\d+)" % name, line): | ||
value = match.group(1) | ||
return int(value) | ||
|
||
raise ConfigError('#define "{}" is either\n'.format(name) + | ||
" not present in file {} OR\n".format(path) + | ||
" its value is not an integer literal") | ||
raise ConfigError( | ||
((f'#define "{name}" is either\n' + f" not present in file {path} OR\n") | ||
+ " its value is not an integer literal")) |
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_header_version
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
'Specified SYCL_TOOLKIT_PATH "{}" does not exist'.format(basekit_path)) | ||
f'Specified SYCL_TOOLKIT_PATH "{basekit_path}" does not exist') | ||
|
||
result = {} | ||
result = {"sycl_basekit_path": basekit_path, "sycl_toolkit_path": toolkit_path} | ||
|
||
result["sycl_basekit_path"] = basekit_path | ||
result["sycl_toolkit_path"] = toolkit_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 find_sycl_config
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Merge dictionary assignment with declaration [×2] (
merge-dict-assign
)
print("%s: %s" % (key, value)) | ||
print(f"{key}: {value}") | ||
except ConfigError as e: | ||
sys.stderr.write("\nERROR: {}\n\n".format(str(e))) | ||
sys.stderr.write(f"\nERROR: {str(e)}\n\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 main
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Replace call to format with f-string (
use-fstring-for-formatting
)
cmd = path + " -dM -E -x c /dev/null | grep '__INTEL_LLVM_COMPILER'" | ||
cmd = f"{path} -dM -E -x c /dev/null | grep '__INTEL_LLVM_COMPILER'" | ||
check_result = subprocess.getoutput(cmd) | ||
if len(check_result) > 0 and check_result.find('__INTEL_LLVM_COMPILER') > -1: | ||
return True | ||
return False | ||
return (len(check_result) > 0 | ||
and check_result.find('__INTEL_LLVM_COMPILER') > -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 check_is_intel_llvm
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if os.WIFEXITED(ret): | ||
return os.WEXITSTATUS(ret) | ||
else: | ||
return -os.WTERMSIG(ret) | ||
return os.WEXITSTATUS(ret) if os.WIFEXITED(ret) else -os.WTERMSIG(ret) |
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 system
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
only_gen_header=False | ||
if args["--header"].lower() == "true": | ||
only_gen_header=True | ||
|
||
only_gen_header = args["--header"].lower() == "true" |
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 main
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Replace if statement with if expression (
assign-if-exp
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
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 parse_version
refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator
)
root = header_in[:pos] | ||
return root | ||
return header_in[:pos] |
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_root
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
cmake = os.path.join(root, "CMakeLists.txt") | ||
return cmake | ||
return os.path.join(root, "CMakeLists.txt") |
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_cmake
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
@@ -16,6 +16,7 @@ | |||
lib_setup.py file to build wheel for Intel® Extension for OpenXLA* | |||
''' | |||
|
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 43-57
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Merge append into list declaration (
merge-list-append
)
matches.extend( | ||
['../' + x for x in find_files('*', path) if '.py' not in x] | ||
) | ||
matches.extend([f'../{x}' for x in find_files('*', path) if '.py' not in x]) |
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 81-83
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Apply Sweep Rules to your PR?
|
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:Help us improve this pull request!