Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin 1.0.x to tornado 6.1, remove asyncio patch [backport pieces of #339] #355

Merged
merged 5 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_server/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,4 @@ def inner(nbpath):
nb = nbformat.v4.new_notebook()
nbtext = nbformat.writes(nb, version=4)
nbpath.write_text(nbtext)
return inner
return inner
49 changes: 14 additions & 35 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@
from jupyter_server.transutils import trans, _
from jupyter_server.utils import secure_write, run_sync

# check for tornado 3.1.0
# the minimum viable tornado version: needs to be kept in sync with setup.py
MIN_TORNADO = (6, 1, 0)

try:
import tornado
except ImportError as e:
raise ImportError(_("The Jupyter Server requires tornado >= 4.0")) from e
try:
version_info = tornado.version_info
except AttributeError as e:
raise ImportError(_("The Jupyter Server requires tornado >= 4.0, but you have < 1.1.0")) from e
if version_info < (4,0):
raise ImportError(_("The Jupyter Server requires tornado >= 4.0, but you have %s") % tornado.version)
assert tornado.version_info >= MIN_TORNADO
except (ImportError, AttributeError, AssertionError) as e: # pragma: no cover
raise ImportError(
_("The Jupyter Server requires tornado >=%s.%s.%s") % MIN_TORNADO
) from e

from tornado import httpserver
from tornado import ioloop
Expand Down Expand Up @@ -1604,31 +1603,12 @@ def init_httpserver(self):

@staticmethod
def _init_asyncio_patch():
"""set default asyncio policy to be compatible with tornado
Tornado 6 (at least) is not compatible with the default
asyncio implementation on Windows
Pick the older SelectorEventLoopPolicy on Windows
if the known-incompatible default policy is in use.
do this as early as possible to make it a low priority and overrideable
ref: https://github.com/tornadoweb/tornado/issues/2608
FIXME: if/when tornado supports the defaults in asyncio,
remove and bump tornado requirement for py38
"""
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
import asyncio
try:
from asyncio import (
WindowsProactorEventLoopPolicy,
WindowsSelectorEventLoopPolicy,
)
except ImportError:
pass
# not affected
else:
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
# fallback to the pre-3.8 default of Selector
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
"""no longer needed with tornado 6.1"""
warnings.warn(
"""ServerApp._init_asyncio_patch called, and is longer needed for """
"""tornado 6.1+, and will be removed in a future release.""",
DeprecationWarning
)

@catch_config_error
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
Expand All @@ -1648,7 +1628,6 @@ def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
If True, a tornado HTTPServer instance will be created and configured for the Server Web
Application. This will set the http_server attribute of this class.
"""
self._init_asyncio_patch()
# Parse command line, load ServerApp config files,
# and update ServerApp config.
super(ServerApp, self).initialize(argv)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
install_requires = [
'jinja2',
'tornado>=5.0',
'tornado>=6.1.0',
'pyzmq>=17',
'ipython_genutils',
'traitlets>=4.2.1',
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py

This file was deleted.

35 changes: 19 additions & 16 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
new_output)


async def test_hidden_files(fetch, serverapp, root_dir):
not_hidden = [
u'å b',
u'å b/ç. d',
]
hidden = [
u'.å b',
u'å b/.ç d',
]
dirs = not_hidden + hidden

for d in dirs:
path = root_dir / d.replace('/', os.sep)
path.mkdir(parents=True, exist_ok=True)
path.joinpath('foo').write_text('foo')
path.joinpath('.foo').write_text('.foo')
@pytest.fixture(params=[
[False, ['å b']],
[False, ['å b', 'ç. d']],
[True, ['.å b']],
[True, ['å b', '.ç d']]
])
def maybe_hidden(request):
return request.param


async def fetch_expect_200(fetch, *path_parts):
r = await fetch('files', *path_parts, method='GET')
assert (r.body.decode() == path_parts[-1]), (path_parts, r.body)


async def fetch_expect_404(fetch, *path_parts):
with pytest.raises(tornado.httpclient.HTTPClientError) as e:
await fetch('files', *path_parts, method='GET')
assert expected_http_error(e, 404), [path_parts, e]


for d in not_hidden:
Expand Down