Skip to content

Commit

Permalink
squash rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
skjerns committed May 4, 2022
1 parent f4df955 commit d8108b0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 53 deletions.
9 changes: 0 additions & 9 deletions spyder_line_profiler/spyder/api.py

This file was deleted.

7 changes: 6 additions & 1 deletion spyder_line_profiler/spyder/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
#
# Licensed under the terms of the MIT license
# ----------------------------------------------------------------------------

"""
Spyder Line Profiler 5 Preferences Page.
"""

# Third party imports
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QGroupBox, QLabel, QVBoxLayout

from spyder.api.preferences import PluginConfigPage
from spyder.api.translations import get_translation

# Local imports
from .widgets import SpyderLineProfilerWidget

# Localization
_ = get_translation("spyder_line_profiler.spyder")


Expand Down
39 changes: 17 additions & 22 deletions spyder_line_profiler/spyder/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
#
# Licensed under the terms of the MIT license
# ----------------------------------------------------------------------------

"""
Spyder Line Profiler 5 Plugin.
"""

# Third-party imports
from qtpy.QtCore import Signal
from qtpy.QtGui import QIcon

# Spyder imports
from spyder.api.plugins import Plugins, SpyderDockablePlugin
from spyder.api.translations import get_translation
from spyder.api.plugin_registration.decorators import on_plugin_available
from spyder.api.plugin_registration.decorators import on_plugin_teardown
from qtpy.QtCore import Signal
from spyder.plugins.mainmenu.api import ApplicationMenus

# Local imports
from spyder.plugins.mainmenu.api import ApplicationMenus
from spyder_line_profiler.spyder.confpage import SpyderLineProfilerConfigPage
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidgetActions
from spyder_line_profiler.spyder.widgets import is_lineprofiler_installed

# Localization
_ = get_translation("spyder_line_profiler.spyder")



class SpyderLineProfilerActions:
# Triggers
Run = 'run_action_menu'
Run = 'run_profiler_action'


class SpyderLineProfiler(SpyderDockablePlugin):
Expand All @@ -40,7 +40,7 @@ class SpyderLineProfiler(SpyderDockablePlugin):
"""

NAME = "spyder_line_profiler"
REQUIRES = [Plugins.Editor, Plugins.Help]
REQUIRES = [Plugins.Editor]
OPTIONAL = [Plugins.MainMenu]
TABIFY = [Plugins.Help]
WIDGET_CLASS = SpyderLineProfilerWidget
Expand All @@ -58,7 +58,7 @@ def get_name():
return _("Line Profiler")

def get_description(self):
return _("Line profiler display for Spyder 5")
return _("Line profiler display for Spyder")

def get_icon(self):
return QIcon('./data/images/spyder.line_profiler.png')
Expand All @@ -68,33 +68,30 @@ def on_initialize(self):
self.widget.sig_finished.connect(self.sig_finished)

run_action = self.create_action(
SpyderLineProfilerActions.Run,
text=_("Run line profiler"),
tip=_("Run line profiler"),
icon=self.get_icon(),
triggered=self.run_lineprofiler,
register_shortcut=True,
)
SpyderLineProfilerActions.Run,
text=_("Run line profiler"),
tip=_("Run line profiler"),
icon=self.get_icon(),
triggered=self.run_lineprofiler,
register_shortcut=True,
)
run_action.setEnabled(is_lineprofiler_installed())


@on_plugin_available(plugin=Plugins.MainMenu)
def on_main_menu_available(self):
mainmenu = self.get_plugin(Plugins.MainMenu)
start_action = self.get_action(SpyderLineProfilerActions.Run)
run_action = self.get_action(SpyderLineProfilerActions.Run)
mainmenu.add_item_to_application_menu(
start_action, menu_id=ApplicationMenus.Run)
run_action, menu_id=ApplicationMenus.Run)

@on_plugin_teardown(plugin=Plugins.MainMenu)
def on_main_menu_teardown(self):
mainmenu = self.get_plugin(Plugins.MainMenu)

mainmenu.remove_item_from_application_menu(
SpyderLineProfilerActions.ProfileCurrentFile,
menu_id=ApplicationMenus.Run
)


def check_compatibility(self):
valid = True
message = "" # Note: Remember to use _("") to localize the string
Expand All @@ -103,7 +100,6 @@ def check_compatibility(self):
def on_close(self, cancellable=True):
return True


# --- Public API
# ------------------------------------------------------------------------
def update_pythonpath(self):
Expand All @@ -116,7 +112,6 @@ def update_pythonpath(self):
"""
self.widget.spyder_pythonpath = self.main.get_spyder_pythonpath()


def run_lineprofiler(self):
"""Run line profiler."""
editor = self.get_plugin(Plugins.Editor)
Expand All @@ -127,7 +122,7 @@ def run_lineprofiler(self):
self.analyze(self.main.editor.get_current_filename())

def analyze(self, filename):
"""Reimplement analyze method."""
"""Analyze a file."""
if self.dockwidget:
self.switch_to_plugin()
self.widget.analyze(filename=filename)
35 changes: 18 additions & 17 deletions spyder_line_profiler/spyder/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Licensed under the terms of the MIT license
# ----------------------------------------------------------------------------
"""
Spyder Line Profiler 5 Main Widget.
Spyder Line Profiler Main Widget.
"""
# Standard library imports
from __future__ import with_statement
Expand Down Expand Up @@ -63,7 +63,7 @@

def is_lineprofiler_installed():
"""
Checks if the program and the library for line_profiler is installed.
Check if the program and the library for line_profiler is installed.
"""
return (programs.is_module_installed('line_profiler')
and programs.find_program('kernprof') is not None)
Expand Down Expand Up @@ -111,26 +111,32 @@ class SpyderLineProfilerWidgetActions:
SaveData = 'save_data_action'
ShowOutput = 'show_output_action'
Stop = 'stop_action'



class SpyderLineProfilerWidgetMainToolbarSections:
Main = 'main_section'
ExpandCollaps = 'expand_collaps_section'
ShowOutput = 'show_output_section'



class SpyderLineProfilerWidgetToolbars:
Information = 'information_toolbar'



class SpyderLineProfilerWidgetMainToolbarItems:
FileCombo = 'file_combo'



class SpyderLineProfilerWidgetInformationToolbarSections:
Main = 'main_section'



class SpyderLineProfilerWidgetInformationToolbarItems:
Stretcher1 = 'stretcher_1'
Stretcher2 = 'stretcher_2'
DateLabel = 'date_label'



class SpyderLineProfilerWidget(PluginMainWidget):

# PluginMainWidget class constants
Expand Down Expand Up @@ -173,11 +179,11 @@ def __init__(self, name=None, plugin=None, parent=None):
self.filecombo = PythonModulesComboBox(
self, id_= SpyderLineProfilerWidgetMainToolbarItems.FileCombo)
self.datatree = LineProfilerDataTree(self)
self.datelabel = QLabel()
self.datelabel = QLabel(self)
self.datelabel.ID = SpyderLineProfilerWidgetInformationToolbarItems.DateLabel
self.datelabel.setText(_('Please select a file to profile, with '
'added @profile decorators for functions'))
self.timer = QTimer()
self.timer = QTimer(self)

layout = QVBoxLayout()
layout.addWidget(self.datatree)
Expand All @@ -189,7 +195,6 @@ def __init__(self, name=None, plugin=None, parent=None):

# --- PluginMainWidget API
# ------------------------------------------------------------------------

def get_title(self):
return _("Line Profiler")

Expand Down Expand Up @@ -270,6 +275,7 @@ def setup(self):
toolbar=toolbar,
section=SpyderLineProfilerWidgetMainToolbarSections.Main,
)

# Secondary Toolbar
secondary_toolbar = self.create_toolbar(
SpyderLineProfilerWidgetToolbars.Information)
Expand All @@ -287,8 +293,6 @@ def setup(self):
toolbar=secondary_toolbar,
section=SpyderLineProfilerWidgetInformationToolbarSections.Main,
)



if not is_lineprofiler_installed():
for widget in (self.datatree, self.filecombo, self.log_action,
Expand Down Expand Up @@ -482,7 +486,7 @@ def finished(self):
self.timer.stop()
self.set_running_state(False)
self.output = self.error_output + self.output
if not self.output=='aborted':
if not self.output == 'aborted':
elapsed = str(datetime.now() - self.started_time).split(".")[0]
self.show_data(justanalyzed=True)
self.datelabel.setText(_(f'Profiling finished after {elapsed}'))
Expand Down Expand Up @@ -552,15 +556,12 @@ def save_data(self):

self.datelabel.setText(_(f"Saved results to {filename}"))


def update_actions(self):
pass

@on_conf_change
def on_section_conf_change(self, section):
pass




class LineProfilerDataTree(QTreeWidget):
Expand Down
4 changes: 0 additions & 4 deletions spyder_line_profiler/tests/test_lineprofiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
MAIN_APP = qapplication()

# Local imports
import spyder
import spyder_line_profiler
from spyder_line_profiler.spyder.widgets import SpyderLineProfilerWidget
from spyder_line_profiler.spyder.widgets import PythonModulesComboBox


try:
Expand All @@ -39,7 +36,6 @@ def foo():
xs = xs + ['x']
foo()"""



def test_profile_and_display_results(qtbot, tmpdir, monkeypatch):
"""Run profiler on simple script and check that results are okay."""
Expand Down

0 comments on commit d8108b0

Please sign in to comment.