diff --git a/spyder_line_profiler/spyder/api.py b/spyder_line_profiler/spyder/api.py deleted file mode 100644 index 2e3281f..0000000 --- a/spyder_line_profiler/spyder/api.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- coding: utf-8 -*- -# ---------------------------------------------------------------------------- -# Copyright © 2021, Spyder Line Profiler contributors -# -# Licensed under the terms of the MIT license -# ---------------------------------------------------------------------------- -""" -Spyder Line Profiler 5 API. -""" diff --git a/spyder_line_profiler/spyder/confpage.py b/spyder_line_profiler/spyder/confpage.py index a609cd9..4ca7d29 100644 --- a/spyder_line_profiler/spyder/confpage.py +++ b/spyder_line_profiler/spyder/confpage.py @@ -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") diff --git a/spyder_line_profiler/spyder/plugin.py b/spyder_line_profiler/spyder/plugin.py index 970d1e2..a84072f 100644 --- a/spyder_line_profiler/spyder/plugin.py +++ b/spyder_line_profiler/spyder/plugin.py @@ -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): @@ -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 @@ -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') @@ -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 @@ -103,7 +100,6 @@ def check_compatibility(self): def on_close(self, cancellable=True): return True - # --- Public API # ------------------------------------------------------------------------ def update_pythonpath(self): @@ -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) @@ -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) diff --git a/spyder_line_profiler/spyder/widgets.py b/spyder_line_profiler/spyder/widgets.py index dd28da0..1717e68 100644 --- a/spyder_line_profiler/spyder/widgets.py +++ b/spyder_line_profiler/spyder/widgets.py @@ -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 @@ -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) @@ -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 @@ -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) @@ -189,7 +195,6 @@ def __init__(self, name=None, plugin=None, parent=None): # --- PluginMainWidget API # ------------------------------------------------------------------------ - def get_title(self): return _("Line Profiler") @@ -270,6 +275,7 @@ def setup(self): toolbar=toolbar, section=SpyderLineProfilerWidgetMainToolbarSections.Main, ) + # Secondary Toolbar secondary_toolbar = self.create_toolbar( SpyderLineProfilerWidgetToolbars.Information) @@ -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, @@ -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}')) @@ -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): diff --git a/spyder_line_profiler/tests/test_lineprofiler.py b/spyder_line_profiler/tests/test_lineprofiler.py index 3345991..104a08f 100644 --- a/spyder_line_profiler/tests/test_lineprofiler.py +++ b/spyder_line_profiler/tests/test_lineprofiler.py @@ -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: @@ -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."""