Skip to content

Commit 7fbaa76

Browse files
authored
More CI Cleanup (#742)
1 parent 6c58a0e commit 7fbaa76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+111
-91
lines changed

.github/workflows/python-linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Run the tests
5555
if: ${{ matrix.python-version != 'pypy-3.7' }}
5656
run: |
57-
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered || pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --lf
57+
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --cov-fail-under 70 || pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered --cov-fail-under 70 --lf
5858
- name: Run the tests on pypy
5959
if: ${{ matrix.python-version == 'pypy-3.7' }}
6060
run: |

.mailmap

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ David Hirschfeld <[email protected]> dhirschfeld <david.hirschfeld
2626
David P. Sanders <[email protected]> David P. Sanders <[email protected]>
2727
David Warde-Farley <[email protected]> David Warde-Farley <>
2828
Doug Blank <[email protected]> Doug Blank <[email protected]>
29-
Eugene Van den Bulke <[email protected]> Eugene Van den Bulke <[email protected]>
29+
Eugene Van den Bulke <[email protected]> Eugene Van den Bulke <[email protected]>
3030
3131
3232

.pre-commit-config.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ repos:
1515
hooks:
1616
- id: prettier
1717

18-
- repo: https://gitlab.com/pycqa/flake8
18+
- repo: https://github.com/pycqa/flake8
1919
rev: 4.0.1
2020
hooks:
2121
- id: flake8
22+
additional_dependencies:
23+
[
24+
"flake8-bugbear==20.1.4",
25+
"flake8-logging-format==0.6.0",
26+
"flake8-implicit-str-concat==0.2.0",
27+
]
2228

2329
- repo: https://github.com/pre-commit/pre-commit-hooks
2430
rev: v4.1.0
@@ -33,6 +39,8 @@ repos:
3339
- id: check-yaml
3440
- id: debug-statements
3541
- id: forbid-new-submodules
42+
- id: check-builtin-literals
43+
- id: trailing-whitespace
3644

3745
- repo: https://github.com/pre-commit/mirrors-eslint
3846
rev: v8.8.0

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ linkcheck:
176176
@echo
177177
@echo "Link check complete; look for any errors in the above output " \
178178
"or in $(BUILDDIR)/linkcheck/output.txt."
179-
179+
180180
spelling:
181181
$(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) $(BUILDDIR)/spelling
182182
@echo "Spell check complete; look for any errors in the above output " \

docs/autogen_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"""
3838
try:
3939
destination = os.path.join(os.path.dirname(__file__), "source/other/full-config.rst")
40-
except:
40+
except BaseException:
4141
destination = os.path.join(os.getcwd(), "full-config.rst")
4242

4343
with open(destination, "w") as f:

docs/source/conf.py

-11
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,6 @@
279279

280280
# -- Options for LaTeX output ---------------------------------------------
281281

282-
latex_elements = {
283-
# The paper size ('letterpaper' or 'a4paper').
284-
#'papersize': 'letterpaper',
285-
# The font size ('10pt', '11pt' or '12pt').
286-
#'pointsize': '10pt',
287-
# Additional stuff for the LaTeX preamble.
288-
#'preamble': '',
289-
# Latex figure (float) alignment
290-
#'figure_align': 'htbp',
291-
}
292-
293282
# Grouping the document tree into LaTeX files. List of tuples
294283
# (source start file, target name, title,
295284
# author, documentclass [howto, manual, or own class]).

examples/simple/jupyter_server_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# ------------------------------------------------------------------------------
33
# Application(SingletonConfigurable) configuration
44
# ------------------------------------------------------------------------------
5-
## The date format used by logging formatters for %(asctime)s
5+
# The date format used by logging formatters for %(asctime)s
66
c.Application.log_datefmt = "%Y-%m-%d %H:%M:%S Simple_Extensions_Example"

examples/simple/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
22
# Disable any upper exclusion.
3-
norecursedirs =
3+
norecursedirs =

examples/simple/simple_ext11/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def simple11_dir_formatted(self):
5757

5858
def initialize_settings(self):
5959
self.log.info("hello: {}".format(self.hello))
60-
if self.hello == True:
60+
if self.hello is True:
6161
self.log.info(
6262
"Hello Simple11: You have launched with --hello flag or defined 'c.SimpleApp1.hello == True' in your config file"
6363
)

jupyter_server/auth/login.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ def validate_security(cls, app, ssl_options=None):
229229
if not app.ip:
230230
warning = "WARNING: The Jupyter server is listening on all IP addresses"
231231
if ssl_options is None:
232-
app.log.warning(warning + " and not using encryption. This " "is not recommended.")
232+
app.log.warning(f"{warning} and not using encryption. This is not recommended.")
233233
if not app.password and not app.token:
234234
app.log.warning(
235-
warning + " and not using authentication. "
235+
f"{warning} and not using authentication. "
236236
"This is highly insecure and not recommended."
237237
)
238238
else:

jupyter_server/auth/logout.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get(self):
1111
if self.login_available:
1212
message = {"info": "Successfully logged out."}
1313
else:
14-
message = {"warning": "Cannot log out. Jupyter Server authentication " "is disabled."}
14+
message = {"warning": "Cannot log out. Jupyter Server authentication is disabled."}
1515
self.write(self.render_template("logout.html", message=message))
1616

1717

jupyter_server/auth/security.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def passwd(passphrase=None, algorithm="argon2"):
4848
4949
"""
5050
if passphrase is None:
51-
for i in range(3):
51+
for _ in range(3):
5252
p0 = getpass.getpass("Enter password: ")
5353
p1 = getpass.getpass("Verify password: ")
5454
if p0 == p1:
@@ -161,7 +161,7 @@ def persist_config(config_file=None, mode=0o600):
161161

162162
try:
163163
os.chmod(config_file, mode)
164-
except Exception as e:
164+
except Exception:
165165
tb = traceback.format_exc()
166166
warnings.warn("Failed to set permissions on %s:\n%s" % (config_file, tb), RuntimeWarning)
167167

jupyter_server/base/handlers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def check_xsrf_cookie(self):
454454
return
455455
try:
456456
return super(JupyterHandler, self).check_xsrf_cookie()
457-
except web.HTTPError as e:
457+
except web.HTTPError:
458458
if self.request.method in {"GET", "HEAD"}:
459459
# Consider Referer a sufficient cross-origin check for GET requests
460460
if not self.check_referer():

jupyter_server/extension/application.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def load_classic_server_extension(cls, serverapp):
543543
extension.initialize()
544544

545545
@classmethod
546-
def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
546+
def initialize_server(cls, argv=None, load_other_extensions=True, **kwargs):
547547
"""Creates an instance of ServerApp and explicitly sets
548548
this extension to enabled=True (i.e. superceding disabling
549549
found in other config from files).
@@ -560,7 +560,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
560560
serverapp = ServerApp.instance(jpserver_extensions=jpserver_extensions, **kwargs)
561561
serverapp.aliases.update(cls.aliases)
562562
serverapp.initialize(
563-
argv=argv,
563+
argv=argv or [],
564564
starter_extension=cls.name,
565565
find_extensions=find_extensions,
566566
)

jupyter_server/extension/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _valid_metadata(self, proposed):
3939
self._module_name = metadata["module"]
4040
except KeyError:
4141
raise ExtensionMetadataError(
42-
"There is no 'module' key in the extension's " "metadata packet."
42+
"There is no 'module' key in the extension's metadata packet."
4343
)
4444

4545
try:

jupyter_server/extension/serverextension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def list_server_extensions(self):
337337
version = extension.version
338338
self.log.info(" {} {} {}".format(name, version, GREEN_OK))
339339
except Exception as err:
340-
self.log.warn(" {} {}".format(RED_X, err))
340+
self.log.warning(" {} {}".format(RED_X, err))
341341
# Add a blank line between paths.
342342
self.log.info("")
343343

jupyter_server/extension/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def get_loader(obj, logger=None):
2626
underscore prefix.
2727
"""
2828
try:
29-
func = getattr(obj, "_load_jupyter_server_extension")
29+
func = getattr(obj, "_load_jupyter_server_extension") # noqa B009
3030
except AttributeError:
31-
func = getattr(obj, "load_jupyter_server_extension")
31+
func = getattr(obj, "load_jupyter_server_extension", None)
3232
warnings.warn(
3333
"A `_load_jupyter_server_extension` function was not "
3434
"found in {name!s}. Instead, a `load_jupyter_server_extension` "

jupyter_server/gateway/managers.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ async def list_kernels(self, **kwargs):
125125
# Remove any of our kernels that may have been culled on the gateway server
126126
our_kernels = self._kernels.copy()
127127
culled_ids = []
128-
for kid, km in our_kernels.items():
128+
for kid, _ in our_kernels.items():
129129
if kid not in kernel_models:
130-
self.log.warn(f"Kernel {kid} no longer active - probably culled on Gateway server.")
130+
self.log.warning(
131+
f"Kernel {kid} no longer active - probably culled on Gateway server."
132+
)
131133
self._kernels.pop(kid, None)
132134
culled_ids.append(kid) # TODO: Figure out what do with these.
133135
return list(kernel_models.values())
@@ -606,7 +608,7 @@ async def start_channels(self, shell=True, iopub=True, stdin=True, hb=True, cont
606608
"channels",
607609
)
608610
# Gather cert info in case where ssl is desired...
609-
ssl_options = dict()
611+
ssl_options = {}
610612
ssl_options["ca_certs"] = GatewayClient.instance().ca_certs
611613
ssl_options["certfile"] = GatewayClient.instance().client_cert
612614
ssl_options["keyfile"] = GatewayClient.instance().client_key

jupyter_server/i18n/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def parse_accept_lang_header(accept_lang):
5252
by_q[qvalue].append(lang)
5353

5454
res = []
55-
for qvalue, langs in sorted(by_q.items()):
55+
for _, langs in sorted(by_q.items()):
5656
res.extend(sorted(langs))
5757
return res
5858

jupyter_server/i18n/babel_nbui.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[jinja2: notebook/templates/**.html]
22
encoding = utf-8
3-
[extractors]
3+
[extractors]
44
jinja2 = jinja2.ext:babel_extract

jupyter_server/nbconvert/handlers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def find_resource_files(output_files_dir):
3232
files = []
33-
for dirpath, dirnames, filenames in os.walk(output_files_dir):
33+
for dirpath, _, filenames in os.walk(output_files_dir):
3434
files.extend([os.path.join(dirpath, f) for f in filenames])
3535
return files
3636

jupyter_server/serverapp.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
url_path_join,
133133
check_pid,
134134
url_escape,
135-
pathname2url,
136135
unix_socket_in_use,
137136
urlencode_unix_socket_path,
138137
fetch,
@@ -198,7 +197,7 @@ def random_ports(port, n):
198197
"""
199198
for i in range(min(5, n)):
200199
yield port + i
201-
for i in range(n - 5):
200+
for _ in range(n - 5):
202201
yield max(1, port + random.randint(-2 * n, 2 * n))
203202

204203

@@ -292,11 +291,7 @@ def init_settings(
292291
)
293292
sys_info = get_sys_info()
294293

295-
# If the user is running the server in a git directory, make the assumption
296-
# that this is a dev install and suggest to the developer `npm run build:watch`.
297294
base_dir = os.path.realpath(os.path.join(__file__, "..", ".."))
298-
dev_mode = os.path.exists(os.path.join(base_dir, ".git"))
299-
300295
nbui = gettext.translation(
301296
"nbui",
302297
localedir=os.path.join(base_dir, "jupyter_server/i18n"),
@@ -423,7 +418,7 @@ def init_handlers(self, default_services, settings):
423418
# for each handler required for gateway, locate its pattern
424419
# in the current list and replace that entry...
425420
gateway_handlers = load_handlers("jupyter_server.gateway.handlers")
426-
for i, gwh in enumerate(gateway_handlers):
421+
for _, gwh in enumerate(gateway_handlers):
427422
for j, h in enumerate(handlers):
428423
if gwh[0] == h[0]:
429424
handlers[j] = (gwh[0], gwh[1])
@@ -517,7 +512,7 @@ def shutdown_server(server_info, timeout=5, log=None):
517512
if log:
518513
log.debug("POST request to %sapi/shutdown", url)
519514

520-
r = fetch(url, method="POST", headers={"Authorization": "token " + server_info["token"]})
515+
fetch(url, method="POST", headers={"Authorization": "token " + server_info["token"]})
521516
# Poll to see if it shut down.
522517
for _ in range(timeout * 10):
523518
if not check_pid(pid):
@@ -581,7 +576,7 @@ def _shutdown_or_exit(self, target_endpoint, server):
581576
def _maybe_remove_unix_socket(socket_path):
582577
try:
583578
os.unlink(socket_path)
584-
except (OSError, IOError):
579+
except OSError:
585580
pass
586581

587582
def start(self):
@@ -1293,7 +1288,7 @@ def _default_allow_remote(self):
12931288
tornado_settings = Dict(
12941289
config=True,
12951290
help=_i18n(
1296-
"Supply overrides for the tornado.web.Application that the " "Jupyter server uses."
1291+
"Supply overrides for the tornado.web.Application that the Jupyter server uses."
12971292
),
12981293
)
12991294

@@ -1948,7 +1943,6 @@ def init_webapp(self):
19481943
)
19491944
if self.ssl_options.get("ca_certs", False):
19501945
self.ssl_options.setdefault("cert_reqs", ssl.CERT_REQUIRED)
1951-
ssl_options = self.ssl_options
19521946

19531947
self.login_handler_class.validate_security(self, ssl_options=self.ssl_options)
19541948

@@ -2655,8 +2649,10 @@ def launch_browser(self):
26552649

26562650
assembled_url, _ = self._prepare_browser_open()
26572651

2658-
b = lambda: browser.open(assembled_url, new=self.webbrowser_open_new)
2659-
threading.Thread(target=b).start()
2652+
def target():
2653+
browser.open(assembled_url, new=self.webbrowser_open_new)
2654+
2655+
threading.Thread(target=target).start()
26602656

26612657
def start_app(self):
26622658
super(ServerApp, self).start()

jupyter_server/services/contents/fileio.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def atomic_writing(path, text=True, encoding="utf-8", log=None, **kwargs):
113113

114114
try:
115115
yield fileobj
116-
except:
116+
except BaseException:
117117
# Failed! Move the backup file back to the real path to avoid corruption
118118
fileobj.close()
119119
replace_file(tmp_path, path)
@@ -161,7 +161,7 @@ def _simple_writing(path, text=True, encoding="utf-8", log=None, **kwargs):
161161

162162
try:
163163
yield fileobj
164-
except:
164+
except BaseException:
165165
fileobj.close()
166166
raise
167167

@@ -219,7 +219,7 @@ def perm_to_403(self, os_path=""):
219219
"""context manager for turning permission errors into 403."""
220220
try:
221221
yield
222-
except (OSError, IOError) as e:
222+
except OSError as e:
223223
if e.errno in {errno.EPERM, errno.EACCES}:
224224
# make 403 error message without root prefix
225225
# this may not work perfectly on unicode paths on Python 2,

jupyter_server/services/contents/filemanager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def is_non_empty_dir(os_path):
500500
return
501501
else:
502502
self.log.warning(
503-
"Skipping trash for %s, on different device " "to home directory",
503+
"Skipping trash for %s, on different device to home directory",
504504
os_path,
505505
)
506506

@@ -833,7 +833,7 @@ async def is_non_empty_dir(os_path):
833833
return
834834
else:
835835
self.log.warning(
836-
"Skipping trash for %s, on different device " "to home directory",
836+
"Skipping trash for %s, on different device to home directory",
837837
os_path,
838838
)
839839

jupyter_server/services/contents/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def validate_notebook_model(self, model, validation_error=None):
505505
validate_nb(model["content"])
506506
except ValidationError as e:
507507
model["message"] = "Notebook validation failed: {}:\n{}".format(
508-
e.message,
508+
str(e),
509509
json.dumps(e.instance, indent=1, default=lambda obj: "<UNKNOWN>"),
510510
)
511511
return model

0 commit comments

Comments
 (0)