-
Notifications
You must be signed in to change notification settings - Fork 23
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 master branch #207
base: master
Are you sure you want to change the base?
Conversation
@@ -37,6 +37,7 @@ | |||
|
|||
"""Script to render latex figure for each equation found in readme.md""" | |||
|
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 52-52
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
latexfile = open(laxtex_tmp_file, "w") | ||
latexfile.write("\\documentclass[preview]{standalone}") | ||
# latexfile.write('\\input{header.tex}') | ||
latexfile.write("\\usepackage{wasysym}") | ||
latexfile.write("\\usepackage{amssymb}") | ||
latexfile.write("\n\\begin{document}") | ||
latexfile.write(" %s" % formula) | ||
latexfile.write("\n\\end{document} ") | ||
latexfile.close() | ||
with open(laxtex_tmp_file, "w") as latexfile: | ||
latexfile.write("\\documentclass[preview]{standalone}") | ||
# latexfile.write('\\input{header.tex}') | ||
latexfile.write("\\usepackage{wasysym}") | ||
latexfile.write("\\usepackage{amssymb}") | ||
latexfile.write("\n\\begin{document}") | ||
latexfile.write(f" {formula}") | ||
latexfile.write("\n\\end{document} ") | ||
os.system('pdflatex -output-directory="%s" %s' % (dirpath, laxtex_tmp_file)) | ||
if file.startswith("https://rawgithub.com") or file.startswith( | ||
"https://raw.githack.com" | ||
): | ||
file = "./" + re.findall(r"""/master/(.*)""", file)[0] | ||
if file[-3:] == "svg": | ||
os.system("pdf2svg %s %s" % (pdf_tmp_file, file)) | ||
os.system(f"pdf2svg {pdf_tmp_file} {file}") | ||
elif file[-3:] == "pdf": | ||
shutil.copyfile(pdf_tmp_file, file) | ||
else: | ||
os.system("convert -density 100 %s -quality 90 %s" % (pdf_tmp_file, file)) | ||
os.system(f"convert -density 100 {pdf_tmp_file} -quality 90 {file}") |
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 formula_as_file
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
raise Exception("equation image file %s already used" % eqn[1]) | ||
raise Exception(f"equation image file {eqn[1]} already used") | ||
|
||
listname.add(eqn[1]) | ||
print("creating %s" % eqn[1]) | ||
print(f"creating {eqn[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.
Lines 94-97
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
@@ -1,5 +1,6 @@ | |||
"""Setup script for the DEODR project.""" | |||
|
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 30-31
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
assert not (image is None) | ||
assert not (z_buffer is None) | ||
assert image is not None | ||
assert z_buffer is not 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 renderScene
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if self.clockwise: | ||
n = -np.cross(u, v) | ||
else: | ||
n = np.cross(u, v) | ||
n = -np.cross(u, v) if self.clockwise else np.cross(u, v) |
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 TriMeshAdjacencies.compute_face_normals
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
face_normals_b = self._vertices_faces.T * n_b | ||
return face_normals_b | ||
return self._vertices_faces.T * n_b |
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 TriMeshAdjacencies.compute_vertex_normals_backward
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if self.clockwise: | ||
face_visible = np.cross(u, v) > 0 | ||
else: | ||
face_visible = np.cross(u, v) < 0 | ||
face_visible = np.cross(u, v) > 0 if self.clockwise else np.cross(u, v) < 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 TriMeshAdjacencies.edge_on_silhouette
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if self.vertices is not None: | ||
|
||
if self.adjacencies.is_closed: | ||
self.check_orientation() | ||
if self.vertices is not None and self.adjacencies.is_closed: | ||
self.check_orientation() |
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 TriMesh.compute_adjacencies
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
self.textured = not (self.texture is None) | ||
self.textured = self.texture is not None | ||
self.nb_colors = nb_colors | ||
if nb_colors is None: | ||
if texture is None: | ||
self.nb_colors = colors.shape[1] | ||
else: | ||
self.nb_colors = texture.shape[2] | ||
self.nb_colors = colors.shape[1] if texture is None else texture.shape[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 ColoredTriMesh.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Replace if statement with if expression (
assign-if-exp
)
trimesh_mesh = trimesh.Trimesh( | ||
return trimesh.Trimesh( | ||
vertices=new_vertices, faces=new_faces, visual=visual | ||
) | ||
return trimesh_mesh |
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 ColoredTriMesh.to_trimesh
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if display: | ||
cv2.imshow("animation", cv2.resize(combined_image, None, fx=2, fy=2)) | ||
if save_images: | ||
imsave( | ||
os.path.join(iterfolder, f"depth_hand_iter_{niter}.png"), | ||
combined_image, | ||
) | ||
if display: | ||
cv2.imshow("animation", cv2.resize(combined_image, None, fx=2, fy=2)) | ||
if save_images: | ||
imsave( | ||
os.path.join(iterfolder, f"depth_hand_iter_{niter}.png"), | ||
combined_image, | ||
) | ||
cv2.waitKey(1) | ||
|
||
with open( | ||
os.path.join( | ||
iterfolder, | ||
"depth_image_fitting_result_%s.json" | ||
% str(datetime.datetime.now()).replace(":", "_"), | ||
), | ||
"w", | ||
) as f: | ||
with open(os.path.join(iterfolder, f'depth_image_fitting_result_{str(datetime.datetime.now()).replace(":", "_")}.json'), "w") 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.
Function run
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if self.mode in ["camera_centered", "object_centered_trackball"]: | ||
if np.abs(self.y_last - y) >= np.abs(self.x_last - x): | ||
self.camera.extrinsic[2, 3] += self.z_translation_speed * ( | ||
self.y_last - y | ||
) | ||
else: | ||
self.rotate( | ||
[ | ||
0, | ||
0, | ||
-self.rotation_speed * (self.x_last - x), | ||
] | ||
) | ||
self.x_last = x | ||
self.y_last = y | ||
if self.mode not in ["camera_centered", "object_centered_trackball"]: | ||
raise (BaseException(f"unknown camera mode {self.mode}")) | ||
|
||
if np.abs(self.y_last - y) >= np.abs(self.x_last - x): | ||
self.camera.extrinsic[2, 3] += self.z_translation_speed * ( | ||
self.y_last - y | ||
) | ||
else: | ||
raise (BaseException(f"unknown camera mode {self.mode}")) | ||
self.rotate( | ||
[ | ||
0, | ||
0, | ||
-self.rotation_speed * (self.x_last - x), | ||
] | ||
) | ||
self.x_last = x | ||
self.y_last = y |
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 Interactor.mouse_callback
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
help_str = "" | ||
help_str += "Mouse:\n" | ||
help_str = "" + "Mouse:\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 Interactor.print_help
refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
help_str = "" | ||
help_str += "-----------------\n" | ||
help_str = "" + "-----------------\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 Viewer.print_help
refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
)
self.textured = not (self.texture is None) | ||
self.textured = self.texture is not 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 ColoredTriMeshPytorch.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
if self.clockwise: | ||
n = -tf.linalg.cross(u, v) | ||
else: | ||
n = tf.linalg.cross(u, v) | ||
n = -tf.linalg.cross(u, v) if self.clockwise else tf.linalg.cross(u, v) |
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 TriMeshAdjacenciesTensorflow.compute_face_normals
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
self.textured = not (self.texture is None) | ||
self.textured = self.texture is not 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 ColoredTriMeshTensorflow.__init__
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
eps = 0.001 | ||
|
||
clockwise = 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 test_upper_left_pixel_center_coordinates
refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop
)
if not os.name == "nt": # did not manage to install mesa on windows github action | ||
if os.name != "nt": # did not manage to install mesa on windows github action |
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_render_mesh_moderngl
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
Sourcery Code Quality ReportMerging this PR leaves code quality unchanged.
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
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:Help us improve this pull request!