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 #1

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 May 5, 2022

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^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from jakubjezek001 May 5, 2022 19:07
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -23 to 35
module_name = folder_name + "." + filename
module_name = f"{folder_name}.{filename}"

nodes.extend(
obj
for name, obj in inspect.getmembers(
importlib.import_module(module_name)
)
if inspect.isclass(obj)
and filename in str(obj)
and len(inspect.getmembers(obj)) > 0
and obj.__identifier__ != '__None'
)

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

Comment on lines +76 to +85

try:
from Qt import QtWidgets, QtGui, QtCore, QtCompat, QtOpenGL
except ImportError as ie:
from .vendor.Qt import __version__ as qtpy_ver
from .vendor.Qt import QtWidgets, QtGui, QtCore, QtCompat ,QtOpenGL
print('NodeGraphQt: Can\'t import "Qt.py" module falling back on '
'"NodeGraphQt.vendor.Qt ({})"'.format(qtpy_ver))
print(
f"""NodeGraphQt: Can't import "Qt.py" module falling back on "NodeGraphQt.vendor.Qt ({qtpy_ver})\""""
)

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

Comment on lines -20 to +22
self.setText('renamed "{}" to "{}"'.format(node.name(), value))
self.setText(f'renamed "{node.name()}" to "{value}"')
else:
self.setText('property "{}:{}"'.format(node.name(), name))
self.setText(f'property "{node.name()}:{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 PropertyChangedCmd.__init__ refactored with the following changes:

Comment on lines -40 to +45
if hasattr(view, 'widgets') and name in view.widgets.keys():
# check if previous value is identical to current value,
# prevent signals from causing a infinite loop.
if view.widgets[name].value != value:
view.widgets[name].value = value
if (
hasattr(view, 'widgets')
and name in view.widgets.keys()
and view.widgets[name].value != value
):
view.widgets[name].value = value
Copy link
Author

Choose a reason for hiding this comment

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

Function PropertyChangedCmd.set_node_prop refactored with the following changes:

This removes the following comments ( why? ):

# prevent signals from causing a infinite loop.
# check if previous value is identical to current value,

print('can\'t find node type {}'.format(node_type))
print(f"can't find node type {node_type}")
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeFactory.create_node_instance refactored with the following changes:

Comment on lines -1440 to +1423
serial_str = json.dumps(serial_data)
if serial_str:
if serial_str := json.dumps(serial_data):
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeGraph.copy_nodes refactored with the following changes:

Comment on lines -1520 to +1502
text = '{} ({}) nodes'.format(text, len(nodes))
text = f'{text} ({len(nodes)}) nodes'
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeGraph.disable_nodes refactored with the following changes:

return '<{}("{}") object at {}>'.format(
self.__class__.__name__, self.name(), hex(id(self)))
return f'<{self.__class__.__name__}("{self.name()}") object at {hex(id(self))}>'
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeGraphMenu.__repr__ refactored with the following changes:

Comment on lines -64 to +63
menu = self.qmenu.get_menu(name)
if menu:
if menu := self.qmenu.get_menu(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 NodeGraphMenu.get_menu refactored with the following changes:

Comment on lines -92 to +93
if not action.menu():
if not action.isSeparator():
actions.append(action)
else:
if action.menu():
actions += get_actions(action.menu())
elif not action.isSeparator():
actions.append(action)
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeGraphMenu.all_commands.get_actions refactored with the following changes:

Comment on lines -223 to +220
return '<{}("{}") object at {}>'.format(
self.__class__.__name__, self.name(), hex(id(self)))
return f'<{self.__class__.__name__}("{self.name()}") object at {hex(id(self))}>'
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeGraphCommand.__repr__ refactored with the following changes:

return '<{}(\'{}\') object at {}>'.format(
self.__class__.__name__, self.name, hex(id(self)))
return f"<{self.__class__.__name__}('{self.name}') object at {hex(id(self))}>"
Copy link
Author

Choose a reason for hiding this comment

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

Function PortModel.__repr__ refactored with the following changes:

Comment on lines -101 to +100
return '<{}(\'{}\') object at {}>'.format(
self.__class__.__name__, self.name, self.id)
return f"<{self.__class__.__name__}('{self.name}') object at {self.id}>"
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeModel.__repr__ refactored with the following changes:

raise NodePropertyError(
'"{}" reserved for default property.'.format(name))
raise NodePropertyError(f'"{name}" reserved for default property.')
if name in self._custom_prop.keys():
raise NodePropertyError(
'"{}" property already exists.'.format(name))
raise NodePropertyError(f'"{name}" property already exists.')
Copy link
Author

Choose a reason for hiding this comment

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

Function NodeModel.add_property refactored with the following changes:

Comment on lines -180 to +176
attrs = self._TEMP_property_attrs.get(name)
if attrs:
if attrs := self._TEMP_property_attrs.get(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 NodeModel.get_tab_name refactored with the following changes:

return '<{}("{}") object at {}>'.format(
port, self.name(), hex(id(self)))
return f'<{port}("{self.name()}") object at {hex(id(self))}>'
Copy link
Author

Choose a reason for hiding this comment

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

Function Port.__repr__ refactored with the following changes:

Comment on lines -116 to +115
undo_stack.beginMacro('{} port {}'.format(label, self.name()))
undo_stack.beginMacro(f'{label} port {self.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 Port.set_visible refactored with the following changes:

Comment on lines -201 to +200
raise PortError(
'Can\'t connect port because "{}" is locked.'.format(name))
raise PortError(f"""Can't connect port because "{name}" is locked.""")
Copy link
Author

Choose a reason for hiding this comment

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

Function Port.connect_to refactored with the following changes:

Comment on lines -258 to +259
raise PortError(
'Can\'t disconnect port because "{}" is locked.'.format(name))
raise PortError(f"""Can't disconnect port because "{name}" is locked.""")
Copy link
Author

Choose a reason for hiding this comment

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

Function Port.disconnect_from refactored with the following changes:

file_path = viewer.load_dialog(current)
if file_path:
if file_path := viewer.load_dialog(current):
Copy link
Author

Choose a reason for hiding this comment

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

Function _open_session refactored with the following changes:

Comment on lines -163 to +162
file_path = viewer.load_dialog(current)
if file_path:
if file_path := viewer.load_dialog(current):
Copy link
Author

Choose a reason for hiding this comment

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

Function _import_session refactored with the following changes:

Comment on lines -175 to +173
current = graph.current_session()
if current:
if current := graph.current_session():
Copy link
Author

Choose a reason for hiding this comment

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

Function _save_session refactored with the following changes:

Comment on lines -194 to +191
file_path = viewer.save_dialog(current)
if file_path:
if file_path := viewer.save_dialog(current):
Copy link
Author

Choose a reason for hiding this comment

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

Function _save_session_as refactored with the following changes:

Comment on lines -262 to +258
nodes = graph.selected_nodes()
if nodes:
if nodes := graph.selected_nodes():
Copy link
Author

Choose a reason for hiding this comment

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

Function _jump_in refactored with the following changes:

Comment on lines -268 to +263
node = graph.get_node_space()
if node:
if node := graph.get_node_space():
Copy link
Author

Choose a reason for hiding this comment

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

Function _jump_out refactored with the following changes:

Comment on lines -206 to +205
props.update(self._properties)
props |= self._properties
Copy link
Author

Choose a reason for hiding this comment

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

Function AbstractNodeItem.properties refactored with the following changes:

viewer = self.viewer()
if viewer:
if viewer := self.viewer():
Copy link
Author

Choose a reason for hiding this comment

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

Function BackdropNodeItem.mouseDoubleClickEvent refactored with the following changes:

Comment on lines -183 to +182
sel_color = [x for x in NODE_SEL_COLOR]
sel_color = list(NODE_SEL_COLOR)
Copy link
Author

Choose a reason for hiding this comment

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

Function BackdropNodeItem.paint refactored with the following changes:

Comment on lines -214 to +213
if item == self or item == self._sizer:
if item in [self, self._sizer]:
Copy link
Author

Choose a reason for hiding this comment

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

Function BackdropNodeItem.get_nodes refactored with the following changes:

Comment on lines -221 to +220
nodes = nodes or self.get_nodes(True)
if nodes:
if nodes := nodes or self.get_nodes(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 BackdropNodeItem.auto_resize refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented May 5, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 7.00 ⭐ 6.53 ⭐ -0.47 👍
Method Length 42.16 ⭐ 42.10 ⭐ -0.06 👍
Working memory 7.05 🙂 7.12 🙂 0.07 👎
Quality 72.41% 🙂 72.56% 🙂 0.15% 👍
Other metrics Before After Change
Lines 13892 13788 -104
Changed files Quality Before Quality After Quality Change
example_auto_nodes.py 67.27% 🙂 71.77% 🙂 4.50% 👍
NodeGraphQt/init.py 73.81% 🙂 73.67% 🙂 -0.14% 👎
NodeGraphQt/base/commands.py 82.90% ⭐ 82.80% ⭐ -0.10% 👎
NodeGraphQt/base/factory.py 83.82% ⭐ 83.58% ⭐ -0.24% 👎
NodeGraphQt/base/graph.py 69.53% 🙂 69.29% 🙂 -0.24% 👎
NodeGraphQt/base/menu.py 77.22% ⭐ 77.06% ⭐ -0.16% 👎
NodeGraphQt/base/model.py 66.02% 🙂 66.13% 🙂 0.11% 👍
NodeGraphQt/base/node.py 84.21% ⭐ 84.05% ⭐ -0.16% 👎
NodeGraphQt/base/port.py 71.47% 🙂 71.99% 🙂 0.52% 👍
NodeGraphQt/base/utils.py 68.84% 🙂 68.70% 🙂 -0.14% 👎
NodeGraphQt/qgraphics/node_abstract.py 94.40% ⭐ 94.18% ⭐ -0.22% 👎
NodeGraphQt/qgraphics/node_backdrop.py 74.54% 🙂 74.08% 🙂 -0.46% 👎
NodeGraphQt/qgraphics/node_base.py 66.12% 🙂 66.11% 🙂 -0.01% 👎
NodeGraphQt/qgraphics/pipe.py 59.32% 🙂 59.24% 🙂 -0.08% 👎
NodeGraphQt/qgraphics/port.py 78.33% ⭐ 77.86% ⭐ -0.47% 👎
NodeGraphQt/vendor/Qt.py 60.68% 🙂 60.63% 🙂 -0.05% 👎
NodeGraphQt/widgets/actions.py 87.35% ⭐ 87.77% ⭐ 0.42% 👍
NodeGraphQt/widgets/dialogs.py 84.25% ⭐ 84.70% ⭐ 0.45% 👍
NodeGraphQt/widgets/node_publish_widget.py 61.29% 🙂 61.26% 🙂 -0.03% 👎
NodeGraphQt/widgets/node_tree.py 76.02% ⭐ 75.66% ⭐ -0.36% 👎
NodeGraphQt/widgets/node_widgets.py 87.03% ⭐ 86.90% ⭐ -0.13% 👎
NodeGraphQt/widgets/properties.py 81.94% ⭐ 81.94% ⭐ 0.00%
NodeGraphQt/widgets/properties_bin.py 76.86% ⭐ 76.38% ⭐ -0.48% 👎
NodeGraphQt/widgets/scene.py 74.87% 🙂 74.74% 🙂 -0.13% 👎
NodeGraphQt/widgets/stylesheet.py 85.42% ⭐ 83.09% ⭐ -2.33% 👎
NodeGraphQt/widgets/tab_search.py 72.42% 🙂 72.22% 🙂 -0.20% 👎
NodeGraphQt/widgets/viewer.py 58.24% 🙂 59.00% 🙂 0.76% 👍
docs/conf.py 63.82% 🙂 61.47% 🙂 -2.35% 👎
docs/_themes/sphinx_rtd_theme/init.py 89.93% ⭐ 89.50% ⭐ -0.43% 👎
example_auto_nodes/data_node.py 84.98% ⭐ 84.79% ⭐ -0.19% 👎
example_auto_nodes/input_nodes.py 92.60% ⭐ 92.57% ⭐ -0.03% 👎
example_auto_nodes/logic_nodes.py 88.75% ⭐ 88.78% ⭐ 0.03% 👍
example_auto_nodes/module_nodes.py 87.91% ⭐ 87.12% ⭐ -0.79% 👎
example_auto_nodes/subgraph_nodes.py 79.61% ⭐ 79.51% ⭐ -0.10% 👎
example_auto_nodes/node_base/auto_node.py 82.05% ⭐ 82.32% ⭐ 0.27% 👍
example_auto_nodes/node_base/module_node.py 75.47% ⭐ 75.23% ⭐ -0.24% 👎
example_auto_nodes/node_base/subgraph_node.py 65.63% 🙂 68.28% 🙂 2.65% 👍
example_auto_nodes/node_base/utils.py 87.83% ⭐ 87.76% ⭐ -0.07% 👎
example_nodes/init.py 47.84% 😞 51.28% 🙂 3.44% 👍
example_nodes/input_nodes.py 87.97% ⭐ 88.00% ⭐ 0.03% 👍
example_nodes/logic_nodes.py 85.29% ⭐ 85.36% ⭐ 0.07% 👍
example_nodes/math_node.py 76.27% ⭐ 76.08% ⭐ -0.19% 👎
example_nodes/util_nodes.py 69.57% 🙂 69.93% 🙂 0.36% 👍
example_nodes/viewer_nodes.py 88.86% ⭐ 87.41% ⭐ -1.45% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
NodeGraphQt/widgets/viewer.py NodeViewer.mouseMoveEvent 67 ⛔ 349 ⛔ 16 ⛔ 10.75% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
NodeGraphQt/base/graph.py NodeGraph._deserialize 45 ⛔ 361 ⛔ 18 ⛔ 11.68% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
NodeGraphQt/widgets/properties.py NodePropWidget._read_node 36 ⛔ 314 ⛔ 16 ⛔ 17.34% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
example_auto_nodes/node_base/subgraph_node.py SubGraphNode.create_from_nodes 35 ⛔ 386 ⛔ 13 😞 19.99% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
NodeGraphQt/base/graph.py NodeGraph.create_node 26 😞 294 ⛔ 19 ⛔ 20.04% ⛔ 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!

Help us improve this quality report!

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