Skip to content

Commit 0ba4fc9

Browse files
authored
Merge pull request #2 from Zsailer/extensionapp
2 parents 79fd576 + 8611d31 commit 0ba4fc9

File tree

17 files changed

+239
-162
lines changed

17 files changed

+239
-162
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 72 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches: ["main"]
55
pull_request:
6+
67
schedule:
78
- cron: "0 8 * * *"
89

@@ -33,15 +34,18 @@ jobs:
3334
3435
test:
3536
runs-on: ${{ matrix.os }}
37+
timeout-minutes: 10
3638
strategy:
3739
fail-fast: false
3840
matrix:
39-
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
40-
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
41-
exclude:
42-
- os: "windows-latest"
43-
python-version: "pypy-3.7"
44-
- os: "macos-latest"
41+
os: [ubuntu-latest, windows-latest, macos-latest]
42+
python-version: ["3.7", "3.10"]
43+
include:
44+
- os: windows-latest
45+
python-version: "3.9"
46+
- os: ubuntu-latest
47+
python-version: "pypy-3.8"
48+
- os: macos-latest
4549
python-version: "3.8"
4650
steps:
4751
- name: Checkout
@@ -51,28 +55,40 @@ jobs:
5155
- name: Install the Python dependencies
5256
run: |
5357
pip install -e ".[test]" codecov
58+
- name: Point at Jupyter Server branch with terminals removed.
59+
run: |
60+
pip install -U git+https://github.com/Zsailer/jupyter_server.git@jupyter_server_terminals
5461
- name: List installed packages
5562
run: |
5663
pip freeze
5764
pip check
5865
- name: Run the tests with Coverage
5966
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
6067
run: |
61-
pytest -vv jupyter_server_terminals --cov jupyter_server_terminals --cov-branch --cov-report term-missing:skip-covered
68+
python -m pytest -vv --cov jupyter_server_terminals --cov-branch --cov-report term-missing:skip-covered
6269
- name: Run the tests on pypy and Windows
6370
if: ${{ startsWith(matrix.python-version, 'pypy') || startsWith(runner.os, 'Windows') }}
6471
run: |
65-
pytest -vv jupyter_server_terminals
72+
python -m pytest -vv
6673
- name: Coverage
6774
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
6875
run: |
6976
codecov
70-
- name: Test full install
71-
if: ${{ !startsWith(matrix.python-version, 'pypy') && !startsWith(runner.os, 'Windows') }}
72-
run: |
73-
python -m venv test_install
74-
./test_install/bin/python -m pip install -U pip
75-
./test_install/bin/python -m pip install ".[test]"
76-
pushd test_install
77-
./bin/pytest --pyargs jupyter_server_terminals
78-
popd
77+
78+
make_sdist:
79+
name: Make SDist
80+
runs-on: ubuntu-latest
81+
timeout-minutes: 10
82+
steps:
83+
- uses: actions/checkout@v2
84+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
85+
- uses: jupyterlab/maintainer-tools/.github/actions/make-sdist@v1
86+
87+
# test_sdist:
88+
# runs-on: ubuntu-latest
89+
# needs: [make_sdist]
90+
# name: Install from SDist and Test
91+
# timeout-minutes: 15
92+
# steps:
93+
# - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
94+
# - uses: jupyterlab/maintainer-tools/.github/actions/test-sdist@v1

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
repos:
22
- repo: https://github.com/asottile/reorder_python_imports
3-
rev: v1.9.0
3+
rev: v3.0.1
44
hooks:
55
- id: reorder-python-imports
66
- repo: https://github.com/psf/black
7-
rev: 20.8b1
7+
rev: 22.3.0
88
hooks:
99
- id: black
1010
args: ["--line-length", "100"]
1111
- repo: https://gitlab.com/pycqa/flake8
12-
rev: "3.8.4"
12+
rev: "3.9.2"
1313
hooks:
1414
- id: flake8
1515
- repo: https://github.com/pre-commit/pre-commit-hooks
16-
rev: v3.4.0
16+
rev: v4.1.0
1717
hooks:
1818
- id: end-of-file-fixer
1919
- id: check-case-conflict

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ include CONTRIBUTING.rst
33
include README.md
44
include RELEASE.md
55
include CHANGELOG.md
6+
include pyproject.toml
67

78
# include everything in package_data
89
recursive-include jupyter_server_terminals *
910

11+
recursive-include tests *
12+
1013
# Documentation
1114
graft docs
1215
exclude docs/\#*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ServerApp": {
3+
"jpserver_extensions": {
4+
"jupyter_server_terminals": true
5+
}
6+
}
7+
}
Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,10 @@
1-
import os
2-
import sys
3-
from shutil import which
1+
from .app import TerminalsExtensionApp
42

5-
from jupyter_server.utils import url_path_join as ujoin
63

7-
from . import api_handlers
8-
from .handlers import TermSocket
9-
from .terminalmanager import TerminalManager
10-
11-
version_info = (0, 1, 0, ".dev", "0")
12-
__version__ = ".".join(map(str, version_info[:3])) + "".join(version_info[3:])
13-
14-
15-
def initialize(webapp, root_dir, connection_url, settings):
16-
if os.name == "nt":
17-
default_shell = "powershell.exe"
18-
else:
19-
default_shell = which("sh")
20-
shell_override = settings.get("shell_command")
21-
shell = [os.environ.get("SHELL") or default_shell] if shell_override is None else shell_override
22-
# When the notebook server is not running in a terminal (e.g. when
23-
# it's launched by a JupyterHub spawner), it's likely that the user
24-
# environment hasn't been fully set up. In that case, run a login
25-
# shell to automatically source /etc/profile and the like, unless
26-
# the user has specifically set a preferred shell command.
27-
if os.name != "nt" and shell_override is None and not sys.stdout.isatty():
28-
shell.append("-l")
29-
terminal_manager = webapp.settings["terminal_manager"] = TerminalManager(
30-
shell_command=shell,
31-
extra_env={
32-
"JUPYTER_SERVER_ROOT": root_dir,
33-
"JUPYTER_SERVER_URL": connection_url,
4+
def _jupyter_server_extension_points(): # pragma: no cover
5+
return [
6+
{
7+
"module": "jupyter_server_terminals.app",
8+
"app": TerminalsExtensionApp,
349
},
35-
parent=webapp.settings["serverapp"],
36-
)
37-
terminal_manager.log = webapp.settings["serverapp"].log
38-
base_url = webapp.settings["base_url"]
39-
handlers = [
40-
(
41-
ujoin(base_url, r"/terminals/websocket/(\w+)"),
42-
TermSocket,
43-
{"term_manager": terminal_manager},
44-
),
45-
(ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
46-
(ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
4710
]
48-
webapp.add_handlers(".*$", handlers)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0.dev0"

jupyter_server_terminals/api_handlers.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import json
22

3-
from jupyter_server.base.handlers import APIHandler
43
from tornado import web
54

5+
from .base import TerminalsMixin
66

7-
class TerminalRootHandler(APIHandler):
7+
try:
8+
from jupyter_server.base.handlers import APIHandler
9+
except ModuleNotFoundError:
10+
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.")
11+
12+
13+
class TerminalRootHandler(TerminalsMixin, APIHandler):
814
@web.authenticated
915
def get(self):
1016
models = self.terminal_manager.list()
@@ -19,7 +25,7 @@ def post(self):
1925
self.finish(json.dumps(model))
2026

2127

22-
class TerminalHandler(APIHandler):
28+
class TerminalHandler(TerminalsMixin, APIHandler):
2329
SUPPORTED_METHODS = ("GET", "DELETE")
2430

2531
@web.authenticated
@@ -32,3 +38,9 @@ async def delete(self, name):
3238
await self.terminal_manager.terminate(name, force=True)
3339
self.set_status(204)
3440
self.finish()
41+
42+
43+
default_handlers = [
44+
(r"/api/terminals", TerminalRootHandler),
45+
(r"/api/terminals/(\w+)", TerminalHandler),
46+
]

0 commit comments

Comments
 (0)