Skip to content

Commit

Permalink
Merge pull request #94 from kevin-bates/remove-py2
Browse files Browse the repository at this point in the history
Remove Python 2 support, require 3.5+
  • Loading branch information
Zsailer committed Sep 25, 2019
2 parents 5c32e6d + 4d33420 commit ff63d37
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 104 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cache:
- $HOME/.cache/pip
python:
- 3.6
- 2.7

sudo: required

Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ environment:
matrix:
- CONDA_PY: 36
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
- CONDA_PY: 27
CONDA_INSTALL_LOCN: "C:\\Miniconda-x64"

platform:
- x64
Expand Down
7 changes: 2 additions & 5 deletions jupyter_server/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

import re
import os

try:
from urllib.parse import urlparse # Py 3
except ImportError:
from urlparse import urlparse # Py 2
import uuid

from urllib.parse import urlparse

from tornado.escape import url_escape

from .security import passwd_check, set_password
Expand Down
15 changes: 3 additions & 12 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
import traceback
import types
import warnings
try:
# py3
from http.client import responses
from http.cookies import Morsel
except ImportError:
from httplib import responses
from Cookie import Morsel
try:
from urllib.parse import urlparse # Py 3
except ImportError:
from urlparse import urlparse # Py 2

from http.client import responses
from http.cookies import Morsel
from urllib.parse import urlparse
from jinja2 import TemplateNotFound
from tornado import web, gen, escape, httputil
from tornado.log import app_log
Expand Down
8 changes: 2 additions & 6 deletions jupyter_server/base/zmqhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
import struct
import warnings
import sys

try:
from urllib.parse import urlparse # Py 3
except ImportError:
from urlparse import urlparse # Py 2

import tornado

from urllib.parse import urlparse
from tornado import gen, ioloop, web
from tornado.websocket import WebSocketHandler

Expand Down
5 changes: 1 addition & 4 deletions jupyter_server/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import mimetypes
import json

try: #PY3
from base64 import decodebytes
except ImportError: #PY2
from base64 import decodestring as decodebytes
from base64 import decodebytes

from tornado import web

Expand Down
5 changes: 1 addition & 4 deletions jupyter_server/nbconvert/tests/test_nbconvert_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

from ipython_genutils.testing.decorators import onlyif_cmds_exist

try: #PY3
from base64 import encodebytes
except ImportError: #PY2
from base64 import encodestring as encodebytes
from base64 import encodebytes


class NbconvertAPI(object):
Expand Down
13 changes: 1 addition & 12 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
import warnings
import webbrowser

try: #PY3
from base64 import encodebytes
except ImportError: #PY2
from base64 import encodestring as encodebytes


from base64 import encodebytes
from jinja2 import Environment, FileSystemLoader

from jupyter_server.transutils import trans, _
Expand Down Expand Up @@ -70,12 +65,6 @@
__version__,
)

# py23 compatibility
try:
raw_input = raw_input
except NameError:
raw_input = input

from .base.handlers import MainHandler, RedirectWithParams, Template404
from .log import log_request
from .services.kernels.kernelmanager import MappingKernelManager
Expand Down
15 changes: 2 additions & 13 deletions jupyter_server/services/contents/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,13 @@
from traitlets.config import Configurable
from traitlets import Bool

try: #PY3
from base64 import encodebytes, decodebytes
except ImportError: #PY2
from base64 import encodestring as encodebytes, decodestring as decodebytes
from base64 import encodebytes, decodebytes


def replace_file(src, dst):
""" replace dst with src
switches between os.replace or os.rename based on python 2.7 or python 3
"""
if hasattr(os, 'replace'): # PY3
os.replace(src, dst)
else:
if os.name == 'nt' and os.path.exists(dst):
# Rename over existing file doesn't work on Windows
os.remove(dst)
os.rename(src, dst)
os.replace(src, dst)

def copy2_safe(src, dst, log=None):
"""copy src to dst
Expand Down
5 changes: 1 addition & 4 deletions jupyter_server/services/contents/tests/test_contents_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
from ipython_genutils import py3compat
from ipython_genutils.tempdir import TemporaryDirectory

try: #PY3
from base64 import encodebytes, decodebytes
except ImportError: #PY2
from base64 import encodestring as encodebytes, decodestring as decodebytes
from base64 import encodebytes, decodebytes


def uniq_stable(elems):
Expand Down
6 changes: 1 addition & 5 deletions jupyter_server/tests/launchserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@

pjoin = os.path.join

try:
from unittest.mock import patch
except ImportError:
from mock import patch #py2

from unittest.mock import patch
import requests
from tornado.ioloop import IOLoop
import zmq
Expand Down
13 changes: 2 additions & 11 deletions jupyter_server/tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import os
import sys
from unittest import TestCase
try:
from unittest.mock import patch
except ImportError:
from mock import patch # py2
from unittest.mock import patch

from ipython_genutils.tempdir import TemporaryDirectory
from ipython_genutils import py3compat
Expand All @@ -17,13 +14,7 @@
from jupyter_server.extensions import toggle_serverextension_python, _get_config_dir
from jupyter_server import extensions, extensions_base
from jupyter_server.serverapp import ServerApp

if sys.version_info > (3,):
from types import SimpleNamespace
else:
class SimpleNamespace(object):
pass

from types import SimpleNamespace
from collections import OrderedDict

def test_help_output():
Expand Down
11 changes: 2 additions & 9 deletions jupyter_server/tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

from jupyter_server.base.handlers import path_regex

try: # py3
assert_regex = nt.assert_regex
assert_not_regex = nt.assert_not_regex
except AttributeError: # py2
assert_regex = nt.assert_regexp_matches
assert_not_regex = nt.assert_not_regexp_matches


# build regexps that tornado uses:
path_pat = re.compile('^' + '/x%s' % path_regex + '$')
Expand All @@ -24,7 +17,7 @@ def test_path_regex():
'/x/foo/bar',
'/x/foo/bar.txt',
):
assert_regex(path, path_pat)
nt.assert_regex(path, path_pat)

def test_path_regex_bad():
for path in (
Expand All @@ -37,4 +30,4 @@ def test_path_regex_bad():
'/y',
'/y/x/foo',
):
assert_not_regex(path, path_pat)
nt.assert_not_regex(path, path_pat)
6 changes: 1 addition & 5 deletions jupyter_server/tests/test_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
from subprocess import Popen, PIPE, STDOUT
import sys
from tempfile import NamedTemporaryFile

try:
from unittest.mock import patch
except ImportError:
from mock import patch # py2
from unittest.mock import patch

import nose.tools as nt

Expand Down
6 changes: 1 addition & 5 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class ConcurrentFuture:
"""If concurrent.futures isn't importable, nothing will be a c.f.Future"""
pass

try:
from urllib.parse import quote, unquote, urlparse
except ImportError:
from urllib import quote, unquote
from urlparse import urlparse
from urllib.parse import quote, unquote, urlparse

# tornado.concurrent.Future is asyncio.Future
# in tornado >=5 with Python 3
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
name = "jupyter_server"

# Minimal Python version sanity check
v = sys.version_info
if v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):
error = "ERROR: %s requires Python version 2.7 or 3.3 or above." % name
if sys.version_info < (3,5):
error = "ERROR: %s requires Python version 3.5 or above." % name
print(error, file=sys.stderr)
sys.exit(1)

Expand Down Expand Up @@ -67,8 +66,10 @@
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
zip_safe = False,
install_requires = [
Expand All @@ -90,12 +91,11 @@
"pywin32>=1.0 ; sys_platform == 'win32'"
],
extras_require = {
':python_version == "2.7"': ['ipaddress'],
'test:python_version == "2.7"': ['mock'],
'test': ['nose', 'coverage', 'requests', 'nose_warnings_filters',
'nbval', 'nose-exclude', 'selenium'],
'test:sys_platform == "win32"': ['nose-exclude'],
},
python_requires='>=3.5',
entry_points = {
'console_scripts': [
'jupyter-server = jupyter_server.serverapp:main',
Expand Down

0 comments on commit ff63d37

Please sign in to comment.