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 master branch #36

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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 1, 2020

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^

Comment on lines -433 to +437
sections = []
for material in a.materials.keys():
sections.append('*SOLID SECTION, ELSET={0}, MATERIAL={0}\n'.format(material))
sections = [
'*SOLID SECTION, ELSET={0}, MATERIAL={0}\n'.format(material)
for material in a.materials.keys()
]

Copy link
Author

Choose a reason for hiding this comment

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

Function Material.add_sections refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)

Comment on lines -1183 to +1196
abaqus_format = ['\n** -------------------------------------------------------------\n']
abaqus_format.append('**\n** STEP: {0}\n**\n'.format(step_name))
abaqus_format = [
'\n** -------------------------------------------------------------\n',
'**\n** STEP: {0}\n**\n'.format(step_name),
]

nlgeom = modules['step_options']['nlgeom']
increment = modules['step_options']['inc']
abaqus_format.append('*Step, name={0}, nlgeom={1}, inc={2}\n'
.format(step_name, nlgeom, increment))
for module_name, module_items in modules.items():
if module_name == 'step_options':
continue
Copy link
Author

Choose a reason for hiding this comment

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

Function Procedure.__format refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Extract guard clause from elif block (guard)
  • Merge append into list declaration (merge-list-append)

ax = parsed_options['ax'] if parsed_options['ax'] else plt.figure().add_subplot()
ax = parsed_options['ax'] or plt.figure().add_subplot()
Copy link
Author

Choose a reason for hiding this comment

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

Function plot_grain_characteristic refactored with the following changes:

  • Simplify if expression by using or (or-if-exp-identity)

if edge_sum > 0:
orientation = 'cw'
else:
orientation = 'ccw'
return orientation
return 'cw' if edge_sum > 0 else 'ccw'
Copy link
Author

Choose a reason for hiding this comment

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

Function polygon_orientation refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -323 to +319
for vertex in range(n_branch - 1):
for _ in range(n_branch - 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 branches2boundary refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

Comment on lines -1158 to +1153
ax = method_options['ax'] if method_options['ax'] else plt.figure().add_subplot()
ax = method_options['ax'] or plt.figure().add_subplot()
Copy link
Author

Choose a reason for hiding this comment

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

Function Polygon.plot refactored with the following changes:

  • Simplify if expression by using or (or-if-exp-identity)

Comment on lines -100 to +104
node_groups = {}
for group_name in group_names:
node_groups[group_name] = mesh.getGroupArr(1, group_name).toNumPyArray()
node_groups = {
group_name: mesh.getGroupArr(1, group_name).toNumPyArray()
for group_name in group_names
}

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

  • Convert for loop into dictionary comprehension (dict-comprehension)

Comment on lines -40 to -43
repr_OOF = "QuadSkeleton(left_right_periodicity={1}, " \
return "QuadSkeleton(left_right_periodicity={1}, " \
"top_bottom_periodicity={2})".format(self.leftright_periodicity,
self.topbottom_periodicity)
return repr_OOF
Copy link
Author

Choose a reason for hiding this comment

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

Function QuadSkeletonGeometry.__repr__ refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines -54 to -58
repr_OOF = "TriSkeleton(arrangement='{0}', left_right_periodicity={1}, " \
return "TriSkeleton(arrangement='{0}', left_right_periodicity={1}, " \
"top_bottom_periodicity={2})".format(self.arrangement,
self.leftright_periodicity,
self.topbottom_periodicity)
return repr_OOF
Copy link
Author

Choose a reason for hiding this comment

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

Function TriSkeletonGeometry.__repr__ refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

if args:
image = args[0]
else:
image = self.original_image
image = args[0] if args else self.original_image
Copy link
Author

Choose a reason for hiding this comment

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

Function Segmentation.initial_segmentation refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Nov 1, 2020

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 3.53 ⭐ 3.52 ⭐ -0.01 👍
Method Length 69.62 🙂 69.26 🙂 -0.36 👍
Working memory 8.04 🙂 8.04 🙂 0.00
Quality 76.23% 76.30% 0.07% 👍
Other metrics Before After Change
Lines 4414 4410 -4
Changed files Quality Before Quality After Quality Change
grains/abaqus.py 71.73% 🙂 71.71% 🙂 -0.02% 👎
grains/analysis.py 69.46% 🙂 69.48% 🙂 0.02% 👍
grains/cad.py 73.64% 🙂 73.74% 🙂 0.10% 👍
grains/geometry.py 76.78% ⭐ 76.78% ⭐ 0.00%
grains/med.py 76.66% ⭐ 76.49% ⭐ -0.17% 👎
grains/meshing.py 85.53% ⭐ 85.78% ⭐ 0.25% 👍
grains/segmentation.py 77.02% ⭐ 77.16% ⭐ 0.14% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
grains/abaqus.py Procedure.read 44 ⛔ 636 ⛔ 27 ⛔ 5.97% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
grains/geometry.py TriMesh.plot 19 😞 292 ⛔ 16 ⛔ 27.31% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
grains/abaqus.py Material.read 16 🙂 233 ⛔ 20 ⛔ 29.05% 😞 Try splitting into smaller methods. Extract out complex expressions
grains/cad.py branches2boundary 20 😞 202 😞 14 😞 33.74% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
grains/meshing.py OOF2.materials2groups 24 😞 131 😞 12 😞 40.85% 😞 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!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

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.

None yet

0 participants