Skip to content

Commit

Permalink
Refresh precommit (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Feb 11, 2022
1 parent 49dfe2e commit 745f5ba
Show file tree
Hide file tree
Showing 41 changed files with 260 additions and 248 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: Test downstream projects

on:
push:
branches: "*"
pull_request:
branches: "*"

jobs:
tests:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Jupyter Server Integration Tests [Linux]
on:
push:
branches: "main"
branches: ["main"]
pull_request:
branches: "*"
branches: ["*"]
jobs:
build:
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu]
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
steps:
- name: Checkout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-linux.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Jupyter Server Tests [Linux]
on:
push:
branches: "main"
branches: ["main"]
pull_request:
branches: "*"
branches: ["*"]
jobs:
# Run "pre-commit run --all-files"
pre-commit:
Expand All @@ -30,11 +30,11 @@ jobs:
echo " pre-commit run --all-files"
build:
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu]
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
steps:
- name: Checkout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-macos.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Jupyter Server Tests [Mac OS]
on:
push:
branches: "main"
branches: ["main"]
pull_request:
branches: "*"
branches: ["*"]
jobs:
build:
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos]
os: [macos-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7"]
steps:
- name: Checkout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/python-windows.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Jupyter Server Tests [Windows]
on:
push:
branches: "main"
branches: ["main"]
pull_request:
branches: "*"
branches: ["*"]
jobs:
build:
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows]
os: [windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- name: Checkout
Expand Down
32 changes: 26 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.9.0
rev: v2.7.1
hooks:
- id: reorder-python-imports

- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.1.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
rev: v2.5.1
hooks:
- id: prettier

- repo: https://gitlab.com/pycqa/flake8
rev: "3.8.4"
rev: 4.0.1
hooks:
- id: flake8

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: forbid-new-submodules

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.32.0
rev: v8.8.0
hooks:
- id: eslint

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.10.2
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
2 changes: 1 addition & 1 deletion examples/simple/simple_ext1/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get(self):

class TemplateHandler(BaseTemplateHandler):
def get(self, path):
""" Optionaly, you can print(self.get_template('simple1.html'))"""
"""Optionaly, you can print(self.get_template('simple1.html'))"""
self.write(self.render_template("simple1.html", path=path))


Expand Down
60 changes: 29 additions & 31 deletions examples/simple/simple_ext1/static/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,35 @@
/******/
}; // create a fake namespace object // mode & 1: value is a module id, require it // mode & 2: merge all properties of value into the ns // mode & 4: return value when already ns object // mode & 8|1: behave like require
/******/
/******/ /******/ /******/ /******/ /******/ /******/ __webpack_require__.t = function (
value,
mode
) {
/******/ if (mode & 1) value = __webpack_require__(value);
/******/ if (mode & 8) return value;
/******/ if (
mode & 4 &&
typeof value === "object" &&
value &&
value.__esModule
)
return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, "default", {
enumerable: true,
value: value,
});
/******/ if (mode & 2 && typeof value != "string")
for (var key in value)
__webpack_require__.d(
ns,
key,
function (key) {
return value[key];
}.bind(null, key)
);
/******/ return ns;
/******/
}; // getDefaultExport function for compatibility with non-harmony modules
/******/ /******/ /******/ /******/ /******/ /******/ __webpack_require__.t =
function (value, mode) {
/******/ if (mode & 1) value = __webpack_require__(value);
/******/ if (mode & 8) return value;
/******/ if (
mode & 4 &&
typeof value === "object" &&
value &&
value.__esModule
)
return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, "default", {
enumerable: true,
value: value,
});
/******/ if (mode & 2 && typeof value != "string")
for (var key in value)
__webpack_require__.d(
ns,
key,
function (key) {
return value[key];
}.bind(null, key)
);
/******/ return ns;
/******/
}; // getDefaultExport function for compatibility with non-harmony modules
/******/
/******/ /******/ __webpack_require__.n = function (module) {
/******/ var getter =
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/_sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def pkg_commit_hash(pkg_path):
if repo_commit:
return "repository", repo_commit.strip().decode("ascii")
else:
return u"", u""
return "", ""
par_path = p.dirname(par_path)

return u"", u""
return "", ""


def pkg_info(pkg_path):
Expand Down
6 changes: 3 additions & 3 deletions jupyter_server/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def passwd_check(self, a, b):
return passwd_check(a, b)

def post(self):
typed_password = self.get_argument("password", default=u"")
new_password = self.get_argument("new_password", default=u"")
typed_password = self.get_argument("password", default="")
new_password = self.get_argument("new_password", default="")

if self.get_login_available(self.settings):
if self.passwd_check(self.hashed_password, typed_password) and not new_password:
Expand Down Expand Up @@ -248,7 +248,7 @@ def password_from_settings(cls, settings):
If there is no configured password, an empty string will be returned.
"""
return settings.get("password", u"")
return settings.get("password", "")

@classmethod
def get_login_available(cls, settings):
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,13 @@ def get_json_body(self):
if not self.request.body:
return None
# Do we need to call body.decode('utf-8') here?
body = self.request.body.strip().decode(u"utf-8")
body = self.request.body.strip().decode("utf-8")
try:
model = json.loads(body)
except Exception as e:
self.log.debug("Bad JSON: %r", body)
self.log.error("Couldn't parse JSON", exc_info=True)
raise web.HTTPError(400, u"Invalid JSON in body of request") from e
raise web.HTTPError(400, "Invalid JSON in body of request") from e
return model

def write_error(self, status_code, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def _default_log_level(self):
@default("log_format")
def _default_log_format(self):
"""override default log format to include date & time"""
return u"%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)s"
return (
"%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d %(name)s]%(end_color)s %(message)s"
)

static_url_prefix = Unicode(
help="""Url where the static assets for the extension are served."""
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 @@ -329,7 +329,7 @@ def list_server_extensions(self):
for name, extension in ext_manager.extensions.items():
enabled = extension.enabled
# Attempt to get extension metadata
self.log.info(u" {} {}".format(name, GREEN_ENABLED if enabled else RED_DISABLED))
self.log.info(" {} {}".format(name, GREEN_ENABLED if enabled else RED_DISABLED))
try:
self.log.info(" - Validating {}...".format(name))
if not extension.validate():
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def load_connection_args(self, **kwargs):


async def gateway_request(endpoint, **kwargs):
"""Make an async request to kernel gateway endpoint, returns a response """
"""Make an async request to kernel gateway endpoint, returns a response"""
client = AsyncHTTPClient()
kwargs = GatewayClient.instance().load_connection_args(**kwargs)
try:
Expand Down
4 changes: 2 additions & 2 deletions jupyter_server/gateway/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def send_ping(self):
self.ping(b"")

def open(self, kernel_id, *args, **kwargs):
"""Handle web socket connection open to notebook server and delegate to gateway web socket handler """
"""Handle web socket connection open to notebook server and delegate to gateway web socket handler"""
self.ping_callback = PeriodicCallback(self.send_ping, GATEWAY_WS_PING_INTERVAL_SECS * 1000)
self.ping_callback.start()

Expand Down Expand Up @@ -221,7 +221,7 @@ async def _read_messages(self, callback):
jitter = random.randint(10, 100) * 0.01
retry_interval = (
min(
GatewayClient.instance().gateway_retry_interval * (2 ** self.retry),
GatewayClient.instance().gateway_retry_interval * (2**self.retry),
GatewayClient.instance().gateway_retry_interval_max,
)
+ jitter
Expand Down
14 changes: 7 additions & 7 deletions jupyter_server/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, **kwargs):
)

def remove_kernel(self, kernel_id):
"""Complete override since we want to be more tolerant of missing keys """
"""Complete override since we want to be more tolerant of missing keys"""
try:
return self._kernels.pop(kernel_id)
except KeyError:
Expand Down Expand Up @@ -178,7 +178,7 @@ async def shutdown_all(self, now=False):
self.remove_kernel(kernel_id)

async def cull_kernels(self):
"""Override cull_kernels so we can be sure their state is current. """
"""Override cull_kernels so we can be sure their state is current."""
await self.list_kernels()
await super().cull_kernels()

Expand Down Expand Up @@ -301,7 +301,7 @@ class GatewaySessionManager(SessionManager):
kernel_manager = Instance("jupyter_server.gateway.managers.GatewayMappingKernelManager")

async def kernel_culled(self, kernel_id):
"""Checks if the kernel is still considered alive and returns true if its not found. """
"""Checks if the kernel is still considered alive and returns true if its not found."""
kernel = None
try:
km = self.kernel_manager.get_kernel(kernel_id)
Expand All @@ -315,7 +315,7 @@ async def kernel_culled(self, kernel_id):


class GatewayKernelManager(AsyncKernelManager):
"""Manages a single kernel remotely via a Gateway Server. """
"""Manages a single kernel remotely via a Gateway Server."""

kernel_id = None
kernel = None
Expand Down Expand Up @@ -451,23 +451,23 @@ async def start_kernel(self, **kwargs):
self.kernel_url = url_path_join(self.kernels_url, url_escape(str(self.kernel_id)))

async def shutdown_kernel(self, now=False, restart=False):
"""Attempts to stop the kernel process cleanly via HTTP. """
"""Attempts to stop the kernel process cleanly via HTTP."""

if self.has_kernel:
self.log.debug("Request shutdown kernel at: %s", self.kernel_url)
response = await gateway_request(self.kernel_url, method="DELETE")
self.log.debug("Shutdown kernel response: %d %s", response.code, response.reason)

async def restart_kernel(self, **kw):
"""Restarts a kernel via HTTP. """
"""Restarts a kernel via HTTP."""
if self.has_kernel:
kernel_url = self.kernel_url + "/restart"
self.log.debug("Request restart kernel at: %s", kernel_url)
response = await gateway_request(kernel_url, method="POST", body=json_encode({}))
self.log.debug("Restart kernel response: %d %s", response.code, response.reason)

async def interrupt_kernel(self):
"""Interrupts the kernel via an HTTP request. """
"""Interrupts the kernel via an HTTP request."""
if self.has_kernel:
kernel_url = self.kernel_url + "/interrupt"
self.log.debug("Request interrupt kernel at: %s", kernel_url)
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/kernelspecs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get(self, kernel_name, path, include_body=True):
try:
self.root = ksm.get_kernel_spec(kernel_name).resource_dir
except KeyError as e:
raise web.HTTPError(404, u"Kernel spec %s not found" % kernel_name) from e
raise web.HTTPError(404, "Kernel spec %s not found" % kernel_name) from e
self.log.debug("Serving kernel resource from: %s", self.root)
return web.StaticFileHandler.get(self, path, include_body=include_body)

Expand Down
Loading

0 comments on commit 745f5ba

Please sign in to comment.