Skip to content

Commit b4e0474

Browse files
authored
Merge pull request #355 from Zsailer/1.0.x
Pin 1.0.x to tornado 6.1, remove asyncio patch [backport pieces of #339]
2 parents fad6c97 + 5071b0c commit b4e0474

File tree

5 files changed

+35
-54
lines changed

5 files changed

+35
-54
lines changed

jupyter_server/pytest_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,4 @@ def inner(nbpath):
282282
nb = nbformat.v4.new_notebook()
283283
nbtext = nbformat.writes(nb, version=4)
284284
nbpath.write_text(nbtext)
285-
return inner
285+
return inner

jupyter_server/serverapp.py

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@
4141
from jupyter_server.transutils import trans, _
4242
from jupyter_server.utils import secure_write, run_sync
4343

44-
# check for tornado 3.1.0
44+
# the minimum viable tornado version: needs to be kept in sync with setup.py
45+
MIN_TORNADO = (6, 1, 0)
46+
4547
try:
4648
import tornado
47-
except ImportError as e:
48-
raise ImportError(_("The Jupyter Server requires tornado >= 4.0")) from e
49-
try:
50-
version_info = tornado.version_info
51-
except AttributeError as e:
52-
raise ImportError(_("The Jupyter Server requires tornado >= 4.0, but you have < 1.1.0")) from e
53-
if version_info < (4,0):
54-
raise ImportError(_("The Jupyter Server requires tornado >= 4.0, but you have %s") % tornado.version)
49+
assert tornado.version_info >= MIN_TORNADO
50+
except (ImportError, AttributeError, AssertionError) as e: # pragma: no cover
51+
raise ImportError(
52+
_("The Jupyter Server requires tornado >=%s.%s.%s") % MIN_TORNADO
53+
) from e
5554

5655
from tornado import httpserver
5756
from tornado import ioloop
@@ -1604,31 +1603,12 @@ def init_httpserver(self):
16041603

16051604
@staticmethod
16061605
def _init_asyncio_patch():
1607-
"""set default asyncio policy to be compatible with tornado
1608-
Tornado 6 (at least) is not compatible with the default
1609-
asyncio implementation on Windows
1610-
Pick the older SelectorEventLoopPolicy on Windows
1611-
if the known-incompatible default policy is in use.
1612-
do this as early as possible to make it a low priority and overrideable
1613-
ref: https://github.com/tornadoweb/tornado/issues/2608
1614-
FIXME: if/when tornado supports the defaults in asyncio,
1615-
remove and bump tornado requirement for py38
1616-
"""
1617-
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
1618-
import asyncio
1619-
try:
1620-
from asyncio import (
1621-
WindowsProactorEventLoopPolicy,
1622-
WindowsSelectorEventLoopPolicy,
1623-
)
1624-
except ImportError:
1625-
pass
1626-
# not affected
1627-
else:
1628-
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
1629-
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
1630-
# fallback to the pre-3.8 default of Selector
1631-
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
1606+
"""no longer needed with tornado 6.1"""
1607+
warnings.warn(
1608+
"""ServerApp._init_asyncio_patch called, and is longer needed for """
1609+
"""tornado 6.1+, and will be removed in a future release.""",
1610+
DeprecationWarning
1611+
)
16321612

16331613
@catch_config_error
16341614
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
@@ -1648,7 +1628,6 @@ def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
16481628
If True, a tornado HTTPServer instance will be created and configured for the Server Web
16491629
Application. This will set the http_server attribute of this class.
16501630
"""
1651-
self._init_asyncio_patch()
16521631
# Parse command line, load ServerApp config files,
16531632
# and update ServerApp config.
16541633
super(ServerApp, self).initialize(argv)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
],
3838
install_requires = [
3939
'jinja2',
40-
'tornado>=5.0',
40+
'tornado>=6.1.0',
4141
'pyzmq>=17',
4242
'ipython_genutils',
4343
'traitlets>=4.2.1',

tests/conftest.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test_files.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@
1010
new_output)
1111

1212

13-
async def test_hidden_files(fetch, serverapp, root_dir):
14-
not_hidden = [
15-
u'å b',
16-
u'å b/ç. d',
17-
]
18-
hidden = [
19-
u'.å b',
20-
u'å b/.ç d',
21-
]
22-
dirs = not_hidden + hidden
23-
24-
for d in dirs:
25-
path = root_dir / d.replace('/', os.sep)
26-
path.mkdir(parents=True, exist_ok=True)
27-
path.joinpath('foo').write_text('foo')
28-
path.joinpath('.foo').write_text('.foo')
13+
@pytest.fixture(params=[
14+
[False, ['å b']],
15+
[False, ['å b', 'ç. d']],
16+
[True, ['.å b']],
17+
[True, ['å b', '.ç d']]
18+
])
19+
def maybe_hidden(request):
20+
return request.param
21+
22+
23+
async def fetch_expect_200(fetch, *path_parts):
24+
r = await fetch('files', *path_parts, method='GET')
25+
assert (r.body.decode() == path_parts[-1]), (path_parts, r.body)
26+
27+
28+
async def fetch_expect_404(fetch, *path_parts):
29+
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
30+
await fetch('files', *path_parts, method='GET')
31+
assert expected_http_error(e, 404), [path_parts, e]
2932

3033

3134
for d in not_hidden:

0 commit comments

Comments
 (0)