From 23b16efb9121d56aaf8b324608ee5f0b9e84e743 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Wed, 18 Sep 2019 19:19:38 +0100 Subject: [PATCH 1/5] Compatibility changes for Spyder 4 --- setup.py | 2 +- spyder_line_profiler/lineprofiler.py | 16 ++++++---------- spyder_line_profiler/widgets/lineprofiler.py | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/setup.py b/setup.py index 189b83f..eb626ec 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ def get_package_data(name, extlist): # Requirements -REQUIREMENTS = ['line_profiler', 'spyder>=3'] +REQUIREMENTS = ['line_profiler', 'spyder>=4'] EXTLIST = ['.jpg', '.png', '.json', '.mo', '.ini'] LIBNAME = 'spyder_line_profiler' diff --git a/spyder_line_profiler/lineprofiler.py b/spyder_line_profiler/lineprofiler.py index ad98a66..681a217 100644 --- a/spyder_line_profiler/lineprofiler.py +++ b/spyder_line_profiler/lineprofiler.py @@ -14,9 +14,9 @@ from spyder.utils.qthelpers import qapplication MAIN_APP = qapplication() +from spyder.api.plugins import SpyderPluginWidget +from spyder.api.preferences import PluginConfigPage from spyder.config.base import get_translation -from spyder.plugins import SpyderPluginWidget -from spyder.plugins.configdialog import PluginConfigPage from spyder.utils import icon_manager as ima from spyder.utils.qthelpers import create_action @@ -86,9 +86,6 @@ def __init__(self, parent=None): layout.addWidget(self.widget) self.setLayout(layout) - # Initialize plugin - self.initialize_plugin() - def update_pythonpath(self): """ Update the PYTHONPATH used when running the line_profiler. @@ -127,13 +124,14 @@ def on_first_registration(self): def register_plugin(self): """Register plugin in Spyder's main window.""" + super(LineProfiler, self).register_plugin() + # Spyder PYTHONPATH self.update_pythonpath() self.main.sig_pythonpath_changed.connect(self.update_pythonpath) self.edit_goto.connect(self.main.editor.load) self.widget.redirect_stdio.connect(self.main.redirect_internalshell_stdio) - self.main.add_dockwidget(self) lineprofiler_act = create_action(self, _("Profile line by line"), icon=self.get_plugin_icon(), @@ -163,10 +161,8 @@ def run_lineprofiler(self): def analyze(self, filename): """Reimplement analyze method.""" - if self.dockwidget and not self.ismaximized: - self.dockwidget.setVisible(True) - self.dockwidget.setFocus() - self.dockwidget.raise_() + if self.dockwidget: + self.switch_to_plugin() self.widget.analyze( filename=filename, use_colors=self.get_option('use_colors', True)) diff --git a/spyder_line_profiler/widgets/lineprofiler.py b/spyder_line_profiler/widgets/lineprofiler.py index 8954945..9d4a67a 100644 --- a/spyder_line_profiler/widgets/lineprofiler.py +++ b/spyder_line_profiler/widgets/lineprofiler.py @@ -30,11 +30,11 @@ # Local imports from spyder.config.base import get_conf_path, get_translation +from spyder.plugins.variableexplorer.widgets.texteditor import TextEditor from spyder.utils import programs +from spyder.utils.misc import add_pathlist_to_PYTHONPATH from spyder.utils.qthelpers import create_toolbutton, get_icon from spyder.widgets.comboboxes import PythonModulesComboBox -from spyder.utils.misc import add_pathlist_to_PYTHONPATH -from spyder.widgets.variableexplorer.texteditor import TextEditor try: from spyder.py3compat import to_text_string, getcwd, pickle @@ -88,7 +88,7 @@ class LineProfilerWidget(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) # Need running QApplication before importing runconfig - from spyder.plugins import runconfig + from spyder.preferences import runconfig self.runconfig = runconfig self.spyder_pythonpath = None From 4dcb7cfaa9db69b04cbcd0d5d2f0233e5e72d715 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Thu, 19 Sep 2019 09:46:34 +0100 Subject: [PATCH 2/5] Update CI scripts and unify with Spyder scripts --- .circleci/config.yml | 12 ++--- .circleci/install.sh | 24 --------- .travis.yml | 30 +++++++++++ appveyor.yml | 52 ------------------- .../circle}/coverage.sh | 0 continuous_integration/circle/install.sh | 35 +++++++++++++ .../circle}/run_tests.sh | 0 requirements/conda.txt | 2 + requirements/tests.txt | 4 ++ 9 files changed, 74 insertions(+), 85 deletions(-) delete mode 100755 .circleci/install.sh create mode 100644 .travis.yml delete mode 100644 appveyor.yml rename {.circleci => continuous_integration/circle}/coverage.sh (100%) create mode 100755 continuous_integration/circle/install.sh rename {.circleci => continuous_integration/circle}/run_tests.sh (100%) create mode 100644 requirements/conda.txt create mode 100644 requirements/tests.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index c1c8ad2..308e86f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,11 +12,11 @@ main: &main sudo apt-get -qq update sudo apt-get install -q libegl1-mesa - run: - command: ./.circleci/install.sh + command: bash ./continuous_integration/circle/install.sh - run: - command: ./.circleci/run_tests.sh + command: bash ./continuous_integration/circle/run_tests.sh - run: - command: ./.circleci/coverage.sh + command: bash ./continuous_integration/circle/coverage.sh jobs: python2.7: @@ -24,11 +24,6 @@ jobs: environment: - PYTHON_VERSION: "2.7" - python3.5: - <<: *main - environment: - - PYTHON_VERSION: "3.5" - python3.6: <<: *main environment: @@ -44,6 +39,5 @@ workflows: build_and_test: jobs: - python2.7 - - python3.5 - python3.6 - python3.7 diff --git a/.circleci/install.sh b/.circleci/install.sh deleted file mode 100755 index 5d120f3..0000000 --- a/.circleci/install.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -export TRAVIS_OS_NAME="linux" -export CONDA_DEPENDENCIES_FLAGS="--quiet" -export CONDA_DEPENDENCIES="line_profiler mock pytest spyder pytest-cov" -export CONDA_DEPENDENCIES_FLAGS="-q" -export PIP_DEPENDENCIES="coveralls pytest-qt" - -echo -e "PYTHON = $PYTHON_VERSION \n============" -git clone git://github.com/astropy/ci-helpers.git > /dev/null -source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh -source $HOME/miniconda/etc/profile.d/conda.sh -conda activate test - -# Install the package in develop mode -pip install -e . - -# Used by qthelpers to close widgets after a defined time -export TEST_CI="True" -export TEST_CI_APP="True" - -# Run Spyder to get it's config files -spyder --reset -spyder diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..56df305 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +# https://travis-ci.org/spyder-ide/spyder-line-profiler + +language: generic +dist: xenial +services: + - xvfb + +matrix: + fast_finish: true + include: + - env: PYTHON_VERSION=2.7 USE_CONDA=yes + - env: PYTHON_VERSION=3.6 USE_CONDA=yes + - env: PYTHON_VERSION=3.7 USE_CONDA=yes + +before_install: + # Avoid annoying focus problems when running tests + # See discussion in e.g. https://github.com/spyder-ide/spyder/pull/6132 + - sudo apt-get -qq update + - sudo apt-get install -y matchbox-window-manager xterm libxkbcommon-x11-0 + - matchbox-window-manager& + - sleep 5 + +install: + - ./continuous_integration/circle/install.sh + +script: + - ./continuous_integration/circle/run_tests.sh + +after_success: + - ./continuous_integration/circle/coverage.sh diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8c92f9b..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,52 +0,0 @@ -# https://ci.appveyor.com/project/goanpeca/spyder-unittest - -matrix: - fast_finish: true - -branches: - only: - - master - -environment: - global: - # Used by qthelpers to close widgets after a defined time - TEST_CI: True - TEST_CI_APP: True - # Environment variables used by astropy helpers - PYTHON: "C:\\conda" - CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci-helpers\\appveyor\\windows_sdk.cmd" - PYTHON_ARCH: "64" - CONDA_DEPENDENCIES: "line_profiler mock pytest spyder" - PIP_DEPENDENCIES: "pytest-qt" - - matrix: - - PYTHON_VERSION: "3.6" - - PYTHON_VERSION: "3.5" - -platform: - -x64 - -install: - # If there is a newer build queued for the same PR, cancel this one. - # The AppVeyor 'rollout builds' option is supposed to serve the same - # purpose but it is problematic because it tends to cancel builds pushed - # directly to master instead of just PR builds (or the converse). - # credits: JuliaLang developers. - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } - # Astropy ci-helpers. See https://github.com/astropy/ci-helpers - - "git clone git://github.com/astropy/ci-helpers.git" - - "powershell ci-helpers/appveyor/install-miniconda.ps1" - - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - - "activate test" - - "pip install -e ." - - "spyder --reset" - - "spyder" - -# Not a .NET project, we build in the install step instead -build: false - -test_script: - - pytest -x -vv spyder_line_profiler diff --git a/.circleci/coverage.sh b/continuous_integration/circle/coverage.sh similarity index 100% rename from .circleci/coverage.sh rename to continuous_integration/circle/coverage.sh diff --git a/continuous_integration/circle/install.sh b/continuous_integration/circle/install.sh new file mode 100755 index 0000000..02121a4 --- /dev/null +++ b/continuous_integration/circle/install.sh @@ -0,0 +1,35 @@ +#!/bin/bash -ex + +# -- Install Miniconda +MINICONDA=Miniconda3-latest-Linux-x86_64.sh +wget https://repo.continuum.io/miniconda/$MINICONDA -O miniconda.sh +bash miniconda.sh -b -p $HOME/miniconda +source $HOME/miniconda/etc/profile.d/conda.sh + + +# -- Make new conda environment with required Python version +conda create -y -n test python=$PYTHON_VERSION +conda activate test + + +# -- Install dependencies + +# Avoid problems with invalid SSL certificates +if [ "$PYTHON_VERSION" = "2.7" ]; then + conda install -q -y python=2.7.16=h9bab390_0 +fi + +# Install nomkl to avoid installing Intel MKL libraries +conda install -q -y nomkl + +# Install main dependencies +conda install -q -y -c spyder-ide --file requirements/conda.txt + +# Install test ones +conda install -q -y -c spyder-ide --file requirements/tests.txt + +# Github backend tests are failing with 1.1.1d +conda install -q -y openssl=1.1.1c + +# Install coveralls +pip install -q coveralls diff --git a/.circleci/run_tests.sh b/continuous_integration/circle/run_tests.sh similarity index 100% rename from .circleci/run_tests.sh rename to continuous_integration/circle/run_tests.sh diff --git a/requirements/conda.txt b/requirements/conda.txt new file mode 100644 index 0000000..b73fd6f --- /dev/null +++ b/requirements/conda.txt @@ -0,0 +1,2 @@ +line_profiler +spyder >=4 diff --git a/requirements/tests.txt b/requirements/tests.txt new file mode 100644 index 0000000..dd6b660 --- /dev/null +++ b/requirements/tests.txt @@ -0,0 +1,4 @@ +mock +pytest +pytest-cov +pytest-qt From ec803ca01cba86d4f02ddff46c596e39ce55ecb0 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Thu, 19 Sep 2019 13:49:22 +0100 Subject: [PATCH 3/5] Allow Spyder beta release in specification Also, remove some parts in install script that seem unnecessary. --- continuous_integration/circle/install.sh | 6 ------ requirements/conda.txt | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/continuous_integration/circle/install.sh b/continuous_integration/circle/install.sh index 02121a4..cb76280 100755 --- a/continuous_integration/circle/install.sh +++ b/continuous_integration/circle/install.sh @@ -27,9 +27,3 @@ conda install -q -y -c spyder-ide --file requirements/conda.txt # Install test ones conda install -q -y -c spyder-ide --file requirements/tests.txt - -# Github backend tests are failing with 1.1.1d -conda install -q -y openssl=1.1.1c - -# Install coveralls -pip install -q coveralls diff --git a/requirements/conda.txt b/requirements/conda.txt index b73fd6f..98c46ae 100644 --- a/requirements/conda.txt +++ b/requirements/conda.txt @@ -1,2 +1,2 @@ line_profiler -spyder >=4 +spyder >=4.0.0b5 From 227e181048f2a5ca18eb3e6152d6ceadf08a54af Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Thu, 19 Sep 2019 14:53:58 +0100 Subject: [PATCH 4/5] Add coveralls as testing requirement --- requirements/tests.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/tests.txt b/requirements/tests.txt index dd6b660..566b55c 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,3 +1,4 @@ +coveralls mock pytest pytest-cov From 14c3956a412195ed090901c44c9b41d593dd3bee Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Fri, 20 Sep 2019 14:15:03 +0100 Subject: [PATCH 5/5] Remove one more line which is only needed for Spyder 3 compatibility --- spyder_line_profiler/lineprofiler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spyder_line_profiler/lineprofiler.py b/spyder_line_profiler/lineprofiler.py index 681a217..abf8eb2 100644 --- a/spyder_line_profiler/lineprofiler.py +++ b/spyder_line_profiler/lineprofiler.py @@ -78,7 +78,6 @@ class LineProfiler(SpyderPluginWidget): def __init__(self, parent=None): SpyderPluginWidget.__init__(self, parent) - self.main = parent # Spyder 3 compatibility # Create widget and add to dockwindow self.widget = LineProfilerWidget(self.main)