Skip to content

Commit

Permalink
More CI Cleanup (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Mar 16, 2022
1 parent 6c58a0e commit 7fbaa76
Show file tree
Hide file tree
Showing 49 changed files with 111 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-linux.yml
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Run the tests
if: ${{ matrix.python-version != 'pypy-3.7' }}
run: |
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
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
- name: Run the tests on pypy
if: ${{ matrix.python-version == 'pypy-3.7' }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .mailmap
Expand Up @@ -26,7 +26,7 @@ David Hirschfeld <david.hirschfeld@gazprom-mt.com> dhirschfeld <david.hirschfeld
David P. Sanders <dpsanders@gmail.com> David P. Sanders <dpsanders@ciencias.unam.mx>
David Warde-Farley <wardefar@iro.umontreal.ca> David Warde-Farley <>
Doug Blank <dblank@cs.brynmawr.edu> Doug Blank <doug.blank@gmail.com>
Eugene Van den Bulke <eugene.van-den-bulke@gmail.com> Eugene Van den Bulke <eugene.vandenbulke@gmail.com>
Eugene Van den Bulke <eugene.van-den-bulke@gmail.com> Eugene Van den Bulke <eugene.vandenbulke@gmail.com>
Evan Patterson <epatters@enthought.com> <epatters@EPattersons-MacBook-Pro.local>
Evan Patterson <epatters@enthought.com> <epatters@evan-laptop.localdomain>
Evan Patterson <epatters@enthought.com> <epatters@caltech.edu>
Expand Down
10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Expand Up @@ -15,10 +15,16 @@ repos:
hooks:
- id: prettier

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
[
"flake8-bugbear==20.1.4",
"flake8-logging-format==0.6.0",
"flake8-implicit-str-concat==0.2.0",
]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
Expand All @@ -33,6 +39,8 @@ repos:
- id: check-yaml
- id: debug-statements
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.8.0
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Expand Up @@ -176,7 +176,7 @@ linkcheck:
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

spelling:
$(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) $(BUILDDIR)/spelling
@echo "Spell check complete; look for any errors in the above output " \
Expand Down
2 changes: 1 addition & 1 deletion docs/autogen_config.py
Expand Up @@ -37,7 +37,7 @@
"""
try:
destination = os.path.join(os.path.dirname(__file__), "source/other/full-config.rst")
except:
except BaseException:
destination = os.path.join(os.getcwd(), "full-config.rst")

with open(destination, "w") as f:
Expand Down
11 changes: 0 additions & 11 deletions docs/source/conf.py
Expand Up @@ -279,17 +279,6 @@

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Latex figure (float) alignment
#'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/jupyter_server_config.py
Expand Up @@ -2,5 +2,5 @@
# ------------------------------------------------------------------------------
# Application(SingletonConfigurable) configuration
# ------------------------------------------------------------------------------
## The date format used by logging formatters for %(asctime)s
# The date format used by logging formatters for %(asctime)s
c.Application.log_datefmt = "%Y-%m-%d %H:%M:%S Simple_Extensions_Example"
2 changes: 1 addition & 1 deletion examples/simple/pytest.ini
@@ -1,3 +1,3 @@
[pytest]
# Disable any upper exclusion.
norecursedirs =
norecursedirs =
2 changes: 1 addition & 1 deletion examples/simple/simple_ext11/application.py
Expand Up @@ -57,7 +57,7 @@ def simple11_dir_formatted(self):

def initialize_settings(self):
self.log.info("hello: {}".format(self.hello))
if self.hello == True:
if self.hello is True:
self.log.info(
"Hello Simple11: You have launched with --hello flag or defined 'c.SimpleApp1.hello == True' in your config file"
)
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/auth/login.py
Expand Up @@ -229,10 +229,10 @@ def validate_security(cls, app, ssl_options=None):
if not app.ip:
warning = "WARNING: The Jupyter server is listening on all IP addresses"
if ssl_options is None:
app.log.warning(warning + " and not using encryption. This " "is not recommended.")
app.log.warning(f"{warning} and not using encryption. This is not recommended.")
if not app.password and not app.token:
app.log.warning(
warning + " and not using authentication. "
f"{warning} and not using authentication. "
"This is highly insecure and not recommended."
)
else:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/auth/logout.py
Expand Up @@ -11,7 +11,7 @@ def get(self):
if self.login_available:
message = {"info": "Successfully logged out."}
else:
message = {"warning": "Cannot log out. Jupyter Server authentication " "is disabled."}
message = {"warning": "Cannot log out. Jupyter Server authentication is disabled."}
self.write(self.render_template("logout.html", message=message))


Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/auth/security.py
Expand Up @@ -48,7 +48,7 @@ def passwd(passphrase=None, algorithm="argon2"):
"""
if passphrase is None:
for i in range(3):
for _ in range(3):
p0 = getpass.getpass("Enter password: ")
p1 = getpass.getpass("Verify password: ")
if p0 == p1:
Expand Down Expand Up @@ -161,7 +161,7 @@ def persist_config(config_file=None, mode=0o600):

try:
os.chmod(config_file, mode)
except Exception as e:
except Exception:
tb = traceback.format_exc()
warnings.warn("Failed to set permissions on %s:\n%s" % (config_file, tb), RuntimeWarning)

Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/base/handlers.py
Expand Up @@ -454,7 +454,7 @@ def check_xsrf_cookie(self):
return
try:
return super(JupyterHandler, self).check_xsrf_cookie()
except web.HTTPError as e:
except web.HTTPError:
if self.request.method in {"GET", "HEAD"}:
# Consider Referer a sufficient cross-origin check for GET requests
if not self.check_referer():
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/extension/application.py
Expand Up @@ -543,7 +543,7 @@ def load_classic_server_extension(cls, serverapp):
extension.initialize()

@classmethod
def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
def initialize_server(cls, argv=None, load_other_extensions=True, **kwargs):
"""Creates an instance of ServerApp and explicitly sets
this extension to enabled=True (i.e. superceding disabling
found in other config from files).
Expand All @@ -560,7 +560,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
serverapp = ServerApp.instance(jpserver_extensions=jpserver_extensions, **kwargs)
serverapp.aliases.update(cls.aliases)
serverapp.initialize(
argv=argv,
argv=argv or [],
starter_extension=cls.name,
find_extensions=find_extensions,
)
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/extension/manager.py
Expand Up @@ -39,7 +39,7 @@ def _valid_metadata(self, proposed):
self._module_name = metadata["module"]
except KeyError:
raise ExtensionMetadataError(
"There is no 'module' key in the extension's " "metadata packet."
"There is no 'module' key in the extension's metadata packet."
)

try:
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/extension/serverextension.py
Expand Up @@ -337,7 +337,7 @@ def list_server_extensions(self):
version = extension.version
self.log.info(" {} {} {}".format(name, version, GREEN_OK))
except Exception as err:
self.log.warn(" {} {}".format(RED_X, err))
self.log.warning(" {} {}".format(RED_X, err))
# Add a blank line between paths.
self.log.info("")

Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/extension/utils.py
Expand Up @@ -26,9 +26,9 @@ def get_loader(obj, logger=None):
underscore prefix.
"""
try:
func = getattr(obj, "_load_jupyter_server_extension")
func = getattr(obj, "_load_jupyter_server_extension") # noqa B009
except AttributeError:
func = getattr(obj, "load_jupyter_server_extension")
func = getattr(obj, "load_jupyter_server_extension", None)
warnings.warn(
"A `_load_jupyter_server_extension` function was not "
"found in {name!s}. Instead, a `load_jupyter_server_extension` "
Expand Down
8 changes: 5 additions & 3 deletions jupyter_server/gateway/managers.py
Expand Up @@ -125,9 +125,11 @@ async def list_kernels(self, **kwargs):
# Remove any of our kernels that may have been culled on the gateway server
our_kernels = self._kernels.copy()
culled_ids = []
for kid, km in our_kernels.items():
for kid, _ in our_kernels.items():
if kid not in kernel_models:
self.log.warn(f"Kernel {kid} no longer active - probably culled on Gateway server.")
self.log.warning(
f"Kernel {kid} no longer active - probably culled on Gateway server."
)
self._kernels.pop(kid, None)
culled_ids.append(kid) # TODO: Figure out what do with these.
return list(kernel_models.values())
Expand Down Expand Up @@ -606,7 +608,7 @@ async def start_channels(self, shell=True, iopub=True, stdin=True, hb=True, cont
"channels",
)
# Gather cert info in case where ssl is desired...
ssl_options = dict()
ssl_options = {}
ssl_options["ca_certs"] = GatewayClient.instance().ca_certs
ssl_options["certfile"] = GatewayClient.instance().client_cert
ssl_options["keyfile"] = GatewayClient.instance().client_key
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/i18n/__init__.py
Expand Up @@ -52,7 +52,7 @@ def parse_accept_lang_header(accept_lang):
by_q[qvalue].append(lang)

res = []
for qvalue, langs in sorted(by_q.items()):
for _, langs in sorted(by_q.items()):
res.extend(sorted(langs))
return res

Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/i18n/babel_nbui.cfg
@@ -1,4 +1,4 @@
[jinja2: notebook/templates/**.html]
encoding = utf-8
[extractors]
[extractors]
jinja2 = jinja2.ext:babel_extract
2 changes: 1 addition & 1 deletion jupyter_server/nbconvert/handlers.py
Expand Up @@ -30,7 +30,7 @@

def find_resource_files(output_files_dir):
files = []
for dirpath, dirnames, filenames in os.walk(output_files_dir):
for dirpath, _, filenames in os.walk(output_files_dir):
files.extend([os.path.join(dirpath, f) for f in filenames])
return files

Expand Down
22 changes: 9 additions & 13 deletions jupyter_server/serverapp.py
Expand Up @@ -132,7 +132,6 @@
url_path_join,
check_pid,
url_escape,
pathname2url,
unix_socket_in_use,
urlencode_unix_socket_path,
fetch,
Expand Down Expand Up @@ -198,7 +197,7 @@ def random_ports(port, n):
"""
for i in range(min(5, n)):
yield port + i
for i in range(n - 5):
for _ in range(n - 5):
yield max(1, port + random.randint(-2 * n, 2 * n))


Expand Down Expand Up @@ -292,11 +291,7 @@ def init_settings(
)
sys_info = get_sys_info()

# If the user is running the server in a git directory, make the assumption
# that this is a dev install and suggest to the developer `npm run build:watch`.
base_dir = os.path.realpath(os.path.join(__file__, "..", ".."))
dev_mode = os.path.exists(os.path.join(base_dir, ".git"))

nbui = gettext.translation(
"nbui",
localedir=os.path.join(base_dir, "jupyter_server/i18n"),
Expand Down Expand Up @@ -423,7 +418,7 @@ def init_handlers(self, default_services, settings):
# for each handler required for gateway, locate its pattern
# in the current list and replace that entry...
gateway_handlers = load_handlers("jupyter_server.gateway.handlers")
for i, gwh in enumerate(gateway_handlers):
for _, gwh in enumerate(gateway_handlers):
for j, h in enumerate(handlers):
if gwh[0] == h[0]:
handlers[j] = (gwh[0], gwh[1])
Expand Down Expand Up @@ -517,7 +512,7 @@ def shutdown_server(server_info, timeout=5, log=None):
if log:
log.debug("POST request to %sapi/shutdown", url)

r = fetch(url, method="POST", headers={"Authorization": "token " + server_info["token"]})
fetch(url, method="POST", headers={"Authorization": "token " + server_info["token"]})
# Poll to see if it shut down.
for _ in range(timeout * 10):
if not check_pid(pid):
Expand Down Expand Up @@ -581,7 +576,7 @@ def _shutdown_or_exit(self, target_endpoint, server):
def _maybe_remove_unix_socket(socket_path):
try:
os.unlink(socket_path)
except (OSError, IOError):
except OSError:
pass

def start(self):
Expand Down Expand Up @@ -1293,7 +1288,7 @@ def _default_allow_remote(self):
tornado_settings = Dict(
config=True,
help=_i18n(
"Supply overrides for the tornado.web.Application that the " "Jupyter server uses."
"Supply overrides for the tornado.web.Application that the Jupyter server uses."
),
)

Expand Down Expand Up @@ -1948,7 +1943,6 @@ def init_webapp(self):
)
if self.ssl_options.get("ca_certs", False):
self.ssl_options.setdefault("cert_reqs", ssl.CERT_REQUIRED)
ssl_options = self.ssl_options

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

Expand Down Expand Up @@ -2655,8 +2649,10 @@ def launch_browser(self):

assembled_url, _ = self._prepare_browser_open()

b = lambda: browser.open(assembled_url, new=self.webbrowser_open_new)
threading.Thread(target=b).start()
def target():
browser.open(assembled_url, new=self.webbrowser_open_new)

threading.Thread(target=target).start()

def start_app(self):
super(ServerApp, self).start()
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/services/contents/fileio.py
Expand Up @@ -113,7 +113,7 @@ def atomic_writing(path, text=True, encoding="utf-8", log=None, **kwargs):

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

try:
yield fileobj
except:
except BaseException:
fileobj.close()
raise

Expand Down Expand Up @@ -219,7 +219,7 @@ def perm_to_403(self, os_path=""):
"""context manager for turning permission errors into 403."""
try:
yield
except (OSError, IOError) as e:
except OSError as e:
if e.errno in {errno.EPERM, errno.EACCES}:
# make 403 error message without root prefix
# this may not work perfectly on unicode paths on Python 2,
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/services/contents/filemanager.py
Expand Up @@ -500,7 +500,7 @@ def is_non_empty_dir(os_path):
return
else:
self.log.warning(
"Skipping trash for %s, on different device " "to home directory",
"Skipping trash for %s, on different device to home directory",
os_path,
)

Expand Down Expand Up @@ -833,7 +833,7 @@ async def is_non_empty_dir(os_path):
return
else:
self.log.warning(
"Skipping trash for %s, on different device " "to home directory",
"Skipping trash for %s, on different device to home directory",
os_path,
)

Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/manager.py
Expand Up @@ -505,7 +505,7 @@ def validate_notebook_model(self, model, validation_error=None):
validate_nb(model["content"])
except ValidationError as e:
model["message"] = "Notebook validation failed: {}:\n{}".format(
e.message,
str(e),
json.dumps(e.instance, indent=1, default=lambda obj: "<UNKNOWN>"),
)
return model
Expand Down

0 comments on commit 7fbaa76

Please sign in to comment.