Skip to content

Commit

Permalink
Merge pull request #355 from Zsailer/1.0.x
Browse files Browse the repository at this point in the history
Pin 1.0.x to tornado 6.1, remove asyncio patch [backport pieces of #339]
  • Loading branch information
Zsailer authored Dec 8, 2020
2 parents fad6c97 + 5071b0c commit b4e0474
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 54 deletions.
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

0 comments on commit b4e0474

Please sign in to comment.