Skip to content

Commit

Permalink
Merge branch 'main' into revert-1346-revert-1341-forward-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 6, 2023
2 parents 4b9b411 + 5c5b501 commit 9aacc95
Show file tree
Hide file tree
Showing 47 changed files with 188 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
hatch run lint:build
pipx run interrogate -v .
pipx run doc8 --max-line-length=200 --ignore-path=docs/source/other/full-config.rst
npm install -g eslint
Expand Down
21 changes: 13 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-ast
Expand Down Expand Up @@ -44,11 +44,6 @@ repos:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
Expand All @@ -62,14 +57,24 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
hooks:
- id: mypy
files: jupyter_server
stages: [manual]
additional_dependencies:
["traitlets>=5.13", "jupyter_core>=5.5", "jupyter_client>=8.5"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/scientific-python/cookie
rev: "2023.09.21"
rev: "2023.10.27"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.

<!-- <START NEW CHANGELOG ENTRY> -->

## 2.9.1

([Full Changelog](https://github.com/jupyter-server/jupyter_server/compare/v2.9.0...bb293ec5cac5b277259f27e458da60fa8a926f46))

### Bugs fixed

- Revert "Update kernel env to reflect changes in session." [#1346](https://github.com/jupyter-server/jupyter_server/pull/1346) ([@blink1073](https://github.com/blink1073))

### Contributors to this release

([GitHub contributors page for this release](https://github.com/jupyter-server/jupyter_server/graphs/contributors?from=2023-10-25&to=2023-10-25&type=c))

[@blink1073](https://github.com/search?q=repo%3Ajupyter-server%2Fjupyter_server+involves%3Ablink1073+updated%3A2023-10-25..2023-10-25&type=Issues)

<!-- <END NEW CHANGELOG ENTRY> -->

## 2.9.0

([Full Changelog](https://github.com/jupyter-server/jupyter_server/compare/v2.8.0...3438ddb16575155e98fc4f49700fff420088c8b0))
Expand All @@ -23,8 +39,6 @@ All notable changes to this project will be documented in this file.

[@akshaychitneni](https://github.com/search?q=repo%3Ajupyter-server%2Fjupyter_server+involves%3Aakshaychitneni+updated%3A2023-10-16..2023-10-25&type=Issues) | [@Carreau](https://github.com/search?q=repo%3Ajupyter-server%2Fjupyter_server+involves%3ACarreau+updated%3A2023-10-16..2023-10-25&type=Issues) | [@ojarjur](https://github.com/search?q=repo%3Ajupyter-server%2Fjupyter_server+involves%3Aojarjur+updated%3A2023-10-16..2023-10-25&type=Issues)

<!-- <END NEW CHANGELOG ENTRY> -->

## 2.8.0

([Full Changelog](https://github.com/jupyter-server/jupyter_server/compare/v2.7.3...a984e0771da5db4a14e9ac86a392ad3592b863e5))
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ Some of the hooks only run on CI by default, but you can invoke them by
running with the ``--hook-stage manual`` argument.

There are three hatch scripts that can be run locally as well:
``hatch run lint:style`` will check styling. ``hatch run lint:fmt``
will attempt to auto-format files. ``hatch run typing:test`` will
``hatch run lint:build`` will enforce styling. ``hatch run typing:test`` will
run the type checker.

Troubleshooting the Installation
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
html_theme_options = {"navigation_with_keys": False}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down
2 changes: 1 addition & 1 deletion examples/identity/system_password/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pwd
from getpass import getuser

from pamela import PAMError, authenticate # type:ignore[import-not-found]
from pamela import PAMError, authenticate

from jupyter_server.auth.identity import IdentityProvider, User

Expand Down
19 changes: 12 additions & 7 deletions jupyter_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
JUPYTER_SERVER_EVENTS_URI = "https://events.jupyter.org/jupyter_server"
DEFAULT_EVENTS_SCHEMA_PATH = pathlib.Path(__file__).parent / "event_schemas"

del os
from ._version import __version__, version_info
from .base.call_context import CallContext

from ._version import __version__, version_info # noqa
from .base.call_context import CallContext # noqa


def _cleanup():
pass
__all__ = [
"DEFAULT_STATIC_FILES_PATH",
"DEFAULT_TEMPLATE_PATH_LIST",
"DEFAULT_JUPYTER_SERVER_PORT",
"JUPYTER_SERVER_EVENTS_URI",
"DEFAULT_EVENTS_SCHEMA_PATH",
"__version__",
"version_info",
"CallContext",
]
20 changes: 7 additions & 13 deletions jupyter_server/_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

from datetime import datetime, timedelta, tzinfo
from typing import Callable
from datetime import datetime, timedelta, timezone, tzinfo

# constant for zero offset
ZERO = timedelta(0)
Expand All @@ -26,21 +25,16 @@ def dst(self, d: datetime | None) -> timedelta:
return ZERO


UTC = tzUTC() # type:ignore[abstract]

def utcnow() -> datetime:
"""Return timezone-aware UTC timestamp"""
return datetime.now(timezone.utc)

def utc_aware(unaware: Callable[..., datetime]) -> Callable[..., datetime]:
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""

def utc_method(*args, **kwargs):
dt = unaware(*args, **kwargs)
return dt.replace(tzinfo=UTC)
def utcfromtimestamp(timestamp):
return datetime.fromtimestamp(timestamp, timezone.utc)

return utc_method


utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
utcnow = utc_aware(datetime.utcnow)
UTC = tzUTC() # type:ignore[abstract]


def isoformat(dt: datetime) -> str:
Expand Down
8 changes: 4 additions & 4 deletions jupyter_server/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .authorizer import * # noqa
from .decorator import authorized # noqa
from .identity import * # noqa
from .security import passwd # noqa
from .authorizer import * # noqa: F403
from .decorator import authorized # noqa: F401
from .identity import * # noqa: F403
from .security import passwd # noqa: F401
2 changes: 1 addition & 1 deletion jupyter_server/auth/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from jupyter_core.paths import jupyter_config_dir
from traitlets.log import get_logger

from jupyter_server.auth import passwd
from jupyter_server.auth import passwd # type:ignore[attr-defined]
from jupyter_server.config_manager import BaseJSONConfigManager


Expand Down
3 changes: 2 additions & 1 deletion jupyter_server/auth/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from contextlib import contextmanager

from jupyter_core.paths import jupyter_config_dir
from traitlets.config import Config, ConfigFileNotFound, JSONFileConfigLoader
from traitlets.config import Config
from traitlets.config.loader import ConfigFileNotFound, JSONFileConfigLoader

# Length of the salt in nr of hex chars, which implies salt_len * 4
# bits of randomness.
Expand Down
8 changes: 3 additions & 5 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from jupyter_server import CallContext
from jupyter_server._sysinfo import get_sys_info
from jupyter_server._tz import utcnow
from jupyter_server.auth import authorized
from jupyter_server.auth.decorator import authorized
from jupyter_server.i18n import combine_translations
from jupyter_server.services.security import csp_report_uri
from jupyter_server.utils import (
Expand Down Expand Up @@ -611,7 +611,7 @@ async def prepare(self) -> Awaitable[None] | None: # type:ignore[override]
warnings.warn( # noqa
"Overriding JupyterHandler.get_current_user is deprecated in jupyter-server 2.0."
" Use an IdentityProvider class.",
DeprecationWarning
DeprecationWarning,
# stacklevel not useful here
)
user = User(self.get_current_user())
Expand Down Expand Up @@ -993,9 +993,7 @@ def initialize(
if isinstance(path, str):
path = [path]

self.root = tuple(
os.path.abspath(os.path.expanduser(p)) + os.sep for p in path
) # type:ignore[assignment]
self.root = tuple(os.path.abspath(os.path.expanduser(p)) + os.sep for p in path) # type:ignore[assignment]
self.default_filename = default_filename

def compute_etag(self) -> str | None:
Expand Down
21 changes: 16 additions & 5 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""An extension application."""
from __future__ import annotations

import logging
import re
import sys
Expand Down Expand Up @@ -158,19 +160,21 @@ class method. This method can be set as a entry_point in

@default("open_browser")
def _default_open_browser(self):
assert self.serverapp is not None
return self.serverapp.config["ServerApp"].get("open_browser", True)

@property
def config_file_paths(self):
"""Look on the same path as our parent for config files"""
# rely on parent serverapp, which should control all config loading
assert self.serverapp is not None
return self.serverapp.config_file_paths

# The extension name used to name the jupyter config
# file, jupyter_{name}_config.
# This should also match the jupyter subcommand used to launch
# this extension from the CLI, e.g. `jupyter {name}`.
name: t.Union[str, Unicode] = "ExtensionApp" # type:ignore[assignment]
name: str | Unicode = "ExtensionApp" # type:ignore[assignment]

@classmethod
def get_extension_package(cls):
Expand Down Expand Up @@ -206,7 +210,7 @@ def _default_url(self):
]

# A ServerApp is not defined yet, but will be initialized below.
serverapp = Any()
serverapp: ServerApp | None = Any() # type:ignore[assignment]

@default("serverapp")
def _default_serverapp(self):
Expand Down Expand Up @@ -242,6 +246,7 @@ def _default_log_format(self):
@default("static_url_prefix")
def _default_static_url_prefix(self):
static_url = f"static/{self.name}/"
assert self.serverapp is not None
return url_path_join(self.serverapp.base_url, static_url)

static_paths = List(
Expand All @@ -264,7 +269,9 @@ def _default_static_url_prefix(self):

settings = Dict(help=_i18n("""Settings that will passed to the server.""")).tag(config=True)

handlers = List(help=_i18n("""Handlers appended to the server.""")).tag(config=True)
handlers: List[tuple[t.Any, ...]] = List(
help=_i18n("""Handlers appended to the server.""")
).tag(config=True) # type:ignore[assignment]

def _config_file_name_default(self):
"""The default config file name."""
Expand Down Expand Up @@ -295,6 +302,7 @@ def _prepare_config(self):
def _prepare_settings(self):
"""Prepare the settings."""
# Make webapp settings accessible to initialize_settings method
assert self.serverapp is not None
webapp = self.serverapp.web_app
self.settings.update(**webapp.settings)

Expand All @@ -314,6 +322,7 @@ def _prepare_settings(self):

def _prepare_handlers(self):
"""Prepare the handlers."""
assert self.serverapp is not None
webapp = self.serverapp.web_app

# Get handlers defined by extension subclass.
Expand Down Expand Up @@ -352,7 +361,7 @@ def _prepare_handlers(self):
)
new_handlers.append(handler)

webapp.add_handlers(".*$", new_handlers)
webapp.add_handlers(".*$", new_handlers) # type:ignore[arg-type]

def _prepare_templates(self):
"""Add templates to web app settings if extension has templates."""
Expand All @@ -372,7 +381,7 @@ def _jupyter_server_config(self):
base_config["ServerApp"].update(self.serverapp_config)
return base_config

def _link_jupyter_server_extension(self, serverapp):
def _link_jupyter_server_extension(self, serverapp: ServerApp) -> None:
"""Link the ExtensionApp to an initialized ServerApp.
The ServerApp is stored as an attribute and config
Expand Down Expand Up @@ -436,6 +445,7 @@ def start(self):
"""
super().start()
# Start the server.
assert self.serverapp is not None
self.serverapp.start()

def current_activity(self):
Expand All @@ -447,6 +457,7 @@ async def stop_extension(self):

def stop(self):
"""Stop the underlying Jupyter server."""
assert self.serverapp is not None
self.serverapp.stop()
self.serverapp.clear_instance()

Expand Down
2 changes: 2 additions & 0 deletions jupyter_server/extension/manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""The extension manager."""
from __future__ import annotations

import importlib

from tornado.gen import multi
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/extension/serverextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def list_server_extensions(self) -> None:
self.log.info(f" {name} {version} {GREEN_OK}")
except Exception as err:
exc_info = False
if int(self.log_level) <= logging.DEBUG:
if int(self.log_level) <= logging.DEBUG: # type:ignore[call-overload]
exc_info = True
self.log.warning(f" {RED_X} {err}", exc_info=exc_info)
# Add a blank line between paths.
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from jupyter_core.utils import ensure_async
from tornado import web

from jupyter_server.auth import authorized
from jupyter_server.auth.decorator import authorized
from jupyter_server.base.handlers import JupyterHandler

AUTH_RESOURCE = "contents"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/gateway/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from ..services.kernels.connection.base import BaseKernelWebsocketConnection
from ..utils import url_path_join
from .managers import GatewayClient
from .gateway_client import GatewayClient


class GatewayWebSocketConnection(BaseKernelWebsocketConnection):
Expand Down
6 changes: 2 additions & 4 deletions jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _gateway_retry_max_default(self):
)
gateway_token_renewer_class_env = "JUPYTER_GATEWAY_TOKEN_RENEWER_CLASS"
gateway_token_renewer_class = Type(
klass=GatewayTokenRenewerBase, # type:ignore[type-abstract]
klass=GatewayTokenRenewerBase,
config=True,
help="""The class to use for Gateway token renewal. (JUPYTER_GATEWAY_TOKEN_RENEWER_CLASS env var)""",
)
Expand Down Expand Up @@ -546,9 +546,7 @@ def __init__(self, **kwargs):
"""Initialize a gateway client."""
super().__init__(**kwargs)
self._connection_args = {} # initialized on first use
self.gateway_token_renewer = self.gateway_token_renewer_class(
parent=self, log=self.log
) # type:ignore[operator]
self.gateway_token_renewer = self.gateway_token_renewer_class(parent=self, log=self.log) # type:ignore[abstract]

# store of cookies with store time
self._cookies: ty.Dict[str, ty.Tuple[Morsel, datetime]] = {}
Expand Down
Loading

0 comments on commit 9aacc95

Please sign in to comment.