Skip to content

Commit b1f2a99

Browse files
authored
Fix Server Version Handling and Clean up CI (#71)
1 parent 2a489a8 commit b1f2a99

File tree

9 files changed

+36
-48
lines changed

9 files changed

+36
-48
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ jobs:
4545
uses: actions/checkout@v3
4646
- name: Base Setup
4747
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
48+
- name: Run the tests on pypy
49+
if: ${{ startsWith(matrix.python-version, 'pypy') }}
50+
run: |
51+
hatch run test:nowarn || hatch run test:nowarn --lf
4852
- name: Run the tests
53+
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
4954
run: |
5055
hatch run cov:test --cov-fail-under 75 || hatch run test:test --lf
5156
- name: Coverage

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
- id: black
3737

3838
- repo: https://github.com/charliermarsh/ruff-pre-commit
39-
rev: v0.0.165
39+
rev: v0.0.181
4040
hooks:
4141
- id: ruff
4242
args: ["--fix"]

jupyter_server_terminals/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from ._version import __version__ # noqa:F401
22

33
try:
4-
from .app import TerminalsExtensionApp
4+
from jupyter_server._version import version_info
55
except ModuleNotFoundError:
6-
import warnings
6+
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
77

8-
warnings.warn("Could not import submodules")
8+
if int(version_info[0]) < 2: # type:ignore
9+
raise RuntimeError("Jupyter Server Terminals requires Jupyter Server 2.0+")
10+
11+
from .app import TerminalsExtensionApp
912

1013

1114
def _jupyter_server_extension_points(): # pragma: no cover

jupyter_server_terminals/api_handlers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
from pathlib import Path
33
from typing import Optional
44

5+
from jupyter_server.auth.decorator import authorized
6+
from jupyter_server.base.handlers import APIHandler
57
from tornado import web
68

79
from .base import TerminalsMixin
810

9-
try:
10-
from jupyter_server.auth.decorator import authorized
11-
from jupyter_server.base.handlers import APIHandler
12-
except ModuleNotFoundError:
13-
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
14-
15-
1611
AUTH_RESOURCE = "terminals"
1712

1813

jupyter_server_terminals/app.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
import sys
44
from shutil import which
55

6+
from jupyter_core.utils import ensure_async
7+
from jupyter_server.extension.application import ExtensionApp
8+
from jupyter_server.transutils import trans
69
from traitlets import Type
710

811
from . import api_handlers, handlers
912
from .terminalmanager import TerminalManager
1013

11-
try:
12-
from jupyter_core.utils import ensure_async
13-
from jupyter_server.extension.application import ExtensionApp
14-
from jupyter_server.transutils import trans
15-
except ModuleNotFoundError:
16-
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
17-
1814

1915
class TerminalsExtensionApp(ExtensionApp):
2016

jupyter_server_terminals/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
try:
2-
from jupyter_server.extension.handler import ExtensionHandlerMixin
3-
except ModuleNotFoundError:
4-
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
1+
from jupyter_server.extension.handler import ExtensionHandlerMixin
52

63

74
class TerminalsMixin(ExtensionHandlerMixin):

jupyter_server_terminals/handlers.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
"""Tornado handlers for the terminal emulator."""
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
4+
from jupyter_server._tz import utcnow
5+
from jupyter_server.auth.utils import warn_disabled_authorization
6+
from jupyter_server.base.handlers import JupyterHandler
7+
from jupyter_server.base.websocket import WebSocketMixin
48
from terminado.websocket import TermSocket as BaseTermSocket
59
from tornado import web
610

711
from .base import TerminalsMixin
812

9-
try:
10-
from jupyter_server._tz import utcnow
11-
from jupyter_server.auth.utils import warn_disabled_authorization
12-
from jupyter_server.base.handlers import JupyterHandler
13-
from jupyter_server.base.websocket import WebSocketMixin
14-
except ModuleNotFoundError:
15-
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
16-
1713
AUTH_RESOURCE = "terminals"
1814

1915

jupyter_server_terminals/terminalmanager.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
# Distributed under the terms of the Modified BSD License.
77
from datetime import timedelta
88

9+
from jupyter_server._tz import isoformat, utcnow
10+
from jupyter_server.prometheus.metrics import ( # type:ignore[attr-defined]
11+
TERMINAL_CURRENTLY_RUNNING_TOTAL,
12+
)
913
from terminado.management import NamedTermManager
1014
from tornado import web
1115
from tornado.ioloop import IOLoop, PeriodicCallback
1216
from traitlets import Integer
1317
from traitlets.config import LoggingConfigurable
1418

15-
try:
16-
from jupyter_server._tz import isoformat, utcnow
17-
from jupyter_server.prometheus.metrics import ( # type:ignore[attr-defined]
18-
TERMINAL_CURRENTLY_RUNNING_TOTAL,
19-
)
20-
except ModuleNotFoundError:
21-
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.") from None
22-
2319

2420
class TerminalManager(LoggingConfigurable, NamedTermManager): # type:ignore[misc]
2521
""" """

pyproject.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ docs = [
5555
"sphinxcontrib_github_alt",
5656
"sphinxemoji",
5757
]
58-
lint = [
59-
"black[jupyter]>=22.6.0",
60-
"mdformat>0.7",
61-
"mdformat-gfm>=0.3.5",
62-
"ruff>=0.0.156"
63-
]
64-
typing = ["mypy>=0.990"]
6558

6659
[tool.hatch.version]
6760
path = "jupyter_server_terminals/_version.py"
@@ -88,12 +81,19 @@ test = "python -m pytest -vv --cov jupyter_server_terminals --cov-branch --cov-r
8881
nowarn = "test -W default {args}"
8982

9083
[tool.hatch.envs.typing]
91-
features = ["typing", "test"]
84+
features = ["test"]
85+
dependencies = ["mypy>=0.990"]
9286
[tool.hatch.envs.typing.scripts]
9387
test = "mypy --install-types --non-interactive {args:jupyter_server_terminals tests}"
9488

9589
[tool.hatch.envs.lint]
96-
features = ["lint"]
90+
dependencies = [
91+
"black[jupyter]==22.10.0",
92+
"mdformat>0.7",
93+
"mdformat-gfm>=0.3.5",
94+
"ruff==0.0.181"
95+
]
96+
detached = true
9797
[tool.hatch.envs.lint.scripts]
9898
style = [
9999
"ruff {args:.}",
@@ -163,7 +163,7 @@ ignore = [
163163
# Line too long
164164
"E501",
165165
# Relative imports are banned
166-
"I252",
166+
"TID252",
167167
# Boolean ... in function definition
168168
"FBT001", "FBT002",
169169
# Module level import not at top of file

0 commit comments

Comments
 (0)