Skip to content

Commit 7dabbff

Browse files
authored
Add flake8 linting in ci and clean up style issues (#230)
* Fix whitespace to match flake8. * Fix imports to appease flake8. * Rename things to match pep8. * Simplify check for nbagg.transparent. `rcParams` is a `dict`, so there's no need for the roundabout `set(rcParams.keys())`. * Add flake8 linting via reviewdog and GitHub Actions.
1 parent 8257581 commit 7dabbff

File tree

4 files changed

+64
-20
lines changed

4 files changed

+64
-20
lines changed

.github/workflows/reviewdog.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@ jobs:
1414
github_token: ${{ secrets.GITHUB_TOKEN }}
1515
reporter: github-check
1616
workdir: 'js'
17+
18+
flake8:
19+
name: flake8
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Set up Python 3
25+
uses: actions/setup-python@v1
26+
with:
27+
python-version: 3.8
28+
29+
- name: Install flake8
30+
run: pip3 install flake8
31+
32+
- name: Set up reviewdog
33+
run: |
34+
mkdir -p $HOME/bin
35+
curl -sfL \
36+
https://github.com/reviewdog/reviewdog/raw/master/install.sh | \
37+
sh -s -- -b $HOME/bin
38+
echo ::add-path::$HOME/bin
39+
40+
- name: Run flake8
41+
env:
42+
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
run: flake8 | reviewdog -f=pep8 -name=flake8 -reporter=github-check

ipympl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import sys
2-
from ._version import version_info, __version__
2+
from ._version import version_info, __version__ # noqa
33

44
npm_pkg_name = 'jupyter-matplotlib'
55

6+
67
def _jupyter_nbextension_paths():
78
return [{
89
'section': 'notebook',

ipympl/backend_nbagg.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
}
3737

3838

39-
4039
class Show(ShowBase):
4140

4241
def __call__(self, block=None):
@@ -61,8 +60,10 @@ def __call__(self, block=None):
6160
if not interactive and manager in Gcf._activeQue:
6261
Gcf._activeQue.remove(manager)
6362

63+
6464
show = Show()
6565

66+
6667
def draw_if_interactive():
6768
import matplotlib._pylab_helpers as pylab_helpers
6869

@@ -71,6 +72,7 @@ def draw_if_interactive():
7172
if manager is not None:
7273
manager.show()
7374

75+
7476
def connection_info():
7577
"""
7678
Return a string showing the figure and connection status for
@@ -101,13 +103,16 @@ class Toolbar(DOMWidget, NavigationToolbar2WebAgg):
101103
_view_name = Unicode('ToolbarView').tag(sync=True)
102104

103105
toolitems = List().tag(sync=True)
104-
orientation = Enum(['horizontal', 'vertical'], default_value='vertical').tag(sync=True)
106+
orientation = Enum(['horizontal', 'vertical'],
107+
default_value='vertical').tag(sync=True)
105108
button_style = CaselessStrEnum(
106-
values=['primary', 'success', 'info', 'warning', 'danger', ''], default_value='',
109+
values=['primary', 'success', 'info', 'warning', 'danger', ''],
110+
default_value='',
107111
help="""Use a predefined styling for the button.""").tag(sync=True)
108112
collapsed = Bool(True).tag(sync=True)
109113

110-
_current_action = Enum(values=['pan', 'zoom', ''], default_value='').tag(sync=True)
114+
_current_action = Enum(values=['pan', 'zoom', ''],
115+
default_value='').tag(sync=True)
111116

112117
def __init__(self, canvas, *args, **kwargs):
113118
DOMWidget.__init__(self, *args, **kwargs)
@@ -119,7 +124,8 @@ def export(self):
119124
buf = io.BytesIO()
120125
self.canvas.figure.savefig(buf, format='png', dpi='figure')
121126
# Figure width in pixels
122-
pwidth = self.canvas.figure.get_figwidth() * self.canvas.figure.get_dpi()
127+
pwidth = (self.canvas.figure.get_figwidth() *
128+
self.canvas.figure.get_dpi())
123129
# Scale size to match widget on HiPD monitors
124130
width = pwidth / self.canvas._dpi_ratio
125131
data = "<img src='data:image/png;base64,{0}' width={1}/>"
@@ -138,7 +144,8 @@ def _default_toolitems(self):
138144
'export': 'file-picture-o'
139145
}
140146

141-
download_item = ('Download', 'Download plot', 'download', 'save_figure')
147+
download_item = ('Download', 'Download plot', 'download',
148+
'save_figure')
142149

143150
toolitems = (NavigationToolbar2.toolitems + (download_item,))
144151

@@ -158,9 +165,11 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
158165
_view_module_version = Unicode(js_semver).tag(sync=True)
159166
_view_name = Unicode('MPLCanvasView').tag(sync=True)
160167

161-
toolbar = Instance(Toolbar, allow_none=True).tag(sync=True, **widget_serialization)
168+
toolbar = Instance(Toolbar,
169+
allow_none=True).tag(sync=True, **widget_serialization)
162170
toolbar_visible = Bool(True).tag(sync=True)
163-
toolbar_position = Enum(['top', 'bottom', 'left', 'right'], default_value='left').tag(sync=True)
171+
toolbar_position = Enum(['top', 'bottom', 'left', 'right'],
172+
default_value='left').tag(sync=True)
164173

165174
header_visible = Bool(True).tag(sync=True)
166175
footer_visible = Bool(True).tag(sync=True)
@@ -270,9 +279,9 @@ def new_figure_manager(num, *args, **kwargs):
270279
"""
271280
Create a new figure manager instance
272281
"""
273-
FigureClass = kwargs.pop('FigureClass', Figure)
274-
thisFig = FigureClass(*args, **kwargs)
275-
return new_figure_manager_given_figure(num, thisFig)
282+
figure_class = kwargs.pop('FigureClass', Figure)
283+
this_fig = figure_class(*args, **kwargs)
284+
return new_figure_manager_given_figure(num, this_fig)
276285

277286

278287
def new_figure_manager_given_figure(num, figure):
@@ -285,7 +294,7 @@ def closer(event):
285294
Gcf.destroy(num)
286295

287296
canvas = Canvas(figure)
288-
if 'nbagg.transparent' in set(rcParams.keys()) and rcParams['nbagg.transparent']:
297+
if 'nbagg.transparent' in rcParams and rcParams['nbagg.transparent']:
289298
figure.patch.set_alpha(0)
290299
manager = FigureManager(canvas, num)
291300

setup.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import print_function
2+
from distutils import log
23
from setuptools import setup, find_packages, Command
34
from setuptools.command.sdist import sdist
45
from setuptools.command.build_py import build_py
@@ -15,15 +16,15 @@
1516

1617
npm_path = os.pathsep.join([
1718
pjoin(node_root, 'node_modules', '.bin'),
18-
os.environ.get('PATH', os.defpath),
19+
os.environ.get('PATH', os.defpath),
1920
])
2021

21-
from distutils import log
2222
log.info('setup.py entered')
2323
log.info('$PATH=%s' % os.environ['PATH'])
2424

2525
LONG_DESCRIPTION = 'Matplotlib Jupyter Extension'
2626

27+
2728
def js_prerelease(command, strict=False):
2829
"""decorator for building minified js/css prior to another command"""
2930
class DecoratedCommand(command):
@@ -50,6 +51,7 @@ def run(self):
5051
update_package_data(self.distribution)
5152
return DecoratedCommand
5253

54+
5355
def update_package_data(distribution):
5456
"""update package_data to catch changes during setup"""
5557
build_py = distribution.get_command_obj('build_py')
@@ -106,21 +108,26 @@ def has_npm(self):
106108
def run(self):
107109
has_npm = self.has_npm()
108110
if not has_npm:
109-
log.error("`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo")
111+
log.error("`npm` unavailable. If you're running this command "
112+
"using sudo, make sure `npm` is available to sudo")
110113

111114
env = os.environ.copy()
112115
env['PATH'] = npm_path
113116

114117
if self.has_npm():
115-
log.info("Installing build dependencies with npm. This may take a while...")
116-
check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr)
117-
check_call(['npm', 'pack'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr)
118+
log.info("Installing build dependencies with npm. "
119+
"This may take a while...")
120+
check_call(['npm', 'install'], cwd=node_root, stdout=sys.stdout,
121+
stderr=sys.stderr)
122+
check_call(['npm', 'pack'], cwd=node_root, stdout=sys.stdout,
123+
stderr=sys.stderr)
118124

119125
for t in self.targets:
120126
if not os.path.exists(t):
121127
msg = 'Missing file: %s' % t
122128
if not has_npm:
123-
msg += '\nnpm is required to build a development version of widgetsnbextension'
129+
msg += ('\nnpm is required to build a development version '
130+
'of widgetsnbextension')
124131
raise ValueError(msg)
125132

126133
# update package data in case this created new files

0 commit comments

Comments
 (0)