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

Drop Python 2 legacy code #586

Merged
merged 1 commit into from
Apr 20, 2021
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
5 changes: 1 addition & 4 deletions docs/source/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ For manual registration see :doc:`extensions`.
Dependencies
------------

nbdime requires Python version 3.3 or higher. If you are using Python 2,
nbdime requires 2.7.1 or higher.
nbdime requires Python version 3.6 or higher.

nbdime depends on the following Python packages,
which will be installed by :command:`pip`:

- six
- nbformat
- tornado
- colorama
- backports.shutil_which (on python 2.7)

and nbdime's web-based viewers depend on the following Node.js packages:

Expand Down
24 changes: 0 additions & 24 deletions docs/source/nodevenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,3 @@ For example with Python 3.5, the steps with output are::
* Install prebuilt node (7.2.0) ..... done.
* Appending data to /Users/username/myenv/bin/activate
(myenv) $

Using Python 2.7, the steps with output are (note: you may need to install
virtualenv as shown here)::

$ python2 -m pip install virtualenv
Collecting virtualenv
Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |████████████████████████████████| 1.8MB 600kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
$ python2 -m virtualenv myenv
New python executable in /Users/username/myenv/bin/python
Installing setuptools, pip, wheel...done.
$ source myenv/bin/activate
(myenv) $ pip install nodeenv
Collecting nodeenv
Downloading nodeenv-1.0.0.tar.gz
Installing collected packages: nodeenv
Running setup.py install for nodeenv ... done
Successfully installed nodeenv-1.0.0
(myenv) $ nodeenv -p
* Install prebuilt node (7.2.0) ..... done.
* Appending data to /Users/username/myenv/bin/activate
(myenv) $
2 changes: 0 additions & 2 deletions nbdime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from ._version import __version__

from .diffing import diff, diff_notebooks
Expand Down
8 changes: 1 addition & 7 deletions nbdime/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals
from __future__ import print_function

import sys
from subprocess import call

import nbdime
from ._version import __version__

try:
from shutil import which
except ImportError:
from backports.shutil_which import which
from shutil import which

COMMANDS = ["show", "diff", "merge", "diff-web", "merge-web", "mergetool",
"config-git", "extensions"]
Expand Down
3 changes: 1 addition & 2 deletions nbdime/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import os
from six import string_types

from ipython_genutils import py3compat
from jupyter_core.paths import jupyter_config_path
Expand Down Expand Up @@ -161,7 +160,7 @@ def validate_elements(self, obj, value):
raise TraitError('ignore config paths need to start with `/`')
if not (v in (True, False) or
(isinstance(v, (tuple, list, set)) and
all(isinstance(i, string_types) for i in v)
all(isinstance(i, str) for i in v)
)):
raise TraitError('ignore config value needs to be True, False or a list of strings')
return self.klass(value)
Expand Down
8 changes: 2 additions & 6 deletions nbdime/diff_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from six import string_types

from .log import NBDiffFormatError


Expand Down Expand Up @@ -195,7 +191,7 @@ def validate_diff(diff, deep=False):
validate_diff_entry(e, deep=deep)


sequence_types = string_types + (list,)
sequence_types = (str, list)


def validate_diff_entry(e, deep=False):
Expand Down Expand Up @@ -230,7 +226,7 @@ def validate_diff_entry(e, deep=False):
validate_diff(e.diff, deep=deep)
else:
raise NBDiffFormatError("Unknown diff op '{}'.".format(op))
elif isinstance(key, string_types) and op in MappingDiffBuilder.OPS:
elif isinstance(key, str) and op in MappingDiffBuilder.OPS:
if op == DiffOp.ADD:
pass # e.value is a single value to insert at key
elif op == DiffOp.REMOVE:
Expand Down
15 changes: 6 additions & 9 deletions nbdime/diff_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import itertools
import copy

from six import string_types
from six.moves import xrange as range

from .diff_format import DiffOp, DiffEntry, op_addrange, op_removerange
from .log import NBDiffFormatError

Expand Down Expand Up @@ -50,7 +47,7 @@ def source_as_string(source):
"""Return source as a single string, joined as lines if it's a list."""
if isinstance(source, list):
source = "\n".join(line.strip("\n") for line in source)
if not isinstance(source, string_types):
if not isinstance(source, str):
raise TypeError("Invalid argument type. Should be string or sequence of strings."
"Got %r" % source)
return source
Expand Down Expand Up @@ -94,7 +91,7 @@ def _combine_ops(existing, new):
if new.op == DiffOp.ADDRANGE:
d.valuelist += new.valuelist
else:
if isinstance(d.valuelist, string_types):
if isinstance(d.valuelist, str):
d.valuelist += new.value
else:
d.valuelist.append(new.value)
Expand All @@ -108,7 +105,7 @@ def flatten_list_of_string_diff(a, linebased_diff):
"""Translates a diff of strings split by str.splitlines(True) to a diff of
the joined multiline string.
"""
if isinstance(a, string_types):
if isinstance(a, str):
a = a.splitlines(True)

line_to_char = [0] + list(_accum(len(ia) for ia in a))
Expand Down Expand Up @@ -196,15 +193,15 @@ def to_json_patch(d, path=""):
for e in d:
op = e.op
if op == DiffOp.ADD:
assert isinstance(e.key, string_types), "'add' diff op needs string key"
assert isinstance(e.key, str), "'add' diff op needs string key"
p = "/".join([path, e.key])
jp.append({"op": "add", "path": p, "value": e.value})
elif op == DiffOp.REPLACE:
assert isinstance(e.key, string_types), "'replace' diff op needs string key"
assert isinstance(e.key, str), "'replace' diff op needs string key"
p = "/".join([path, e.key])
jp.append({"op": "replace", "path": p, "value": e.value})
elif op == DiffOp.REMOVE:
assert isinstance(e.key, string_types), "'remove' diff op needs string key"
assert isinstance(e.key, str), "'remove' diff op needs string key"
p = "/".join([path, e.key])
jp.append({"op": "remove", "path": p})
elif op == DiffOp.ADDRANGE:
Expand Down
2 changes: 0 additions & 2 deletions nbdime/diffing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from .generic import diff
from .notebooks import diff_notebooks

Expand Down
8 changes: 2 additions & 6 deletions nbdime/diffing/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from six import string_types
from six.moves import xrange as range
import operator
from collections import defaultdict
import difflib
Expand All @@ -22,7 +18,7 @@

def is_atomic(x):
"Return True for values that diff should treat as a single atomic value."
return not isinstance(x, string_types + (list, dict))
return not isinstance(x, (str, list, dict))


def default_predicates():
Expand Down Expand Up @@ -90,7 +86,7 @@ def diff(a, b, path="", predicates=None, differs=None):
d = diff_lists(a, b, path=path, predicates=predicates, differs=differs)
elif isinstance(a, dict) and isinstance(b, dict):
d = diff_dicts(a, b, path=path, predicates=predicates, differs=differs)
elif isinstance(a, string_types) and isinstance(b, string_types):
elif isinstance(a, str) and isinstance(b, str):
# Don't pass differs/predicates as the only possible use case is to
# use a different character differ within each line or predicates
# for comparing lines
Expand Down
4 changes: 0 additions & 4 deletions nbdime/diffing/lcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from six.moves import xrange as range

from ..diff_format import SequenceDiffBuilder


Expand Down
11 changes: 2 additions & 9 deletions nbdime/diffing/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@
Up- and down-conversion is handled by nbformat.
"""

from __future__ import unicode_literals

import operator
import re
import copy
from six import string_types
from six.moves import zip
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
from functools import lru_cache

from ..diff_format import MappingDiffBuilder, DiffOp
from ..utils import defaultdict2
Expand Down Expand Up @@ -139,7 +132,7 @@ def _compare_mimedata(mimetype, x, y, comp_text, comp_base64):

# TODO: Compare binary images?
#if mimetype.startswith("image/"):
if isinstance(x, string_types) and isinstance(y, string_types):
if isinstance(x, str) and isinstance(y, str):
return _compare_mimedata_strings(x, y, comp_text, comp_base64)
# Fallback to exactly equal
return x == y
Expand Down
3 changes: 0 additions & 3 deletions nbdime/diffing/seq_bruteforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from six.moves import xrange as range
import operator
from .lcs import diff_from_lcs

Expand Down
2 changes: 0 additions & 2 deletions nbdime/diffing/seq_difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from difflib import SequenceMatcher
from ..diff_format import SequenceDiffBuilder

Expand Down
2 changes: 0 additions & 2 deletions nbdime/diffing/seq_myers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

import operator

__all__ = ["diff_sequence_myers"]
Expand Down
7 changes: 2 additions & 5 deletions nbdime/diffing/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

import operator
from six import string_types
from collections import defaultdict

from .seq_difflib import diff_sequence_difflib
Expand Down Expand Up @@ -42,7 +39,7 @@ def diff_sequence(a, b, compare=operator.__eq__):

def diff_strings_by_char(a, b, path="", predicates=None, differs=None):
"Compute char-based diff of two strings."
assert isinstance(a, string_types) and isinstance(b, string_types), (
assert isinstance(a, str) and isinstance(b, str), (
'Arguments need to be string types. Got %r and %r' % (a, b))
if a == b:
return []
Expand All @@ -53,7 +50,7 @@ def diff_strings_by_char(a, b, path="", predicates=None, differs=None):
def diff_strings_linewise(a, b):
"""Do a line-wise diff of two strings
"""
assert isinstance(a, string_types) and isinstance(b, string_types), (
assert isinstance(a, str) and isinstance(b, str), (
'Arguments need to be string types. Got %r and %r' % (a, b))
lines_a = a.splitlines(True)
lines_b = b.splitlines(True)
Expand Down
2 changes: 0 additions & 2 deletions nbdime/diffing/snakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Utilities for computing 'snakes', or contiguous sequences of equal elements of two sequences.
"""

from __future__ import unicode_literals

from ..diff_format import SequenceDiffBuilder
from .seq_bruteforce import bruteforce_compute_snakes

Expand Down
4 changes: 1 addition & 3 deletions nbdime/gitfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
from collections import deque

from six import string_types

os.environ['GIT_PYTHON_REFRESH'] = 'quiet'
from git import (
Repo, InvalidGitRepositoryError, BadName, NoSuchPathError,
Expand Down Expand Up @@ -153,7 +151,7 @@ def changed_notebooks(ref_base, ref_remote, paths=None, repo_dir=None):
repo, popped = get_repo(repo_dir or os.curdir)
if repo_dir is None:
repo_dir = os.path.relpath(repo.working_tree_dir, os.curdir)
if isinstance(paths, string_types):
if isinstance(paths, str):
paths = (paths,)
if paths and popped:
# All paths need to be prepended by popped
Expand Down
2 changes: 0 additions & 2 deletions nbdime/ignorables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

diff_ignorables = ('sources', 'outputs', 'attachments', 'metadata', 'id', 'details')
2 changes: 0 additions & 2 deletions nbdime/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

import logging


Expand Down
2 changes: 0 additions & 2 deletions nbdime/merging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from .generic import decide_merge
from .decisions import apply_decisions
from .notebooks import merge_notebooks
Expand Down
2 changes: 0 additions & 2 deletions nbdime/merging/autoresolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import print_function, unicode_literals

from ..diff_format import DiffOp, Deleted
from ..patching import patch
from ..utils import split_path, resolve_path
Expand Down
4 changes: 0 additions & 4 deletions nbdime/merging/chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from __future__ import unicode_literals

from six.moves import xrange as range

from ..diff_format import DiffOp, SequenceDiffBuilder


Expand Down
Loading