Skip to content

Commit 25ec3ed

Browse files
authored
Add pyupgrade and doc8 hooks (#768)
1 parent 45ce912 commit 25ec3ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+310
-276
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ repos:
3636
hooks:
3737
- id: prettier
3838

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+
3951
- repo: https://github.com/pycqa/flake8
4052
rev: 4.0.1
4153
hooks:

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
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.

docs/source/developers/dependency.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
Depending on Jupyter Server
22
===========================
33

4-
If your project depends directly on Jupyter Server, be sure to watch Jupyter Server's ChangeLog and pin your project to a version that works for your application. Major releases represent possible backwards-compatibility breaking API changes or features.
5-
6-
When a new major version in released on PyPI, a branch for that version will be created in this repository, and the version of the master branch will be bumped to the next major version number. That way, the master branch always reflects the latest un-released version.
4+
If your project depends directly on Jupyter Server, be sure to watch Jupyter
5+
Server's ChangeLog and pin your project to a version that works for your
6+
application. Major releases represent possible backwards-compatibility breaking
7+
API changes or features.
8+
9+
When a new major version in released on PyPI, a branch for that version will be
10+
created in this repository, and the version of the master branch will be bumped
11+
to the next major version number. That way, the master branch always reflects
12+
the latest un-released version.
713

814
To install the latest patch of a given version:
915

docs/source/developers/extensions.rst

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ You can check some simple examples on the `examples folder
1010
Authoring a basic server extension
1111
==================================
1212

13-
The simplest way to write a Jupyter Server extension is to write an extension module with a ``_load_jupyter_server_extension`` function. This function should take a single argument, an instance of the ``ServerApp``.
13+
The simplest way to write a Jupyter Server extension is to write an extension
14+
module with a ``_load_jupyter_server_extension`` function. This function should
15+
take a single argument, an instance of the ``ServerApp``.
1416

1517

1618
.. code-block:: python
@@ -62,7 +64,11 @@ Then add this handler to Jupyter Server's Web Application through the ``_load_ju
6264
Making an extension discoverable
6365
--------------------------------
6466

65-
To make this extension discoverable to Jupyter Server, first define a ``_jupyter_server_extension_points()`` function at the root of the module/package. This function returns metadata describing how to load the extension. Usually, this requires a ``module`` key with the import path to the extension's ``_load_jupyter_server_extension`` function.
67+
To make this extension discoverable to Jupyter Server, first define a
68+
``_jupyter_server_extension_points()`` function at the root of the module/
69+
package. This function returns metadata describing how to load the extension.
70+
Usually, this requires a ``module`` key with the import path to the extension's
71+
``_load_jupyter_server_extension`` function.
6672

6773
.. code-block:: python
6874
@@ -85,7 +91,10 @@ Second, add the extension to the ServerApp's ``jpserver_extensions`` trait. This
8591
"my_extension": True
8692
}
8793
88-
or loaded from a JSON file in the ``jupyter_server_config.d`` directory under one of `Jupyter's paths`_. (See the `Distributing a server extension`_ section for details on how to automatically enabled your extension when users install it.)
94+
or loaded from a JSON file in the ``jupyter_server_config.d`` directory under
95+
one of `Jupyter's paths`_. (See the `Distributing a server extension`_ section
96+
for details on how to automatically enabled your extension when users install
97+
it.)
8998

9099
.. code-block:: python
91100
@@ -161,7 +170,10 @@ The basic structure of an ExtensionApp is shown below:
161170
# Perform any required shut down steps
162171
163172
164-
The ``ExtensionApp`` uses the following methods and properties to connect your extension to the Jupyter server. You do not need to define a ``_load_jupyter_server_extension`` function for these apps. Instead, overwrite the pieces below to add your custom settings, handlers and templates:
173+
The ``ExtensionApp`` uses the following methods and properties to connect your
174+
extension to the Jupyter server. You do not need to define a
175+
``_load_jupyter_server_extension`` function for these apps. Instead, overwrite
176+
the pieces below to add your custom settings, handlers and templates:
165177

166178
Methods
167179

@@ -212,7 +224,9 @@ Jinja templating from frontend extensions
212224

213225
Many Jupyter frontend applications use Jinja for basic HTML templating. Since this is common enough, Jupyter Server provides some extra mixin that integrate Jinja with Jupyter server extensions.
214226

215-
Use ``ExtensionAppJinjaMixin`` to automatically add a Jinja templating environment to an ``ExtensionApp``. This adds a ``<name>_jinja2_env`` setting to Tornado Web Server's settings that will be used by request handlers.
227+
Use ``ExtensionAppJinjaMixin`` to automatically add a Jinja templating
228+
environment to an ``ExtensionApp``. This adds a ``<name>_jinja2_env`` setting
229+
to Tornado Web Server's settings that will be used by request handlers.
216230

217231
.. code-block:: python
218232
@@ -224,7 +238,9 @@ Use ``ExtensionAppJinjaMixin`` to automatically add a Jinja templating environme
224238
...
225239
226240
227-
Pair the example above with ``ExtensionHandlers`` that also inherit the ``ExtensionHandlerJinjaMixin`` mixin. This will automatically load HTML templates from the Jinja templating environment created by the ``ExtensionApp``.
241+
Pair the example above with ``ExtensionHandlers`` that also inherit the
242+
``ExtensionHandlerJinjaMixin`` mixin. This will automatically load HTML
243+
templates from the Jinja templating environment created by the ``ExtensionApp``.
228244

229245

230246
.. code-block:: python
@@ -347,7 +363,10 @@ Putting it all together, authors can distribute their extension following this s
347363
This is where the extension logic will live (i.e. custom extension handlers, config, etc). See the sections above for more information on how to create an extension.
348364

349365
3. Add the following JSON config file to the extension package.
350-
The file should be named after the extension (e.g. ``myextension.json``) and saved in a subdirectory of the package with the prefix: ``jupyter-config/jupyter_server_config.d/``. The extension package will have a similar structure to this example:
366+
The file should be named after the extension (e.g. ``myextension.json``)
367+
and saved in a subdirectory of the package with the prefix:
368+
``jupyter-config/jupyter_server_config.d/``. The extension package will
369+
have a similar structure to this example:
351370

352371
.. code-block::
353372
@@ -413,12 +432,18 @@ Putting it all together, authors can distribute their extension following this s
413432
Migrating an extension to use Jupyter Server
414433
============================================
415434

416-
If you're a developer of a `classic Notebook Server`_ extension, your extension should be able to work with *both* the classic notebook server and ``jupyter_server``.
435+
If you're a developer of a `classic Notebook Server`_ extension, your extension
436+
should be able to work with *both* the classic notebook server and
437+
``jupyter_server``.
417438

418439
There are a few key steps to make this happen:
419440

420441
1. Point Jupyter Server to the ``load_jupyter_server_extension`` function with a new reference name.
421-
The ``load_jupyter_server_extension`` function was the key to loading a server extension in the classic Notebook Server. Jupyter Server expects the name of this function to be prefixed with an underscore—i.e. ``_load_jupyter_server_extension``. You can easily achieve this by adding a reference to the old function name with the new name in the same module.
442+
The ``load_jupyter_server_extension`` function was the key to loading a
443+
server extension in the classic Notebook Server. Jupyter Server expects the
444+
name of this function to be prefixed with an underscore—i.e.
445+
``_load_jupyter_server_extension``. You can easily achieve this by adding a
446+
reference to the old function name with the new name in the same module.
422447

423448
.. code-block:: python
424449
@@ -483,7 +508,10 @@ There are a few key steps to make this happen:
483508
)
484509
485510
3. (Optional) Point extension at the new favicon location.
486-
The favicons in the Jupyter Notebook have been moved to a new location in Jupyter Server. If your extension is using one of these icons, you'll want to add a set of redirect handlers this. (In ``ExtensionApp``, this is handled automatically).
511+
The favicons in the Jupyter Notebook have been moved to a new location in
512+
Jupyter Server. If your extension is using one of these icons, you'll want
513+
to add a set of redirect handlers this. (In ``ExtensionApp``, this is
514+
handled automatically).
487515

488516
This usually means adding a chunk to your ``load_jupyter_server_extension`` function similar to this:
489517

docs/source/developers/websocket-protocols.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ The Jupyter Server needs to pass messages between kernels and the Jupyter web ap
88
ZeroMQ wire protocol
99
--------------------
1010

11-
The kernel wire protocol over ZeroMQ takes advantage of multipart messages, allowing to decompose a message into parts and to send and receive them unmerged. The following table shows the message format (the beginning has been omitted for clarity):
11+
The kernel wire protocol over ZeroMQ takes advantage of multipart messages,
12+
allowing to decompose a message into parts and to send and receive them
13+
unmerged. The following table shows the message format (the beginning has been
14+
omitted for clarity):
1215

1316
.. list-table:: Format of a kernel message over ZeroMQ socket (indices refer to parts, not bytes)
1417
:header-rows: 1

docs/source/operators/configuring-extensions.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Configuring Extensions
44
======================
55

6-
Some Jupyter Server extensions are also configurable applications. There are two ways to configure such extensions: i) pass arguments to the extension's entry point or ii) list configurable options in a Jupyter config file.
6+
Some Jupyter Server extensions are also configurable applications. There are
7+
two ways to configure such extensions: i) pass arguments to the extension's
8+
entry point or ii) list configurable options in a Jupyter config file.
79

810
Jupyter Server looks for an extension's config file in a set of specific paths. Use the ``jupyter`` entry point to list these paths:
911

@@ -45,7 +47,9 @@ A Jupyter Server will automatically load config for each enabled extension. You
4547
Extension config on the command line
4648
------------------------------------
4749

48-
Server extension applications can also be configured from the command line, and multiple extension can be configured at the same time. Simply pass the traits (with their appropriate prefix) to the ``jupyter server`` entrypoint, e.g.:
50+
Server extension applications can also be configured from the command line, and
51+
multiple extension can be configured at the same time. Simply pass the traits
52+
(with their appropriate prefix) to the ``jupyter server`` entrypoint, e.g.:
4953

5054
.. code-block:: console
5155

docs/source/operators/multiple-extensions.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
Managing multiple extensions
55
----------------------------
66

7-
One of the major benefits of Jupyter Server is that you can run serve multiple Jupyter frontend applications above the same Tornado web server. That's because every Jupyter frontend application is now a server extension. When you run a Jupyter Server will multiple extensions enabled, each extension appends its own set of handlers and static assets to the server.
7+
One of the major benefits of Jupyter Server is that you can run serve multiple
8+
Jupyter frontend applications above the same Tornado web server.
9+
That's because every Jupyter frontend application is now a server extension.
10+
When you run a Jupyter Server will multiple extensions enabled, each extension
11+
appends its own set of handlers and static assets to the server.
812

913
Listing extensions
1014
~~~~~~~~~~~~~~~~~~

docs/source/operators/public-server.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ Preparing a hashed password
113113
You can prepare a hashed password manually, using the function
114114
:func:`notebook.auth.security.passwd`:
115115

116-
.. code-block:: ipython
116+
.. code-block:: python
117117
118-
In [1]: from jupyter_server.auth import passwd
119-
In [2]: passwd()
120-
Enter password:
121-
Verify password:
122-
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
118+
>>> from jupyter_server.auth import passwd
119+
>>> passwd()
120+
... Enter password:
121+
... Verify password:
122+
'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
123123
124124
.. caution::
125125

docs/source/other/full-config.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,11 @@ ServerApp.show_config_json : Bool
514514
ServerApp.shutdown_no_activity_timeout : Int
515515
Default: ``0``
516516

517-
Shut down the server after N seconds with no kernels or terminals running and no activity. This can be used together with culling idle kernels (MappingKernelManager.cull_idle_timeout) to shutdown the Jupyter server when it's not in use. This is not precisely timed: it may shut down up to a minute later. 0 (the default) disables this automatic shutdown.
517+
Shut down the server after N seconds with no kernels or terminals running
518+
and no activity. This can be used together with culling idle kernels
519+
(MappingKernelManager.cull_idle_timeout) to shutdown the Jupyter server
520+
when it's not in use. This is not precisely timed: it may shut down up to
521+
a minute later. 0 (the default) disables this automatic shutdown.
518522

519523
ServerApp.ssl_options : Dict
520524
Default: ``{}``

docs/source/users/configuration.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ By default, Jupyter Server looks for server-specific configuration in a ``jupyte
2727
The paths under ``config`` are listed in order of precedence. If the same trait is listed in multiple places, it will be set to the value from the file will highest precendence.
2828

2929

30-
Jupyter Server uses IPython's traitlets system for configuration. Traits can be listed in a Python or JSON config file. You can quickly create a ``jupyter_server_config.py`` file in the ``.jupyter`` directory, with all the defaults commented out, use the following command:
30+
Jupyter Server uses IPython's traitlets system for configuration. Traits can be
31+
listed in a Python or JSON config file. You can quickly create a
32+
``jupyter_server_config.py`` file in the ``.jupyter`` directory, with all the
33+
defaults commented out, use the following command:
3134

3235
.. code-block:: console
3336

docs/source/users/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Documentation for Users
22
=======================
33

4-
The Jupyter Server is a highly technical piece of the Jupyter Stack, so users probably won't import or install this library directly. These pages are to meant to help you in case you run into issues or bugs.
4+
The Jupyter Server is a highly technical piece of the Jupyter Stack, so users
5+
probably won't import or install this library directly. These pages are to
6+
meant to help you in case you run into issues or bugs.
57

68

79
.. toctree::

docs/source/users/installation.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
Installation
44
============
55

6-
Most Jupyter users will **never need to install Jupyter Server manually**. Jupyter Web applications will include the (correct version) of Jupyter Server as a dependency. It's best to let those applications handle installation, because they may require a specific version of Jupyter Server.
6+
Most Jupyter users will **never need to install Jupyter Server manually**.
7+
Jupyter Web applications will include the (correct version) of Jupyter Server
8+
as a dependency. It's best to let those applications handle installation,
9+
because they may require a specific version of Jupyter Server.
710

811
If you decide to install manually, run:
912

docs/source/users/launching.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
Launching a bare Jupyter Server
44
===============================
55

6-
Most of the time, you won't need to start the Jupyter Server directly. Jupyter Web Applications (like Jupyter Notebook, Jupyterlab, Voila, etc.) come with their own entry points that start a server automatically.
6+
Most of the time, you won't need to start the Jupyter Server directly. Jupyter
7+
Web Applications (like Jupyter Notebook, Jupyterlab, Voila, etc.) come with
8+
their own entry points that start a server automatically.
79

8-
Sometimes, though, it can be useful to start Jupyter Server directly when you want to run multiple Jupyter Web applications at the same time. For more details, see the :ref:`Managing multiple extensions <managing-multiple-extensions>` page. If these extensions are enabled, you can simple run the following:
10+
Sometimes, though, it can be useful to start Jupyter Server directly when you
11+
want to run multiple Jupyter Web applications at the same time. For more
12+
details, see the :ref:`Managing multiple extensions <managing-multiple-extensions>` page.
13+
If these extensions are enabled, you can simple run the following:
914

1015
.. code-block:: bash
1116

examples/simple/simple_ext1/application.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ class SimpleApp1(ExtensionAppJinjaMixin, ExtensionApp):
4343
def initialize_handlers(self):
4444
self.handlers.extend(
4545
[
46-
(r"/{}/default".format(self.name), DefaultHandler),
47-
(r"/{}/params/(.+)$".format(self.name), ParameterHandler),
48-
(r"/{}/template1/(.*)$".format(self.name), TemplateHandler),
49-
(r"/{}/redirect".format(self.name), RedirectHandler),
50-
(r"/{}/typescript/?".format(self.name), TypescriptHandler),
51-
(r"/{}/(.*)".format(self.name), ErrorHandler),
46+
(rf"/{self.name}/default", DefaultHandler),
47+
(rf"/{self.name}/params/(.+)$", ParameterHandler),
48+
(rf"/{self.name}/template1/(.*)$", TemplateHandler),
49+
(rf"/{self.name}/redirect", RedirectHandler),
50+
(rf"/{self.name}/typescript/?", TypescriptHandler),
51+
(rf"/{self.name}/(.*)", ErrorHandler),
5252
]
5353
)
5454

5555
def initialize_settings(self):
56-
self.log.info("Config {}".format(self.config))
56+
self.log.info(f"Config {self.config}")
5757

5858

5959
# -----------------------------------------------------------------------------

examples/simple/simple_ext1/handlers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99
class DefaultHandler(ExtensionHandlerMixin, JupyterHandler):
1010
def get(self):
1111
# The name of the extension to which this handler is linked.
12-
self.log.info("Extension Name in {} Default Handler: {}".format(self.name, self.name))
12+
self.log.info(f"Extension Name in {self.name} Default Handler: {self.name}")
1313
# A method for getting the url to static files (prefixed with /static/<name>).
1414
self.log.info(
1515
"Static URL for / in simple_ext1 Default Handler: {}".format(self.static_url(path="/"))
1616
)
1717
self.write("<h1>Hello Simple 1 - I am the default...</h1>")
18-
self.write("Config in {} Default Handler: {}".format(self.name, self.config))
18+
self.write(f"Config in {self.name} Default Handler: {self.config}")
1919

2020

2121
class RedirectHandler(ExtensionHandlerMixin, JupyterHandler):
2222
def get(self):
23-
self.redirect("/static/{}/favicon.ico".format(self.name))
23+
self.redirect(f"/static/{self.name}/favicon.ico")
2424

2525

2626
class ParameterHandler(ExtensionHandlerMixin, JupyterHandler):
2727
def get(self, matched_part=None, *args, **kwargs):
2828
var1 = self.get_argument("var1", default=None)
2929
components = [x for x in self.request.path.split("/") if x]
3030
self.write("<h1>Hello Simple App 1 from Handler.</h1>")
31-
self.write("<p>matched_part: {}</p>".format(url_escape(matched_part)))
32-
self.write("<p>var1: {}</p>".format(url_escape(var1)))
33-
self.write("<p>components: {}</p>".format(components))
31+
self.write(f"<p>matched_part: {url_escape(matched_part)}</p>")
32+
self.write(f"<p>var1: {url_escape(var1)}</p>")
33+
self.write(f"<p>components: {components}</p>")
3434

3535

3636
class BaseTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):

0 commit comments

Comments
 (0)