Skip to content

Commit c849eb0

Browse files
authored
Merge pull request #8 from blink1073/pre-commit
2 parents 0ba4fc9 + b809b0c commit c849eb0

File tree

10 files changed

+119
-77
lines changed

10 files changed

+119
-77
lines changed

.pre-commit-config.yaml

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,69 @@
1+
ci:
2+
skip: [check-jsonschema]
3+
14
repos:
2-
- repo: https://github.com/asottile/reorder_python_imports
3-
rev: v3.0.1
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.1.0
47
hooks:
5-
- id: reorder-python-imports
8+
- id: end-of-file-fixer
9+
- id: check-case-conflict
10+
- id: check-executables-have-shebangs
11+
- id: requirements-txt-fixer
12+
- id: check-added-large-files
13+
- id: check-case-conflict
14+
- id: check-toml
15+
- id: check-yaml
16+
- id: debug-statements
17+
- id: forbid-new-submodules
18+
- id: check-builtin-literals
19+
- id: trailing-whitespace
20+
621
- repo: https://github.com/psf/black
722
rev: 22.3.0
823
hooks:
924
- id: black
1025
args: ["--line-length", "100"]
11-
- repo: https://gitlab.com/pycqa/flake8
12-
rev: "3.9.2"
26+
27+
- repo: https://github.com/PyCQA/isort
28+
rev: 5.10.1
29+
hooks:
30+
- id: isort
31+
files: \.py$
32+
args: [--profile=black]
33+
34+
- repo: https://github.com/pre-commit/mirrors-prettier
35+
rev: v2.6.1
36+
hooks:
37+
- id: prettier
38+
39+
- repo: https://github.com/asottile/pyupgrade
40+
rev: v2.31.1
41+
hooks:
42+
- id: pyupgrade
43+
args: [--py37-plus]
44+
45+
- repo: https://github.com/PyCQA/doc8
46+
rev: 0.11.0
47+
hooks:
48+
- id: doc8
49+
args: [--max-line-length=200]
50+
51+
- repo: https://github.com/pycqa/flake8
52+
rev: 4.0.1
1353
hooks:
1454
- id: flake8
15-
- repo: https://github.com/pre-commit/pre-commit-hooks
16-
rev: v4.1.0
55+
additional_dependencies:
56+
[
57+
"flake8-bugbear==20.1.4",
58+
"flake8-logging-format==0.6.0",
59+
"flake8-implicit-str-concat==0.2.0",
60+
]
61+
62+
- repo: https://github.com/sirosen/check-jsonschema
63+
rev: 0.14.1
1764
hooks:
18-
- id: end-of-file-fixer
19-
- id: check-case-conflict
20-
- id: check-executables-have-shebangs
21-
- id: requirements-txt-fixer
65+
- id: check-jsonschema
66+
name: "Check GitHub Workflows"
67+
files: ^\.github/workflows/
68+
types: [yaml]
69+
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]

docs/source/conf.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# Jupyter Server documentation build configuration file, created by
54
# sphinx-quickstart on Mon Apr 13 09:51:11 2015.
@@ -269,16 +268,7 @@
269268

270269
# -- Options for LaTeX output ---------------------------------------------
271270

272-
latex_elements = {
273-
# The paper size ('letterpaper' or 'a4paper').
274-
#'papersize': 'letterpaper',
275-
# The font size ('10pt', '11pt' or '12pt').
276-
#'pointsize': '10pt',
277-
# Additional stuff for the LaTeX preamble.
278-
#'preamble': '',
279-
# Latex figure (float) alignment
280-
#'figure_align': 'htbp',
281-
}
271+
latex_elements = {}
282272

283273
# Grouping the document tree into LaTeX files. List of tuples
284274
# (source start file, target name, title,
@@ -328,7 +318,7 @@
328318

329319
# -- Options for link checks ----------------------------------------------
330320

331-
linkcheck_ignore = ["http://127\.0\.0\.1/*"]
321+
linkcheck_ignore = [r"http://127\.0\.0\.1/*"]
332322

333323

334324
# -- Options for Texinfo output -------------------------------------------
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"ServerApp": {
3-
"jpserver_extensions": {
4-
"jupyter_server_terminals": true
5-
}
2+
"ServerApp": {
3+
"jpserver_extensions": {
4+
"jupyter_server_terminals": true
65
}
6+
}
77
}

jupyter_server_terminals/app.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@
44

55
from traitlets import Type
66

7-
from . import api_handlers
8-
from . import handlers
7+
from . import api_handlers, handlers
98
from .terminalmanager import TerminalManager
109

1110
try:
1211
from jupyter_server.extension.application import ExtensionApp
13-
from jupyter_server.utils import run_sync_in_loop
1412
from jupyter_server.transutils import trans
15-
16-
# Tolerate missing terminado package.
17-
try:
18-
from .terminalmanager import TerminalManager
19-
20-
terminado_available = True
21-
except ImportError:
22-
terminado_available = False
23-
13+
from jupyter_server.utils import run_sync_in_loop
2414
except ModuleNotFoundError:
2515
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.")
2616

@@ -44,9 +34,7 @@ class TerminalsExtensionApp(ExtensionApp):
4434

4535
def initialize_settings(self):
4636
self.initialize_configurables()
47-
self.settings.update(
48-
dict(terminals_available=terminado_available, terminal_manager=self.terminal_manager)
49-
)
37+
self.settings.update(dict(terminals_available=True, terminal_manager=self.terminal_manager))
5038

5139
def initialize_configurables(self):
5240
if os.name == "nt":

jupyter_server_terminals/handlers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: utf-8
21
"""Tornado handlers for the terminal emulator."""
32
# Copyright (c) Jupyter Development Team.
43
# Distributed under the terms of the Modified BSD License.
@@ -27,14 +26,14 @@ def get(self, *args, **kwargs):
2726
raise web.HTTPError(403)
2827
if not args[0] in self.term_manager.terminals:
2928
raise web.HTTPError(404)
30-
return super(TermSocket, self).get(*args, **kwargs)
29+
return super().get(*args, **kwargs)
3130

3231
def on_message(self, message):
33-
super(TermSocket, self).on_message(message)
32+
super().on_message(message)
3433
self._update_activity()
3534

3635
def write_message(self, message, binary=False):
37-
super(TermSocket, self).write_message(message, binary=binary)
36+
super().write_message(message, binary=binary)
3837
self._update_activity()
3938

4039
def _update_activity(self):

jupyter_server_terminals/rest-api.yml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ info:
77
url: https://jupyter.org
88
version: "1"
99
servers:
10-
- url: /
10+
- url: /
1111
paths:
1212
/api/terminals:
1313
get:
1414
tags:
15-
- terminals
15+
- terminals
1616
summary: Get available terminals
1717
responses:
1818
200:
@@ -22,7 +22,7 @@ paths:
2222
schema:
2323
type: array
2424
items:
25-
$ref: '#/components/schemas/Terminal'
25+
$ref: "#/components/schemas/Terminal"
2626
403:
2727
description: Forbidden to access
2828
content: {}
@@ -31,15 +31,15 @@ paths:
3131
content: {}
3232
post:
3333
tags:
34-
- terminals
34+
- terminals
3535
summary: Create a new terminal
3636
responses:
3737
200:
3838
description: Succesfully created a new terminal
3939
content:
4040
application/json:
4141
schema:
42-
$ref: '#/components/schemas/Terminal'
42+
$ref: "#/components/schemas/Terminal"
4343
403:
4444
description: Forbidden to access
4545
content: {}
@@ -49,22 +49,22 @@ paths:
4949
/api/terminals/{terminal_id}:
5050
get:
5151
tags:
52-
- terminals
52+
- terminals
5353
summary: Get a terminal session corresponding to an id.
5454
parameters:
55-
- name: terminal_id
56-
in: path
57-
description: ID of terminal session
58-
required: true
59-
schema:
60-
type: string
55+
- name: terminal_id
56+
in: path
57+
description: ID of terminal session
58+
required: true
59+
schema:
60+
type: string
6161
responses:
6262
200:
6363
description: Terminal session with given id
6464
content:
6565
application/json:
6666
schema:
67-
$ref: '#/components/schemas/Terminal'
67+
$ref: "#/components/schemas/Terminal"
6868
403:
6969
description: Forbidden to access
7070
content: {}
@@ -73,15 +73,15 @@ paths:
7373
content: {}
7474
delete:
7575
tags:
76-
- terminals
76+
- terminals
7777
summary: Delete a terminal session corresponding to an id.
7878
parameters:
79-
- name: terminal_id
80-
in: path
81-
description: ID of terminal session
82-
required: true
83-
schema:
84-
type: string
79+
- name: terminal_id
80+
in: path
81+
description: ID of terminal session
82+
required: true
83+
schema:
84+
type: string
8585
responses:
8686
204:
8787
description: Succesfully deleted terminal session
@@ -96,7 +96,7 @@ components:
9696
schemas:
9797
Terminal:
9898
required:
99-
- name
99+
- name
100100
type: object
101101
properties:
102102
name:

jupyter_server_terminals/terminalmanager.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88

99
import terminado
1010
from tornado import web
11-
from tornado.ioloop import IOLoop
12-
from tornado.ioloop import PeriodicCallback
11+
from tornado.ioloop import IOLoop, PeriodicCallback
1312
from traitlets import Integer
1413
from traitlets.config import LoggingConfigurable
1514

1615
try:
17-
from jupyter_server._tz import isoformat
18-
from jupyter_server._tz import utcnow
16+
from jupyter_server._tz import isoformat, utcnow
1917
from jupyter_server.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL
2018
except ModuleNotFoundError:
2119
raise ModuleNotFoundError("Jupyter Server must be installed to use this extension.")
@@ -46,7 +44,7 @@ class TerminalManager(LoggingConfigurable, terminado.NamedTermManager):
4644
# Methods for managing terminals
4745
# -------------------------------------------------------------------------
4846
def __init__(self, *args, **kwargs):
49-
super(TerminalManager, self).__init__(*args, **kwargs)
47+
super().__init__(*args, **kwargs)
5048

5149
def create(self, **kwargs):
5250
"""Create a new terminal."""
@@ -78,7 +76,7 @@ def list(self):
7876
async def terminate(self, name, force=False):
7977
"""Terminate terminal 'name'."""
8078
self._check_terminal(name)
81-
await super(TerminalManager, self).terminate(name, force=force)
79+
await super().terminate(name, force=force)
8280

8381
# Decrease the metric below by one
8482
# because a terminal has been shutdown
@@ -113,7 +111,7 @@ def _initialize_culler(self):
113111
"""
114112
if not self._initialized_culler and self.cull_inactive_timeout > 0:
115113
if self._culler_callback is None:
116-
loop = IOLoop.current()
114+
_ = IOLoop.current()
117115
if self.cull_interval <= 0: # handle case where user set invalid value
118116
self.log.warning(
119117
"Invalid value for 'cull_interval' detected (%s) - using default value (%s).",

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ build-backend = "jupyter_packaging.build_api"
66
ignore = [""]
77

88
[tool.pytest.ini_options]
9-
addopts = "--doctest-modules"
9+
addopts = "-raXs --durations 10 --color=yes --doctest-modules"
1010
testpaths = [
1111
"tests/"
1212
]
13+
timeout = 300
14+
# Restore this setting to debug failures
15+
# timeout_method = "thread"
16+
filterwarnings = [
17+
"error",
18+
# From tornado
19+
"ignore:unclosed <socket.socket:ResourceWarning",
20+
"ignore:There is no current event loop:DeprecationWarning",
21+
]
1322

1423
[tool.jupyter-releaser]
1524
skip = ["check-links"]

setup.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test =
3636
pytest>=6.0
3737
pytest_tornasync
3838
pytest-cov
39+
pytest-timeout
3940
jupyter_server[test]>=1
4041

4142
[options.packages.find]
@@ -46,10 +47,19 @@ etc/jupyter/jupyter_server_config.d =
4647
jupyter-config/jupyter_server_terminals.json
4748

4849
[flake8]
49-
ignore = E, C, W, F403, F811, F841, E402, I100, I101, D400
50+
ignore = E501, W503, E402
5051
builtins = c, get_config
5152
exclude =
5253
.cache,
5354
.github,
5455
docs,
5556
setup.py
57+
enable-extensions = G
58+
extend-ignore =
59+
G001, G002, G004, G200, G201, G202,
60+
# black adds spaces around ':'
61+
E203,
62+
per-file-ignores =
63+
# B011: Do not call assert False since python -O removes these calls
64+
# F841 local variable 'foo' is assigned to but never used
65+
tests/*: B011, F841

tests/test_terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def test_culling(jp_server_config, jp_fetch, jp_cleanup_subprocesses):
171171
last_activity = term["last_activity"]
172172

173173
culled = False
174-
for i in range(CULL_TIMEOUT + CULL_INTERVAL * 2):
174+
for _ in range(CULL_TIMEOUT + CULL_INTERVAL * 2):
175175
try:
176176
resp = await jp_fetch(
177177
"api",

0 commit comments

Comments
 (0)