From ca4644875f469de42f4339faccc7b049215b0c0d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 20 May 2020 18:59:01 -0400 Subject: [PATCH 1/5] Fix whitespace to match flake8. --- ipympl/__init__.py | 1 + ipympl/backend_nbagg.py | 25 +++++++++++++++++-------- setup.py | 19 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ipympl/__init__.py b/ipympl/__init__.py index f4cedf83..6f96e2ed 100644 --- a/ipympl/__init__.py +++ b/ipympl/__init__.py @@ -3,6 +3,7 @@ npm_pkg_name = 'jupyter-matplotlib' + def _jupyter_nbextension_paths(): return [{ 'section': 'notebook', diff --git a/ipympl/backend_nbagg.py b/ipympl/backend_nbagg.py index 04d74df3..b3ec0976 100644 --- a/ipympl/backend_nbagg.py +++ b/ipympl/backend_nbagg.py @@ -36,7 +36,6 @@ } - class Show(ShowBase): def __call__(self, block=None): @@ -61,8 +60,10 @@ def __call__(self, block=None): if not interactive and manager in Gcf._activeQue: Gcf._activeQue.remove(manager) + show = Show() + def draw_if_interactive(): import matplotlib._pylab_helpers as pylab_helpers @@ -71,6 +72,7 @@ def draw_if_interactive(): if manager is not None: manager.show() + def connection_info(): """ Return a string showing the figure and connection status for @@ -101,13 +103,16 @@ class Toolbar(DOMWidget, NavigationToolbar2WebAgg): _view_name = Unicode('ToolbarView').tag(sync=True) toolitems = List().tag(sync=True) - orientation = Enum(['horizontal', 'vertical'], default_value='vertical').tag(sync=True) + orientation = Enum(['horizontal', 'vertical'], + default_value='vertical').tag(sync=True) button_style = CaselessStrEnum( - values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='', + values=['primary', 'success', 'info', 'warning', 'danger', ''], + default_value='', help="""Use a predefined styling for the button.""").tag(sync=True) collapsed = Bool(True).tag(sync=True) - _current_action = Enum(values=['pan', 'zoom', ''], default_value='').tag(sync=True) + _current_action = Enum(values=['pan', 'zoom', ''], + default_value='').tag(sync=True) def __init__(self, canvas, *args, **kwargs): DOMWidget.__init__(self, *args, **kwargs) @@ -119,7 +124,8 @@ def export(self): buf = io.BytesIO() self.canvas.figure.savefig(buf, format='png', dpi='figure') # Figure width in pixels - pwidth = self.canvas.figure.get_figwidth() * self.canvas.figure.get_dpi() + pwidth = (self.canvas.figure.get_figwidth() * + self.canvas.figure.get_dpi()) # Scale size to match widget on HiPD monitors width = pwidth / self.canvas._dpi_ratio data = "" @@ -138,7 +144,8 @@ def _default_toolitems(self): 'export': 'file-picture-o' } - download_item = ('Download', 'Download plot', 'download', 'save_figure') + download_item = ('Download', 'Download plot', 'download', + 'save_figure') toolitems = (NavigationToolbar2.toolitems + (download_item,)) @@ -158,9 +165,11 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore): _view_module_version = Unicode(js_semver).tag(sync=True) _view_name = Unicode('MPLCanvasView').tag(sync=True) - toolbar = Instance(Toolbar, allow_none=True).tag(sync=True, **widget_serialization) + toolbar = Instance(Toolbar, + allow_none=True).tag(sync=True, **widget_serialization) toolbar_visible = Bool(True).tag(sync=True) - toolbar_position = Enum(['top', 'bottom', 'left', 'right'], default_value='left').tag(sync=True) + toolbar_position = Enum(['top', 'bottom', 'left', 'right'], + default_value='left').tag(sync=True) header_visible = Bool(True).tag(sync=True) footer_visible = Bool(True).tag(sync=True) diff --git a/setup.py b/setup.py index 66be3172..36872b82 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ npm_path = os.pathsep.join([ pjoin(node_root, 'node_modules', '.bin'), - os.environ.get('PATH', os.defpath), + os.environ.get('PATH', os.defpath), ]) from distutils import log @@ -24,6 +24,7 @@ LONG_DESCRIPTION = 'Matplotlib Jupyter Extension' + def js_prerelease(command, strict=False): """decorator for building minified js/css prior to another command""" class DecoratedCommand(command): @@ -50,6 +51,7 @@ def run(self): update_package_data(self.distribution) return DecoratedCommand + def update_package_data(distribution): """update package_data to catch changes during setup""" build_py = distribution.get_command_obj('build_py') @@ -106,21 +108,26 @@ def has_npm(self): def run(self): has_npm = self.has_npm() if not has_npm: - log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo") + log.error("`npm` unavailable. If you're running this command " + "using sudo, make sure `npm` is available to sudo") env = os.environ.copy() env['PATH'] = npm_path if self.has_npm(): - log.info("Installing build dependencies with npm. This may take a while...") - check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) - check_call(['npm', 'pack'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) + log.info("Installing build dependencies with npm. " + "This may take a while...") + check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout, + stderr=sys.stderr) + check_call(['npm', 'pack'], cwd=node_root, stdout=sys.stdout, + stderr=sys.stderr) for t in self.targets: if not os.path.exists(t): msg = 'Missing file: %s' % t if not has_npm: - msg += '\nnpm is required to build a development version of widgetsnbextension' + msg += ('\nnpm is required to build a development version ' + 'of widgetsnbextension') raise ValueError(msg) # update package data in case this created new files From d8c2e67ad0333158658e9e9a62bad558d27df890 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 20 May 2020 19:00:50 -0400 Subject: [PATCH 2/5] Fix imports to appease flake8. --- ipympl/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ipympl/__init__.py b/ipympl/__init__.py index 6f96e2ed..c3e61d25 100644 --- a/ipympl/__init__.py +++ b/ipympl/__init__.py @@ -1,5 +1,5 @@ import sys -from ._version import version_info, __version__ +from ._version import version_info, __version__ # noqa npm_pkg_name = 'jupyter-matplotlib' diff --git a/setup.py b/setup.py index 36872b82..8123f5eb 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from __future__ import print_function +from distutils import log from setuptools import setup, find_packages, Command from setuptools.command.sdist import sdist from setuptools.command.build_py import build_py @@ -18,7 +19,6 @@ os.environ.get('PATH', os.defpath), ]) -from distutils import log log.info('setup.py entered') log.info('$PATH=%s' % os.environ['PATH']) From d8b3612413e346411e0fd530a852f9b871b4c407 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 20 May 2020 19:02:23 -0400 Subject: [PATCH 3/5] Rename things to match pep8. --- ipympl/backend_nbagg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ipympl/backend_nbagg.py b/ipympl/backend_nbagg.py index b3ec0976..8a33a085 100644 --- a/ipympl/backend_nbagg.py +++ b/ipympl/backend_nbagg.py @@ -279,9 +279,9 @@ def new_figure_manager(num, *args, **kwargs): """ Create a new figure manager instance """ - FigureClass = kwargs.pop('FigureClass', Figure) - thisFig = FigureClass(*args, **kwargs) - return new_figure_manager_given_figure(num, thisFig) + figure_class = kwargs.pop('FigureClass', Figure) + this_fig = figure_class(*args, **kwargs) + return new_figure_manager_given_figure(num, this_fig) def new_figure_manager_given_figure(num, figure): From 08a63b95dfcefcafef502289343224fda1c6691f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 20 May 2020 19:15:31 -0400 Subject: [PATCH 4/5] Simplify check for nbagg.transparent. `rcParams` is a `dict`, so there's no need for the roundabout `set(rcParams.keys())`. --- ipympl/backend_nbagg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipympl/backend_nbagg.py b/ipympl/backend_nbagg.py index 8a33a085..def5ab92 100644 --- a/ipympl/backend_nbagg.py +++ b/ipympl/backend_nbagg.py @@ -294,7 +294,7 @@ def closer(event): Gcf.destroy(num) canvas = Canvas(figure) - if 'nbagg.transparent' in set(rcParams.keys()) and rcParams['nbagg.transparent']: + if 'nbagg.transparent' in rcParams and rcParams['nbagg.transparent']: figure.patch.set_alpha(0) manager = FigureManager(canvas, num) From e4e55f7811ee5f76b9c93e9501aee5e1e0d684ec Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 20 May 2020 19:17:11 -0400 Subject: [PATCH 5/5] Add flake8 linting via reviewdog and GitHub Actions. --- .github/workflows/reviewdog.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 22d2768c..9cc8302d 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -14,3 +14,30 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} reporter: github-check workdir: 'js' + + flake8: + name: flake8 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3 + uses: actions/setup-python@v1 + with: + python-version: 3.8 + + - name: Install flake8 + run: pip3 install flake8 + + - name: Set up reviewdog + run: | + mkdir -p $HOME/bin + curl -sfL \ + https://github.com/reviewdog/reviewdog/raw/master/install.sh | \ + sh -s -- -b $HOME/bin + echo ::add-path::$HOME/bin + + - name: Run flake8 + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: flake8 | reviewdog -f=pep8 -name=flake8 -reporter=github-check