Skip to content

Commit 5888059

Browse files
authored
Merge pull request #1027 from Carreau/cleanup
Cleanup
2 parents ae2f358 + e404b40 commit 5888059

File tree

18 files changed

+47
-47
lines changed

18 files changed

+47
-47
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ jobs:
3434
python3 -m pip install -r requirements.in -r requirements-dev.txt
3535
- name: install mypy
3636
run: |
37-
python3 -m pip install mypy types-pycurl types-requests types-Markdown
37+
python3 -m pip install mypy types-pycurl types-requests types-Markdown pyflakes
3838
- name: run mypy
3939
run: |
4040
mypy nbviewer
41+
- name: run pyflakes
42+
run: |
43+
pyflakes nbviewer
4144
4245
- name: pip freeze
4346
run: |

nbviewer/_version.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
8282
stderr=(subprocess.PIPE if hide_stderr else None),
8383
)
8484
break
85-
except EnvironmentError:
85+
except OSError:
8686
e = sys.exc_info()[1]
8787
if e.errno == errno.ENOENT:
8888
continue
@@ -92,7 +92,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
9292
return None, None
9393
else:
9494
if verbose:
95-
print("unable to find command, tried %s" % (commands,))
95+
print(f"unable to find command, tried {commands}")
9696
return None, None
9797
stdout = p.communicate()[0].strip().decode()
9898
if p.returncode != 0:
@@ -143,22 +143,21 @@ def git_get_keywords(versionfile_abs):
143143
# _version.py.
144144
keywords = {}
145145
try:
146-
f = open(versionfile_abs, "r")
147-
for line in f.readlines():
148-
if line.strip().startswith("git_refnames ="):
149-
mo = re.search(r'=\s*"(.*)"', line)
150-
if mo:
151-
keywords["refnames"] = mo.group(1)
152-
if line.strip().startswith("git_full ="):
153-
mo = re.search(r'=\s*"(.*)"', line)
154-
if mo:
155-
keywords["full"] = mo.group(1)
156-
if line.strip().startswith("git_date ="):
157-
mo = re.search(r'=\s*"(.*)"', line)
158-
if mo:
159-
keywords["date"] = mo.group(1)
160-
f.close()
161-
except EnvironmentError:
146+
with open(versionfile_abs) as f:
147+
for line in f.readlines():
148+
if line.strip().startswith("git_refnames ="):
149+
mo = re.search(r'=\s*"(.*)"', line)
150+
if mo:
151+
keywords["refnames"] = mo.group(1)
152+
if line.strip().startswith("git_full ="):
153+
mo = re.search(r'=\s*"(.*)"', line)
154+
if mo:
155+
keywords["full"] = mo.group(1)
156+
if line.strip().startswith("git_date ="):
157+
mo = re.search(r'=\s*"(.*)"', line)
158+
if mo:
159+
keywords["date"] = mo.group(1)
160+
except OSError:
162161
pass
163162
return keywords
164163

@@ -182,11 +181,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
182181
if verbose:
183182
print("keywords are unexpanded, not using")
184183
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
185-
refs = set([r.strip() for r in refnames.strip("()").split(",")])
184+
refs = {r.strip() for r in refnames.strip("()").split(",")}
186185
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
187186
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
188187
TAG = "tag: "
189-
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
188+
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
190189
if not tags:
191190
# Either we're using git < 1.8.3, or there really are no tags. We use
192191
# a heuristic: assume all version tags have a digit. The old git %d
@@ -195,7 +194,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
195194
# between branches and tags. By ignoring refnames without digits, we
196195
# filter out many common branch names like "release" and
197196
# "stabilization", as well as "HEAD" and "master".
198-
tags = set([r for r in refs if re.search(r"\d", r)])
197+
tags = {r for r in refs if re.search(r"\d", r)}
199198
if verbose:
200199
print("discarding '%s', no digits" % ",".join(refs - tags))
201200
if verbose:
@@ -298,10 +297,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
298297
if verbose:
299298
fmt = "tag '%s' doesn't start with prefix '%s'"
300299
print(fmt % (full_tag, tag_prefix))
301-
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
302-
full_tag,
303-
tag_prefix,
304-
)
300+
pieces[
301+
"error"
302+
] = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'"
305303
return pieces
306304
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
307305

nbviewer/app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ def fetch_kwargs(self):
496496
fetch_kwargs = dict(connect_timeout=10)
497497
if self.proxy_host:
498498
fetch_kwargs.update(proxy_host=self.proxy_host, proxy_port=self.proxy_port)
499-
self.log.info(
500-
"Using web proxy {proxy_host}:{proxy_port}." "".format(**fetch_kwargs)
501-
)
499+
self.log.info("Using web proxy %(proxy_host)s:%(proxy_port).", fetch_kwargs)
502500

503501
if self.no_check_certificate:
504502
fetch_kwargs.update(validate_cert=False)
@@ -579,7 +577,7 @@ def static_paths(self):
579577
def template_paths(self):
580578
default_template_path = pjoin(here, "templates")
581579
if self.template_path:
582-
self.log.info("Using custom template path {}".format(self.template_path))
580+
self.log.info("Using custom template path %()s", self.template_path)
583581
template_paths = [self.template_path, default_template_path]
584582
else:
585583
template_paths = [default_template_path]

nbviewer/providers/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _load_provider_feature(feature, providers, **handler_names):
8383
try:
8484
# Ex: handler_names['url_handler']
8585
handler_names[provider_handler_key]
86-
except KeyError as e:
86+
except KeyError:
8787
continue
8888
else:
8989
# Ex: provider_handlers['url_handler'] = handler_names['url_handler']

nbviewer/providers/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def write_error(self, status_code: int, **kwargs):
445445
# render the template
446446
try:
447447
html = self.render_status_code_template(status_code, **namespace)
448-
except Exception as e:
448+
except Exception:
449449
html = self.render_error_template(**namespace)
450450
self.set_header("Content-Type", "text/html")
451451
self.write(html)
@@ -561,7 +561,7 @@ async def cached_method(self, *args, **kwargs):
561561
cached = pickle.loads(cached_pickle)
562562
else:
563563
cached = None
564-
except Exception as e:
564+
except Exception:
565565
self.log.error("Exception getting %s from cache", short_url, exc_info=True)
566566
cached = None
567567

@@ -631,7 +631,7 @@ def filter_formats(self, nb, raw):
631631
try:
632632
if test is None or test(nb, raw):
633633
yield (name, format)
634-
except Exception as err:
634+
except Exception:
635635
self.log.info("Failed to test %s: %s", self.request.uri, name)
636636

637637
# empty methods to be implemented by subclasses to make GET requests more modular
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .handlers import uri_rewrites
2+
3+
__all__ = ["uri_rewrites"]

nbviewer/providers/gist/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .handlers import default_handlers
22
from .handlers import uri_rewrites
3+
4+
__all__ = ["default_handlers", "uri_rewrites"]

nbviewer/providers/github/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from .handlers import default_handlers
22
from .handlers import uri_rewrites
3+
4+
__all__ = ["default_handlers", "uri_rewrites"]

nbviewer/providers/github/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# -----------------------------------------------------------------------------
77
import json
88
import os
9-
from urllib.parse import urlparse
109

1110
from tornado.httpclient import AsyncHTTPClient
1211
from tornado.httpclient import HTTPError

nbviewer/providers/github/handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def deliver_notebook(
432432
nbjson = filedata.decode("utf-8")
433433
else:
434434
nbjson = filedata
435-
except Exception as e:
435+
except Exception:
436436
self.log.error("Failed to decode notebook: %s", raw_url, exc_info=True)
437437
raise web.HTTPError(400)
438438

0 commit comments

Comments
 (0)