Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 23, 2023

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 ludoplex November 23, 2023 15:50
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)
Copy link
Author

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:

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

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:

Comment on lines -130 to +126
write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var)))
write_to_bazelrc(f'build --action_env {var_name}="{str(var)}"')
Copy link
Author

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:

Comment on lines -230 to +226
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)]
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_python_path refactored with the following changes:

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

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:

Comment on lines -419 to +417
batch = {k: np.array(v) for k, v in batch.items()}

yield batch
yield {k: np.array(v) for k, v in batch.items()}
Copy link
Author

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:

and not any(p["offsets"] == (0, 0) for p in predictions)
and all(p["offsets"] != (0, 0) for p in predictions)
Copy link
Author

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:

with open(str(current_path) + "/prompt.json") as f:
with open(f"{str(current_path)}/prompt.json") as f:
Copy link
Author

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:

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

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:

Comment on lines -144 to +145
print("Accuracy = {}".format(acc))
print(f"Accuracy = {acc}")
Copy link
Author

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:

Comment on lines -63 to +69
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"))
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_header_version refactored with the following changes:

Comment on lines -111 to -116
'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
Copy link
Author

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:

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

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:

Comment on lines -31 to +34
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)
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_is_intel_llvm refactored with the following changes:

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

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:

Comment on lines -315 to +304
only_gen_header=False
if args["--header"].lower() == "true":
only_gen_header=True

only_gen_header = args["--header"].lower() == "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 main refactored with the following changes:

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 parse_version refactored with the following changes:

root = header_in[:pos]
return root
return header_in[:pos]
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_root refactored with the following changes:

Comment on lines -49 to +48
cmake = os.path.join(root, "CMakeLists.txt")
return cmake
return os.path.join(root, "CMakeLists.txt")
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_cmake refactored with the following changes:

@@ -16,6 +16,7 @@
lib_setup.py file to build wheel for Intel® Extension for OpenXLA*
'''

Copy link
Author

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:

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

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:

Copy link

sweep-ai bot commented Nov 23, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.

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