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

Add flake8 linting in ci and clean up style issues #230

Merged
merged 5 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion ipympl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
from ._version import version_info, __version__
from ._version import version_info, __version__ # noqa

npm_pkg_name = 'jupyter-matplotlib'


def _jupyter_nbextension_paths():
return [{
'section': 'notebook',
Expand Down
33 changes: 21 additions & 12 deletions ipympl/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
}



class Show(ShowBase):

def __call__(self, block=None):
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 = "<img src='data:image/png;base64,{0}' width={1}/>"
Expand All @@ -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,))

Expand All @@ -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)
Expand Down Expand Up @@ -270,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):
Expand All @@ -285,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)

Expand Down
21 changes: 14 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,15 +16,15 @@

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
log.info('setup.py entered')
log.info('$PATH=%s' % os.environ['PATH'])

LONG_DESCRIPTION = 'Matplotlib Jupyter Extension'


def js_prerelease(command, strict=False):
"""decorator for building minified js/css prior to another command"""
class DecoratedCommand(command):
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand Down