[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2024-02-05 20:27:28 +00:00
parent 1171bdcef6
commit ef568e3d61
78 changed files with 91 additions and 15 deletions

View File

@@ -13,6 +13,7 @@ The files are:
This file is JupyterHub's REST API schema. Both a version and the RBAC
scopes descriptions are updated in it.
"""
import os
from collections import defaultdict
from pathlib import Path

View File

@@ -2,6 +2,7 @@
Example for a Spawner.pre_spawn_hook
create a directory for the user before the spawner starts
"""
# pylint: disable=import-error
import os
import shutil

View File

@@ -3,6 +3,7 @@
Implements OAuth handshake manually
so all URLs and requests necessary for OAuth with JupyterHub should be in one place
"""
import json
import os
from urllib.parse import urlencode, urlparse

View File

@@ -4,6 +4,7 @@ This example service serves `/services/whoami-oauth/`,
authenticated with the Hub,
showing the user their own info.
"""
import json
import os
from urllib.parse import urlparse

View File

@@ -4,6 +4,7 @@ This serves `/services/whoami-api/`, authenticated with the Hub, showing the use
HubAuthenticated only supports token-based access.
"""
import json
import os
from urllib.parse import urlparse

View File

@@ -1,6 +1,7 @@
"""
Example JupyterHub config allowing users to specify environment variables and notebook-server args
"""
import shlex
from jupyterhub.spawner import LocalProcessSpawner

View File

@@ -3,6 +3,7 @@
Note: a memoized function should always return an _immutable_
result to avoid later modifications polluting cached results.
"""
from collections import OrderedDict
from functools import wraps

View File

@@ -1,4 +1,5 @@
"""JupyterHub version info"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# version_info updated by running `tbump`

View File

@@ -5,6 +5,7 @@ Revises: 833da8570507
Create Date: 2021-09-15 14:04:09.067024
"""
# revision identifiers, used by Alembic.
revision = '0eee8c825d24'
down_revision = '651f5419b74d'

View File

@@ -5,6 +5,7 @@ Revises:
Create Date: 2016-04-11 16:05:34.873288
"""
# revision identifiers, used by Alembic.
revision = '19c0846f6344'
down_revision = None

View File

@@ -5,6 +5,7 @@ Revises: 3ec6993fe20c
Create Date: 2017-12-07 14:43:51.500740
"""
# revision identifiers, used by Alembic.
revision = '1cebaf56856c'
down_revision = '3ec6993fe20c'

View File

@@ -12,6 +12,7 @@ Revises: af4cbdb2d13c
Create Date: 2017-07-28 16:44:40.413648
"""
# revision identifiers, used by Alembic.
revision = '3ec6993fe20c'
down_revision = 'af4cbdb2d13c'

View File

@@ -5,6 +5,7 @@ Revises: 896818069c98
Create Date: 2019-02-28 14:14:27.423927
"""
# revision identifiers, used by Alembic.
revision = '4dc2d5a8c53c'
down_revision = '896818069c98'

View File

@@ -5,6 +5,7 @@ Revises: 1cebaf56856c
Create Date: 2017-12-19 15:21:09.300513
"""
# revision identifiers, used by Alembic.
revision = '56cc5a70207e'
down_revision = '1cebaf56856c'

View File

@@ -5,6 +5,7 @@ Revises: 833da8570507
Create Date: 2022-02-28 12:42:55.149046
"""
# revision identifiers, used by Alembic.
revision = '651f5419b74d'
down_revision = '833da8570507'

View File

@@ -6,6 +6,7 @@ Revises: 4dc2d5a8c53c
Create Date: 2021-02-17 15:03:04.360368
"""
# revision identifiers, used by Alembic.
revision = '833da8570507'
down_revision = '4dc2d5a8c53c'

View File

@@ -5,6 +5,7 @@ Revises: d68c98b66cd4
Create Date: 2018-05-07 11:35:58.050542
"""
# revision identifiers, used by Alembic.
revision = '896818069c98'
down_revision = 'd68c98b66cd4'

View File

@@ -5,6 +5,7 @@ Revises: 56cc5a70207e
Create Date: 2018-03-21 14:27:17.466841
"""
# revision identifiers, used by Alembic.
revision = '99a28a4418e1'
down_revision = '56cc5a70207e'

View File

@@ -5,6 +5,7 @@ Revises: eeb276e51423
Create Date: 2016-07-28 16:16:38.245348
"""
# revision identifiers, used by Alembic.
revision = 'af4cbdb2d13c'
down_revision = 'eeb276e51423'

View File

@@ -5,6 +5,7 @@ Revises: 99a28a4418e1
Create Date: 2018-04-13 10:50:17.968636
"""
# revision identifiers, used by Alembic.
revision = 'd68c98b66cd4'
down_revision = '99a28a4418e1'

View File

@@ -6,6 +6,7 @@ Revision ID: eeb276e51423
Revises: 19c0846f6344
Create Date: 2016-04-11 16:06:49.239831
"""
# revision identifiers, used by Alembic.
revision = 'eeb276e51423'
down_revision = '19c0846f6344'

View File

@@ -1,4 +1,5 @@
"""Authorization handlers"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""Base API handlers"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""Group handlers"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""API handlers for administering the Hub itself"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""Proxy handlers"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -2,6 +2,7 @@
Currently GET-only, no actions can be taken to modify services.
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""User handlers"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""Base Authenticator class and the default PAM Authenticator"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import inspect

View File

@@ -1,4 +1,5 @@
"""Database utilities for JupyterHub"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
# Based on pgcontents.utils.migrate, used under the Apache license.

View File

@@ -1,4 +1,5 @@
"""HTTP Handlers for the hub server"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""HTTP Handlers for the hub server"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""Handlers for serving prometheus metrics"""
from prometheus_client import CONTENT_TYPE_LATEST, REGISTRY, generate_latest
from ..utils import metrics_authentication

View File

@@ -1,4 +1,5 @@
"""Basic html-rendering handlers."""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""logging utilities"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -2,6 +2,7 @@
implements https://oauthlib.readthedocs.io/en/latest/oauth2/server.html
"""
from oauthlib import uri_validate
from oauthlib.oauth2 import RequestValidator, WebApplicationServer
from oauthlib.oauth2.rfc6749.grant_types import authorization_code, base

View File

@@ -1,4 +1,5 @@
"""Some general objects for use in JupyterHub"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import socket

View File

@@ -1,4 +1,5 @@
"""sqlalchemy ORM tools for the state of the constellation of processes"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import enum

View File

@@ -14,6 +14,7 @@ Route Specification:
'host.tld/path/' for host-based routing or '/path/' for default routing.
- Route paths should be normalized to always start and end with '/'
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""Roles utils"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import re

View File

@@ -14,6 +14,7 @@ intersection : set of expanded scopes as intersection of 2 expanded scope sets
identify scopes: set of expanded scopes needed for identify (whoami) endpoints
reduced scopes: expanded scopes that have been reduced
"""
import functools
import inspect
import re

View File

@@ -23,6 +23,7 @@ If you are using OAuth, you will also need to register an oauth callback handler
A tornado implementation is provided in :class:`HubOAuthCallbackHandler`.
"""
import asyncio
import hashlib
import json

View File

@@ -38,6 +38,7 @@ A hub-managed service with no URL::
}
"""
import asyncio
import copy
import os

View File

@@ -12,6 +12,7 @@ Application subclass can be controlled with environment variables:
- JUPYTERHUB_SINGLEUSER_EXTENSION=1 to opt-in to the extension (requires Jupyter Server 2)
- JUPYTERHUB_SINGLEUSER_APP=notebook (or jupyter-server) to opt-in
"""
import os
from .mixins import HubAuthenticatedHandler, make_singleuser_app

View File

@@ -8,6 +8,7 @@
Default app changed to launch `jupyter labhub`.
Use JUPYTERHUB_SINGLEUSER_APP='notebook' for the legacy 'classic' notebook server (requires notebook<7).
"""
import os
from traitlets import import_item

View File

@@ -613,9 +613,9 @@ class JupyterHubSingleUser(ExtensionApp):
jinja_template_vars['logo_url'] = self.hub_auth.hub_host + url_path_join(
self.hub_auth.hub_prefix, 'logo'
)
jinja_template_vars[
'hub_control_panel_url'
] = self.hub_auth.hub_host + url_path_join(self.hub_auth.hub_prefix, 'home')
jinja_template_vars['hub_control_panel_url'] = (
self.hub_auth.hub_host + url_path_join(self.hub_auth.hub_prefix, 'home')
)
_activity_task = None
@@ -628,9 +628,9 @@ class JupyterHubSingleUser(ExtensionApp):
super().initialize()
app = self.serverapp
app.web_app.settings[
"page_config_hook"
] = app.identity_provider.page_config_hook
app.web_app.settings["page_config_hook"] = (
app.identity_provider.page_config_hook
)
# if the user has configured a log function in the tornado settings, do not override it
if not 'log_function' in app.config.ServerApp.get('tornado_settings', {}):
app.web_app.settings["log_function"] = log_request

View File

@@ -734,9 +734,9 @@ class SingleUserNotebookAppMixin(Configurable):
)
self.jinja_template_vars['hub_host'] = self.hub_host
self.jinja_template_vars['hub_prefix'] = self.hub_prefix
self.jinja_template_vars[
'hub_control_panel_url'
] = self.hub_host + url_path_join(self.hub_prefix, 'home')
self.jinja_template_vars['hub_control_panel_url'] = (
self.hub_host + url_path_join(self.hub_prefix, 'home')
)
settings = self.web_app.settings
# patch classic notebook jinja env

View File

@@ -1,6 +1,7 @@
"""
Contains base Spawner class & default implementation
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import ast

View File

@@ -878,9 +878,11 @@ async def test_oauth_page(
user_scopes or ['(no_scope)'], user.name
)
desc_list_expected = [
(
f"{sd['description']} Applies to {sd['filter']}."
if sd.get('filter')
else sd['description']
)
for sd in scope_descriptions
]
assert sorted(desc_list_form) == sorted(desc_list_expected)

View File

@@ -23,6 +23,7 @@ Fixtures to add functionality or spawning behavior
- `slow_bad_spawn`
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -26,6 +26,7 @@ Other components
- public_url
"""
import asyncio
import os
import sys

View File

@@ -1,4 +1,5 @@
"""Example JupyterServer app subclass"""
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.serverapp import ServerApp
from tornado import web

View File

@@ -12,6 +12,7 @@ Handlers and their purpose include:
- WhoAmIHandler: returns name of user making a request (deprecated cookie login)
- OWhoAmIHandler: returns name of user making a request (OAuth login)
"""
import json
import os
import pprint

View File

@@ -11,6 +11,7 @@ Handlers and their purpose include:
- ArgsHandler: allowing retrieval of `sys.argv`.
"""
import json
import os
import sys

View File

@@ -4,6 +4,7 @@ Run with old versions of jupyterhub to test upgrade/downgrade
used in test_db.py
"""
from functools import partial
import jupyterhub

View File

@@ -1,4 +1,5 @@
"""Tests for the REST API."""
import asyncio
import json
import re

View File

@@ -1,4 +1,5 @@
"""Test the JupyterHub entry point"""
import asyncio
import binascii
import json

View File

@@ -1,4 +1,5 @@
"""Tests for PAM authentication"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging

View File

@@ -7,6 +7,7 @@ authentication can expire in a number of ways:
- doesn't need refresh
- needs refresh and cannot be refreshed without new login
"""
from unittest import mock
from urllib.parse import parse_qs, urlparse

View File

@@ -1,4 +1,5 @@
"""Tests for dummy authentication"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from jupyterhub.auth import DummyAuthenticator

View File

@@ -5,6 +5,7 @@ To test a new schema or event, simply add it to the
You *shouldn't* need to write new tests.
"""
import io
import json
import logging

View File

@@ -1,4 +1,5 @@
"""Tests for jupyterhub internal_ssl connections"""
import sys
import time
from unittest import mock

View File

@@ -1,4 +1,5 @@
"""Tests for named servers"""
import asyncio
import json
import time

View File

@@ -1,4 +1,5 @@
"""Tests for basic object-wrappers"""
import socket
import pytest

View File

@@ -1,4 +1,5 @@
"""Tests for the ORM bits"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import os

View File

@@ -1,4 +1,5 @@
"""Tests for HTML pages"""
import asyncio
import sys
from unittest import mock

View File

@@ -1,4 +1,5 @@
"""Test a proxy being started before the Hub"""
import json
import os
from contextlib import contextmanager

View File

@@ -1,4 +1,5 @@
"""Test roles"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json

View File

@@ -1,4 +1,5 @@
"""Test scopes for API handlers"""
from operator import itemgetter
from unittest import mock

View File

@@ -1,4 +1,5 @@
"""Tests for services"""
import os
import sys
from binascii import hexlify

View File

@@ -1,4 +1,5 @@
"""Tests for service authentication"""
import copy
import os
import sys

View File

@@ -1,4 +1,5 @@
"""Tests for jupyterhub.singleuser"""
import os
import sys
from contextlib import nullcontext

View File

@@ -1,4 +1,5 @@
"""Tests for process spawning"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio

View File

@@ -1,4 +1,5 @@
"""Tests for utilities"""
import asyncio
import time
from concurrent.futures import ThreadPoolExecutor

View File

@@ -1,4 +1,5 @@
"""Test version checking"""
import logging
import pytest

View File

@@ -1,6 +1,7 @@
"""
Traitlets that are used in JupyterHub
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import sys

View File

@@ -795,9 +795,9 @@ class User:
await spawner.run_auth_state_hook(auth_state)
# update spawner start time, and activity for both spawner and user
self.last_activity = (
spawner.orm_spawner.started
) = spawner.orm_spawner.last_activity = utcnow(with_tz=False)
self.last_activity = spawner.orm_spawner.started = (
spawner.orm_spawner.last_activity
) = utcnow(with_tz=False)
db.commit()
# wait for spawner.start to return
# run optional preparation work to bootstrap the notebook

View File

@@ -1,4 +1,5 @@
"""Miscellaneous utilities"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import asyncio