From e4e696c640f60afe8586732cc7591d9b9064b876 Mon Sep 17 00:00:00 2001 From: Frederic COLLONVAL Date: Sat, 17 Apr 2021 17:09:06 +0200 Subject: [PATCH] Remove Python 2.7 dedicated code Fixes #583 --- docs/source/installing.rst | 5 +--- docs/source/nodevenv.rst | 24 --------------- nbdime/__init__.py | 2 -- nbdime/__main__.py | 8 +---- nbdime/config.py | 3 +- nbdime/diff_format.py | 8 ++--- nbdime/diff_utils.py | 15 ++++------ nbdime/diffing/__init__.py | 2 -- nbdime/diffing/generic.py | 8 ++--- nbdime/diffing/lcs.py | 4 --- nbdime/diffing/notebooks.py | 11 ++----- nbdime/diffing/seq_bruteforce.py | 3 -- nbdime/diffing/seq_difflib.py | 2 -- nbdime/diffing/seq_myers.py | 2 -- nbdime/diffing/sequences.py | 7 ++--- nbdime/diffing/snakes.py | 2 -- nbdime/gitfiles.py | 4 +-- nbdime/ignorables.py | 2 -- nbdime/log.py | 2 -- nbdime/merging/__init__.py | 2 -- nbdime/merging/autoresolve.py | 2 -- nbdime/merging/chunks.py | 4 --- nbdime/merging/decisions.py | 17 ++++------- nbdime/merging/generic.py | 9 +++--- nbdime/merging/notebooks.py | 4 +-- nbdime/merging/strategies.py | 2 +- nbdime/nbdiffapp.py | 11 ++----- nbdime/nbmergeapp.py | 3 -- nbdime/nbpatchapp.py | 3 -- nbdime/nbshowapp.py | 3 -- nbdime/patching.py | 7 ++--- nbdime/prettyprint.py | 17 ++++------- nbdime/tests/__init__.py | 2 +- nbdime/tests/conftest.py | 29 ++++--------------- nbdime/tests/test_apply_merge.py | 2 +- nbdime/tests/test_args.py | 14 ++++----- nbdime/tests/test_autoresolve.py | 2 +- nbdime/tests/test_cli_apps.py | 9 +++--- nbdime/tests/test_decision_tools.py | 2 +- nbdime/tests/test_diff.py | 4 +-- nbdime/tests/test_diff_gitrefs.py | 8 ++--- nbdime/tests/test_diff_sequence.py | 2 -- nbdime/tests/test_diff_sequence_bruteforce.py | 2 -- nbdime/tests/test_diff_sequence_difflib.py | 3 +- nbdime/tests/test_git_diffdriver.py | 2 +- nbdime/tests/test_git_filter_integration.py | 2 +- nbdime/tests/test_hg_differ.py | 2 +- nbdime/tests/test_merge.py | 2 -- nbdime/tests/test_merge_notebooks.py | 5 ++-- nbdime/tests/test_myers.py | 5 ++-- nbdime/tests/test_notebook_diff.py | 4 +-- nbdime/tests/test_patch.py | 2 +- nbdime/tests/test_prettyprint.py | 18 +++--------- nbdime/tests/utils.py | 17 ++++------- nbdime/utils.py | 18 +++++------- nbdime/vcs/git/diffdriver.py | 2 +- nbdime/vcs/git/filter_integration.py | 2 +- nbdime/vcs/git/mergedriver.py | 2 +- nbdime/vcs/hg/diff.py | 2 +- nbdime/vcs/hg/diffweb.py | 2 +- nbdime/vcs/hg/merge.py | 2 +- nbdime/vcs/hg/mergeweb.py | 2 +- nbdime/webapp/nb_server_extension.py | 2 +- nbdime/webapp/nbdifftool.py | 4 +-- nbdime/webapp/nbdiffweb.py | 4 +-- nbdime/webapp/nbdimeserver.py | 15 +++++----- nbdime/webapp/nbmergetool.py | 4 +-- nbdime/webapp/nbmergeweb.py | 4 +-- nbdime/webapp/webutil.py | 2 +- setup.py | 3 -- 70 files changed, 117 insertions(+), 289 deletions(-) diff --git a/docs/source/installing.rst b/docs/source/installing.rst index 251794cb..f384dea0 100644 --- a/docs/source/installing.rst +++ b/docs/source/installing.rst @@ -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: diff --git a/docs/source/nodevenv.rst b/docs/source/nodevenv.rst index 1cb0aea3..d088f5a3 100644 --- a/docs/source/nodevenv.rst +++ b/docs/source/nodevenv.rst @@ -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) $ diff --git a/nbdime/__init__.py b/nbdime/__init__.py index 9f6f321a..704857c9 100644 --- a/nbdime/__init__.py +++ b/nbdime/__init__.py @@ -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 diff --git a/nbdime/__main__.py b/nbdime/__main__.py index 36e73557..25da5096 100644 --- a/nbdime/__main__.py +++ b/nbdime/__main__.py @@ -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"] diff --git a/nbdime/config.py b/nbdime/config.py index 7f538c1b..450d9af2 100644 --- a/nbdime/config.py +++ b/nbdime/config.py @@ -1,6 +1,5 @@ import os -from six import string_types from ipython_genutils import py3compat from jupyter_core.paths import jupyter_config_path @@ -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) diff --git a/nbdime/diff_format.py b/nbdime/diff_format.py index 545bb27e..749c70ca 100644 --- a/nbdime/diff_format.py +++ b/nbdime/diff_format.py @@ -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 @@ -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): @@ -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: diff --git a/nbdime/diff_utils.py b/nbdime/diff_utils.py index 82b7d14d..2dea7455 100644 --- a/nbdime/diff_utils.py +++ b/nbdime/diff_utils.py @@ -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 @@ -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 @@ -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) @@ -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)) @@ -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: diff --git a/nbdime/diffing/__init__.py b/nbdime/diffing/__init__.py index 8009e951..c9eff1f9 100644 --- a/nbdime/diffing/__init__.py +++ b/nbdime/diffing/__init__.py @@ -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 diff --git a/nbdime/diffing/generic.py b/nbdime/diffing/generic.py index 424f7615..5c164cae 100644 --- a/nbdime/diffing/generic.py +++ b/nbdime/diffing/generic.py @@ -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 @@ -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(): @@ -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 diff --git a/nbdime/diffing/lcs.py b/nbdime/diffing/lcs.py index 1d22752a..20f8c02f 100644 --- a/nbdime/diffing/lcs.py +++ b/nbdime/diffing/lcs.py @@ -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 diff --git a/nbdime/diffing/notebooks.py b/nbdime/diffing/notebooks.py index 6d32df83..5a810a42 100644 --- a/nbdime/diffing/notebooks.py +++ b/nbdime/diffing/notebooks.py @@ -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 @@ -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 diff --git a/nbdime/diffing/seq_bruteforce.py b/nbdime/diffing/seq_bruteforce.py index 744dd998..6bb751a3 100644 --- a/nbdime/diffing/seq_bruteforce.py +++ b/nbdime/diffing/seq_bruteforce.py @@ -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 diff --git a/nbdime/diffing/seq_difflib.py b/nbdime/diffing/seq_difflib.py index da8f9f24..471e234d 100644 --- a/nbdime/diffing/seq_difflib.py +++ b/nbdime/diffing/seq_difflib.py @@ -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 diff --git a/nbdime/diffing/seq_myers.py b/nbdime/diffing/seq_myers.py index 3331bd9b..31717d7b 100644 --- a/nbdime/diffing/seq_myers.py +++ b/nbdime/diffing/seq_myers.py @@ -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"] diff --git a/nbdime/diffing/sequences.py b/nbdime/diffing/sequences.py index 2c5bfde0..d44becb4 100644 --- a/nbdime/diffing/sequences.py +++ b/nbdime/diffing/sequences.py @@ -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 @@ -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 [] @@ -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) diff --git a/nbdime/diffing/snakes.py b/nbdime/diffing/snakes.py index 990c07a2..91f0d9f7 100644 --- a/nbdime/diffing/snakes.py +++ b/nbdime/diffing/snakes.py @@ -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 diff --git a/nbdime/gitfiles.py b/nbdime/gitfiles.py index 87824b6e..bdea1c44 100644 --- a/nbdime/gitfiles.py +++ b/nbdime/gitfiles.py @@ -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, @@ -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 diff --git a/nbdime/ignorables.py b/nbdime/ignorables.py index 1d7145b6..925a5411 100644 --- a/nbdime/ignorables.py +++ b/nbdime/ignorables.py @@ -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') diff --git a/nbdime/log.py b/nbdime/log.py index e1770a7e..ece8db0e 100644 --- a/nbdime/log.py +++ b/nbdime/log.py @@ -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 diff --git a/nbdime/merging/__init__.py b/nbdime/merging/__init__.py index c89dd359..eaf9e0a1 100644 --- a/nbdime/merging/__init__.py +++ b/nbdime/merging/__init__.py @@ -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 diff --git a/nbdime/merging/autoresolve.py b/nbdime/merging/autoresolve.py index b6cc0d26..218a3fb8 100644 --- a/nbdime/merging/autoresolve.py +++ b/nbdime/merging/autoresolve.py @@ -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 diff --git a/nbdime/merging/chunks.py b/nbdime/merging/chunks.py index 27fed323..7ccc6a0a 100644 --- a/nbdime/merging/chunks.py +++ b/nbdime/merging/chunks.py @@ -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 diff --git a/nbdime/merging/decisions.py b/nbdime/merging/decisions.py index 11c90388..112a0340 100644 --- a/nbdime/merging/decisions.py +++ b/nbdime/merging/decisions.py @@ -3,11 +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, text_type -from six.moves import xrange as range - import copy import nbformat @@ -470,9 +465,9 @@ def _sort_key(k): """ ret = [] for s in k.common_path: - if not isinstance(s, (int, text_type)): + if not isinstance(s, (int, str)): s = s.decode("utf8") - if isinstance(s, text_type) and r_is_int.match(s): + if isinstance(s, str) and r_is_int.match(s): s = int(s) if isinstance(s, int): ret.append(('', -s)) @@ -493,7 +488,7 @@ def split_string_path(base, path): position, and any line key in the second position. """ for i in range(len(path)): - if isinstance(base, string_types): + if isinstance(base, str): return path[:i], path[i:] base = base[path[i]] return path, () @@ -507,7 +502,7 @@ def make_cleared_value(value): elif isinstance(value, dict): # Clearing e.g. a metadata dict means setting it to an empty dict return {} - elif isinstance(value, string_types): + elif isinstance(value, str): # Clearing e.g. a source string means setting it to an empty string return "" else: @@ -573,7 +568,7 @@ def resolve_action(base, decision): key, = set(d.key for d in decision.local_diff + decision.remote_diff) if a == 'clear': return [op_replace(key, make_cleared_value(base[key]))] - elif isinstance(base, (list,) + string_types): + elif isinstance(base, (list, str)): return [op_removerange(key, 1)] else: return [op_remove(key)] @@ -583,7 +578,7 @@ def resolve_action(base, decision): # Ideally we would do a op_replace on the parent, but this is not # easily combined with this method, so simply remove all keys return [op_remove(key) for key in base.keys()] - elif isinstance(base, (list,) + string_types): + elif isinstance(base, (list, str)): return [op_removerange(0, len(base))] elif a == "take_max": diff --git a/nbdime/merging/generic.py b/nbdime/merging/generic.py index 5df58f62..e8107ea0 100644 --- a/nbdime/merging/generic.py +++ b/nbdime/merging/generic.py @@ -3,9 +3,8 @@ # 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 collections import defaultdict import nbdime.log @@ -497,7 +496,7 @@ def _merge_lists(base, local_diff, remote_diff, path, parent_decisions, strategi nbdime.log.error("Not expecting conflicting two-sided removal at this point.") # Workaround for string merge - elif isinstance(base, string_types) and chunktype == "AP/AP": + elif isinstance(base, str) and chunktype == "AP/AP": # If we get here, base is a single line from a parent multiline string. # item_strategy points to characters, list_strategy points to lines, @@ -639,7 +638,7 @@ def _merge_lists(base, local_diff, remote_diff, path, parent_decisions, strategi def _merge_strings(base, local_diff, remote_diff, path, parent_decisions, strategies): """Perform a three-way merge of strings. See docstring of merge.""" - assert isinstance(base, string_types) + assert isinstance(base, str) # This functions uses a (static) state variable to track recursion. # The first time it is called, base can (potentially) be a @@ -714,7 +713,7 @@ def _merge(base, local_diff, remote_diff, path, decisions, strategies): return _merge_lists( base, local_diff, remote_diff, path, decisions, strategies) - elif isinstance(base, string_types): + elif isinstance(base, str): return _merge_strings( base, local_diff, remote_diff, path, decisions, strategies) diff --git a/nbdime/merging/notebooks.py b/nbdime/merging/notebooks.py index ea49ed19..4b58d552 100644 --- a/nbdime/merging/notebooks.py +++ b/nbdime/merging/notebooks.py @@ -3,9 +3,9 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals -from six import StringIO + +from io import StringIO from .generic import decide_merge_with_diff from .decisions import apply_decisions diff --git a/nbdime/merging/strategies.py b/nbdime/merging/strategies.py index 9f239ed9..4aff35c0 100644 --- a/nbdime/merging/strategies.py +++ b/nbdime/merging/strategies.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + from collections import defaultdict from itertools import chain diff --git a/nbdime/nbdiffapp.py b/nbdime/nbdiffapp.py index ece783a1..5feaeb6b 100644 --- a/nbdime/nbdiffapp.py +++ b/nbdime/nbdiffapp.py @@ -3,15 +3,10 @@ # 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 json import os import sys -from six import string_types - from .args import ( add_generic_args, add_diff_args, process_diff_flags, resolve_diff_args, add_diff_cli_args, add_prettyprint_args, ConfigBackedParser, @@ -52,7 +47,7 @@ def _handle_diff(base, remote, output, args): # Check that if args are filenames they either exist, or are # explicitly marked as missing (added/removed): for fn in (base, remote): - if (isinstance(fn, string_types) and not os.path.exists(fn) and + if (isinstance(fn, str) and not os.path.exists(fn) and fn != EXPLICIT_MISSING_FILE): print("Missing file {}".format(fn)) return 1 @@ -83,8 +78,8 @@ def write(self, text): # This sets up what to ignore: config = prettyprint_config_from_args(args, out=Printer()) # Separate out filenames: - base_name = base if isinstance(base, string_types) else base.name - remote_name = remote if isinstance(remote, string_types) else remote.name + base_name = base if isinstance(base, str) else base.name + remote_name = remote if isinstance(remote, str) else remote.name pretty_print_notebook_diff(base_name, remote_name, a, d, config) return 0 diff --git a/nbdime/nbmergeapp.py b/nbdime/nbmergeapp.py index fa7d9229..43948d7a 100644 --- a/nbdime/nbmergeapp.py +++ b/nbdime/nbmergeapp.py @@ -3,9 +3,6 @@ # 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 io import os import sys diff --git a/nbdime/nbpatchapp.py b/nbdime/nbpatchapp.py index e70a1daf..6433af6c 100644 --- a/nbdime/nbpatchapp.py +++ b/nbdime/nbpatchapp.py @@ -3,9 +3,6 @@ # 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 os import sys import json diff --git a/nbdime/nbshowapp.py b/nbdime/nbshowapp.py index 252fce11..dd0eb5c6 100644 --- a/nbdime/nbshowapp.py +++ b/nbdime/nbshowapp.py @@ -3,9 +3,6 @@ # 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 os import sys diff --git a/nbdime/patching.py b/nbdime/patching.py index 93f44b23..050a86ef 100644 --- a/nbdime/patching.py +++ b/nbdime/patching.py @@ -3,10 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals - import copy -from six import string_types import nbformat from nbformat import NotebookNode @@ -92,7 +89,7 @@ def patch_dict(obj, diff): for e in diff: op = e.op key = e.key - assert isinstance(key, string_types), 'dict key must be string' + assert isinstance(key, str), 'dict key must be string' assert key not in newobj, 'multiple diff entries target same key: %r' % key if op == DiffOp.ADD: @@ -133,7 +130,7 @@ def patch(obj, diff): return patch_dict(obj, diff) elif isinstance(obj, list): return patch_list(obj, diff) - elif isinstance(obj, string_types): + elif isinstance(obj, str): return patch_string(obj, diff) else: raise ValueError("Invalid object type to patch: {}".format(type(obj).__name__)) diff --git a/nbdime/prettyprint.py b/nbdime/prettyprint.py index 5fb9fa4f..d3744351 100644 --- a/nbdime/prettyprint.py +++ b/nbdime/prettyprint.py @@ -3,9 +3,6 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals -from __future__ import print_function - from collections import namedtuple import datetime from difflib import unified_diff @@ -19,13 +16,9 @@ import sys import tempfile -try: - from shutil import which -except ImportError: - from backports.shutil_which import which +from shutil import which import colorama -from six import string_types from .diff_format import NBDiffFormatError, DiffOp, op_patch from .ignorables import diff_ignorables @@ -430,7 +423,7 @@ def _trim_base64(s): def format_value(v): "Format simple value for printing. Snips base64 strings and uses pprint for the rest." - if not isinstance(v, string_types): + if not isinstance(v, str): # Not a string, defer to pprint vstr = pprint.pformat(v) else: @@ -525,7 +518,7 @@ def pretty_print_item(k, v, prefix="", config=DefaultConfig): def pretty_print_multiline(text, prefix="", config=DefaultConfig): - assert isinstance(text, string_types), 'expected string argument' + assert isinstance(text, str), 'expected string argument' # Preprend prefix to lines, letting lines keep their own newlines lines = text.splitlines(True) @@ -858,7 +851,7 @@ def pretty_print_diff(a, di, path, config=DefaultConfig): pretty_print_dict_diff(a, di, path, config) elif isinstance(a, list): pretty_print_list_diff(a, di, path, config) - elif isinstance(a, string_types): + elif isinstance(a, str): pretty_print_string_diff(a, di, path, config) else: raise NBDiffFormatError( @@ -930,7 +923,7 @@ def pretty_print_merge_decision(base, decision, config=DefaultConfig): config.INFO.replace("##", "---"), dkey, note, config.RESET)) value = base for i, k in enumerate(decision.common_path): - if isinstance(value, string_types): + if isinstance(value, str): # Example case: # common_path = /cells/0/source/3 # value = nb.cells[0].source diff --git a/nbdime/tests/__init__.py b/nbdime/tests/__init__.py index 3b38a590..1fdd9eab 100644 --- a/nbdime/tests/__init__.py +++ b/nbdime/tests/__init__.py @@ -3,4 +3,4 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + diff --git a/nbdime/tests/conftest.py b/nbdime/tests/conftest.py index d3d509f0..bb38e41b 100644 --- a/nbdime/tests/conftest.py +++ b/nbdime/tests/conftest.py @@ -10,7 +10,8 @@ import glob import io import re -from subprocess import Popen +from collections.abc import Sequence +from subprocess import Popen, TimeoutExpired import sys from jsonschema import Draft4Validator as Validator @@ -23,28 +24,10 @@ from nbdime.diffing.notebooks import reset_notebook_differ -try: - # Python >= 3.3 - from subprocess import TimeoutExpired - def popen_wait(p, timeout): - return p.wait(timeout) -except ImportError: - import time - class TimeoutExpired(Exception): - pass - def popen_wait(p, timeout): - """backport of Popen.wait from Python 3""" - for _ in range(int(10 * timeout)): - if p.poll() is not None: - return - time.sleep(0.1) - if p.poll() is None: - raise TimeoutExpired - -try: - from collections.abc import Sequence -except ImportError: - from collections import Sequence + +def popen_wait(p, timeout): + return p.wait(timeout) + pjoin = os.path.join diff --git a/nbdime/tests/test_apply_merge.py b/nbdime/tests/test_apply_merge.py index b89b7300..be143e6a 100644 --- a/nbdime/tests/test_apply_merge.py +++ b/nbdime/tests/test_apply_merge.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + import copy import re diff --git a/nbdime/tests/test_args.py b/nbdime/tests/test_args.py index 0c523670..d1e3c0fb 100644 --- a/nbdime/tests/test_args.py +++ b/nbdime/tests/test_args.py @@ -3,8 +3,6 @@ import pytest import json -from six import text_type - from traitlets import Enum from nbdime.args import ( @@ -73,13 +71,13 @@ def test_config_parser(entrypoint_config): def test_ignore_config_simple(entrypoint_ignore_config, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text( - text_type(json.dumps({ + json.dumps({ 'IgnorableConfig1': { 'Ignore': { '/cells/*/metadata': ['collapsed', 'autoscroll'] } }, - })), + }), encoding='utf-8' ) @@ -100,7 +98,7 @@ def mock_ignore_keys(inner, keys): def test_ignore_config_merge(entrypoint_ignore_config, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text( - text_type(json.dumps({ + json.dumps({ 'IgnorableConfig1': { 'Ignore': { '/cells/*/metadata': ['collapsed', 'autoscroll'] @@ -112,7 +110,7 @@ def test_ignore_config_merge(entrypoint_ignore_config, tmpdir, reset_notebook_di '/cells/*/metadata': ['tags'] } }, - })), + }), encoding='utf-8' ) @@ -134,11 +132,11 @@ def mock_ignore_keys(inner, keys): def test_config_inherit(entrypoint_ignore_config, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text( - text_type(json.dumps({ + json.dumps({ 'IgnorableConfig1': { 'metadata': False }, - })), + }), encoding='utf-8' ) diff --git a/nbdime/tests/test_autoresolve.py b/nbdime/tests/test_autoresolve.py index a4c592a6..a83e825c 100644 --- a/nbdime/tests/test_autoresolve.py +++ b/nbdime/tests/test_autoresolve.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + from nbdime import merge_notebooks diff --git a/nbdime/tests/test_cli_apps.py b/nbdime/tests/test_cli_apps.py index 1e1da1f3..bc2280ca 100644 --- a/nbdime/tests/test_cli_apps.py +++ b/nbdime/tests/test_cli_apps.py @@ -8,7 +8,6 @@ import logging import os from pprint import pprint -from six import text_type from subprocess import CalledProcessError, check_call import sys import time @@ -202,13 +201,13 @@ def test_nbdiff_app_ignore_details(filespath, tmpdir, reset_notebook_diff): def test_nbdiff_app_config_ignores(filespath, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text( - text_type(json.dumps({ + json.dumps({ 'Diff': { 'Ignore': { '/cells/*/metadata': ['nbdime-dummy-field'] } }, - })), + }), encoding='utf-8' ) @@ -239,13 +238,13 @@ def test_nbdiff_app_flags_override_config_ignores(filespath, tmpdir, reset_noteb # This excercises current behavior, but should ideally (?) be different tmpdir.join('nbdime_config.json').write_text( - text_type(json.dumps({ + json.dumps({ 'Diff': { 'Ignore': { '/cells/*/metadata': ['nbdime-dummy-field'] } }, - })), + }), encoding='utf-8' ) diff --git a/nbdime/tests/test_decision_tools.py b/nbdime/tests/test_decision_tools.py index ee5af318..f1d4df16 100644 --- a/nbdime/tests/test_decision_tools.py +++ b/nbdime/tests/test_decision_tools.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + import pytest diff --git a/nbdime/tests/test_diff.py b/nbdime/tests/test_diff.py index ebf3569e..65cd7cba 100644 --- a/nbdime/tests/test_diff.py +++ b/nbdime/tests/test_diff.py @@ -3,8 +3,8 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals -from __future__ import print_function + + #import pytest #import copy diff --git a/nbdime/tests/test_diff_gitrefs.py b/nbdime/tests/test_diff_gitrefs.py index 00f461e1..107c5994 100644 --- a/nbdime/tests/test_diff_gitrefs.py +++ b/nbdime/tests/test_diff_gitrefs.py @@ -1,11 +1,7 @@ import os import shutil -from six import string_types -try: - from itertools import zip_longest -except ImportError: - from itertools import izip_longest as zip_longest +from itertools import zip_longest import pytest @@ -31,7 +27,7 @@ def _nb_name(f): - if isinstance(f, string_types): + if isinstance(f, str): return f return f.name diff --git a/nbdime/tests/test_diff_sequence.py b/nbdime/tests/test_diff_sequence.py index dc761491..9165d306 100644 --- a/nbdime/tests/test_diff_sequence.py +++ b/nbdime/tests/test_diff_sequence.py @@ -3,9 +3,7 @@ # 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 pytest diff --git a/nbdime/tests/test_diff_sequence_bruteforce.py b/nbdime/tests/test_diff_sequence_bruteforce.py index d0f847de..7e929c5e 100644 --- a/nbdime/tests/test_diff_sequence_bruteforce.py +++ b/nbdime/tests/test_diff_sequence_bruteforce.py @@ -3,9 +3,7 @@ # 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 nbdime import patch from nbdime.diff_format import is_valid_diff diff --git a/nbdime/tests/test_diff_sequence_difflib.py b/nbdime/tests/test_diff_sequence_difflib.py index 04511702..bf7b600c 100644 --- a/nbdime/tests/test_diff_sequence_difflib.py +++ b/nbdime/tests/test_diff_sequence_difflib.py @@ -3,9 +3,8 @@ # 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 nbdime import patch from nbdime.diffing.seq_difflib import diff_sequence_difflib from nbdime.diff_format import is_valid_diff diff --git a/nbdime/tests/test_git_diffdriver.py b/nbdime/tests/test_git_diffdriver.py index 4f62fd84..5c52811a 100644 --- a/nbdime/tests/test_git_diffdriver.py +++ b/nbdime/tests/test_git_diffdriver.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + import io import os diff --git a/nbdime/tests/test_git_filter_integration.py b/nbdime/tests/test_git_filter_integration.py index 2de0146b..9532838c 100644 --- a/nbdime/tests/test_git_filter_integration.py +++ b/nbdime/tests/test_git_filter_integration.py @@ -1,7 +1,7 @@ import io import os -from six import StringIO +from io import StringIO from subprocess import CalledProcessError import nbformat diff --git a/nbdime/tests/test_hg_differ.py b/nbdime/tests/test_hg_differ.py index 732fe21a..3ec2123f 100644 --- a/nbdime/tests/test_hg_differ.py +++ b/nbdime/tests/test_hg_differ.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + import os from os.path import join as pjoin diff --git a/nbdime/tests/test_merge.py b/nbdime/tests/test_merge.py index 9390d876..8cde193b 100644 --- a/nbdime/tests/test_merge.py +++ b/nbdime/tests/test_merge.py @@ -3,9 +3,7 @@ # 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 copy import pytest diff --git a/nbdime/tests/test_merge_notebooks.py b/nbdime/tests/test_merge_notebooks.py index 424cd45a..d7f71719 100644 --- a/nbdime/tests/test_merge_notebooks.py +++ b/nbdime/tests/test_merge_notebooks.py @@ -3,11 +3,10 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + import pytest import copy -from six import string_types import nbformat from nbdime.diff_format import op_patch, op_addrange, op_removerange, op_replace @@ -165,7 +164,7 @@ def src2nb(src, strip_ids=False): src is either a single multiline string to become one cell, or a list (cells) of lists (lines) of singleline strings. """ - if isinstance(src, string_types): + if isinstance(src, str): src = [[src]] if isinstance(src, list): src = sources_to_notebook(src) diff --git a/nbdime/tests/test_myers.py b/nbdime/tests/test_myers.py index e4a82c74..9dcc20fd 100644 --- a/nbdime/tests/test_myers.py +++ b/nbdime/tests/test_myers.py @@ -3,11 +3,10 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals -from __future__ import print_function + + import operator -from six.moves import xrange as range # Set to true to enable additional assertions, array access checking, and printouts diff --git a/nbdime/tests/test_notebook_diff.py b/nbdime/tests/test_notebook_diff.py index a5126012..84d06520 100644 --- a/nbdime/tests/test_notebook_diff.py +++ b/nbdime/tests/test_notebook_diff.py @@ -5,8 +5,8 @@ """This file contains tests applying to reference notebook files from the nbdime/tests/files/ directory.""" -from __future__ import unicode_literals -from __future__ import print_function + + import nbformat diff --git a/nbdime/tests/test_patch.py b/nbdime/tests/test_patch.py index f9df2f61..793331d0 100644 --- a/nbdime/tests/test_patch.py +++ b/nbdime/tests/test_patch.py @@ -3,7 +3,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals + from nbdime import patch from nbdime.diff_format import op_patch, op_add, op_remove, op_replace, op_addrange, op_removerange diff --git a/nbdime/tests/test_prettyprint.py b/nbdime/tests/test_prettyprint.py index 636230c8..87092c2c 100644 --- a/nbdime/tests/test_prettyprint.py +++ b/nbdime/tests/test_prettyprint.py @@ -3,22 +3,12 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -# Messes up tests by writing u'str': -#from __future__ import unicode_literals - -from __future__ import print_function - -try: - from base64 import encodebytes -except ImportError: - from base64 import encodestring as encodebytes +from base64 import encodebytes + import os -from six import StringIO +from io import StringIO -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock from nbformat import v4 diff --git a/nbdime/tests/utils.py b/nbdime/tests/utils.py index f47d3190..0536ed7f 100644 --- a/nbdime/tests/utils.py +++ b/nbdime/tests/utils.py @@ -3,10 +3,8 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import unicode_literals -from __future__ import print_function -from six import string_types + from contextlib import contextmanager import os @@ -23,10 +21,7 @@ from nbdime.diff_format import is_valid_diff -try: - from shutil import which -except ImportError: - from backports.shutil_which import which +from shutil import which pjoin = os.path.join @@ -90,7 +85,7 @@ def notebook_to_sources(nb, as_str=True): source = cell["source"] if as_str and isinstance(source, list): source = "\n".join([line.strip("\n") for line in source]) - elif not as_str and isinstance(source, string_types): + elif not as_str and isinstance(source, str): source = source.splitlines(True) sources.append(source) return sources @@ -104,7 +99,7 @@ def outputs_to_notebook(outputs, strip_ids=False): cell = nbformat.v4.new_code_cell() nb.cells.append(cell) for output in cell_outputs: - if isinstance(output, string_types): + if isinstance(output, str): output = nbformat.v4.new_output( output_type="display_data", data={ @@ -149,14 +144,14 @@ def call(cmd): if str, split into command list """ - if isinstance(cmd, string_types): + if isinstance(cmd, str): cmd = shlex.split(cmd) return check_call(cmd, stdout=sys.stdout, stderr=sys.stderr) def get_output(cmd, err=False, returncode=0): """Run a command and get its output (as text)""" - if isinstance(cmd, string_types): + if isinstance(cmd, str): cmd = shlex.split(cmd) stderr = STDOUT if err else sys.stderr try: diff --git a/nbdime/utils.py b/nbdime/utils.py index a73e0742..0f42db49 100644 --- a/nbdime/utils.py +++ b/nbdime/utils.py @@ -15,7 +15,6 @@ from contextlib import contextmanager import nbformat -from six import string_types, text_type, PY2 if os.name == 'nt': EXPLICIT_MISSING_FILE = 'nul' @@ -54,7 +53,7 @@ def read_notebook(f, on_null, on_empty=None): if on_empty is None: raise # Reraise if file is not empty - if isinstance(f, string_types): + if isinstance(f, str): with io.open(f, encoding='utf-8') as fo: if len(fo.read(10)) != 0: raise @@ -77,12 +76,12 @@ def as_text(text): def as_text_lines(text): - if isinstance(text, string_types): + if isinstance(text, str): text = text.splitlines(True) if isinstance(text, tuple): text = list(text) assert isinstance(text, list), 'text argument should be string or string sequence' - assert all(isinstance(t, string_types) for t in text), ( + assert all(isinstance(t, str) for t in text), ( 'text argument should be string or string sequence') return text @@ -92,7 +91,7 @@ def strings_to_lists(obj): return {k: strings_to_lists(v) for k, v in obj.items()} elif isinstance(obj, list): return [strings_to_lists(v) for v in obj] - elif isinstance(obj, string_types): + elif isinstance(obj, str): return obj.splitlines(True) else: return obj @@ -104,7 +103,7 @@ def revert_strings_to_lists(obj): elif isinstance(obj, list): if not obj: return obj - elif isinstance(obj[0], string_types): + elif isinstance(obj[0], str): return "".join(obj) else: return [revert_strings_to_lists(v) for v in obj] @@ -135,7 +134,7 @@ def star_path(path): if isinstance(p, int): path[i] = '*' else: - if not isinstance(p, text_type): + if not isinstance(p, str): p = p.decode() if r_is_int.match(p): path[i] = '*' @@ -289,10 +288,7 @@ def _setup_std_stream_encoding(): errors = getattr(stream, 'errors', None) or 'strict' # if error-handler is strict, switch to replace if errors == 'strict' or errors.startswith('surrogate'): - if PY2: - bin_stream = stream - else: - bin_stream = stream.buffer + bin_stream = stream.buffer new_stream = codecs.getwriter(enc)(bin_stream, errors='backslashreplace') setattr(sys, name, new_stream) diff --git a/nbdime/vcs/git/diffdriver.py b/nbdime/vcs/git/diffdriver.py index b602502d..b58a457d 100644 --- a/nbdime/vcs/git/diffdriver.py +++ b/nbdime/vcs/git/diffdriver.py @@ -16,7 +16,7 @@ git diff [ []] """ -from __future__ import print_function + import io import os diff --git a/nbdime/vcs/git/filter_integration.py b/nbdime/vcs/git/filter_integration.py index 4bfa31a6..42f1eb49 100644 --- a/nbdime/vcs/git/filter_integration.py +++ b/nbdime/vcs/git/filter_integration.py @@ -2,7 +2,7 @@ import io from subprocess import check_output, STDOUT, CalledProcessError -from six import StringIO +from io import StringIO from nbdime.utils import EXPLICIT_MISSING_FILE diff --git a/nbdime/vcs/git/mergedriver.py b/nbdime/vcs/git/mergedriver.py index ab3da17a..5d5f1755 100644 --- a/nbdime/vcs/git/mergedriver.py +++ b/nbdime/vcs/git/mergedriver.py @@ -16,7 +16,7 @@ git merge [ []] """ -from __future__ import print_function + import argparse import io diff --git a/nbdime/vcs/hg/diff.py b/nbdime/vcs/hg/diff.py index 4197e04a..f234c644 100644 --- a/nbdime/vcs/hg/diff.py +++ b/nbdime/vcs/hg/diff.py @@ -9,7 +9,7 @@ hg extdiff -p hg-nbdiff [ []] """ -from __future__ import print_function + import os import sys diff --git a/nbdime/vcs/hg/diffweb.py b/nbdime/vcs/hg/diffweb.py index 16855c32..e1da140a 100644 --- a/nbdime/vcs/hg/diffweb.py +++ b/nbdime/vcs/hg/diffweb.py @@ -9,7 +9,7 @@ hg extdiff -p hg-nbdiff [ []] """ -from __future__ import print_function + import os import sys diff --git a/nbdime/vcs/hg/merge.py b/nbdime/vcs/hg/merge.py index 131ad820..d66c55e7 100644 --- a/nbdime/vcs/hg/merge.py +++ b/nbdime/vcs/hg/merge.py @@ -9,7 +9,7 @@ hg merge [ []] """ -from __future__ import print_function + import argparse import sys diff --git a/nbdime/vcs/hg/mergeweb.py b/nbdime/vcs/hg/mergeweb.py index 41702dcf..098f4c6e 100644 --- a/nbdime/vcs/hg/mergeweb.py +++ b/nbdime/vcs/hg/mergeweb.py @@ -9,7 +9,7 @@ hg merge [ []] """ -from __future__ import print_function + import argparse import sys diff --git a/nbdime/webapp/nb_server_extension.py b/nbdime/webapp/nb_server_extension.py index 2949583e..30938d98 100644 --- a/nbdime/webapp/nb_server_extension.py +++ b/nbdime/webapp/nb_server_extension.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function + import json import os diff --git a/nbdime/webapp/nbdifftool.py b/nbdime/webapp/nbdifftool.py index bc0408ff..d5824697 100644 --- a/nbdime/webapp/nbdifftool.py +++ b/nbdime/webapp/nbdifftool.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals + + import sys diff --git a/nbdime/webapp/nbdiffweb.py b/nbdime/webapp/nbdiffweb.py index d6918bb2..51ab9d7a 100644 --- a/nbdime/webapp/nbdiffweb.py +++ b/nbdime/webapp/nbdiffweb.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals + + import sys diff --git a/nbdime/webapp/nbdimeserver.py b/nbdime/webapp/nbdimeserver.py index 3a4788ce..899cb9f7 100644 --- a/nbdime/webapp/nbdimeserver.py +++ b/nbdime/webapp/nbdimeserver.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals + + import io import json @@ -17,7 +17,6 @@ from jupyter_server.utils import url_path_join from jupyter_server.log import log_request import requests -from six import string_types from tornado import ioloop, web, escape, netutil, httpserver from .. import __file__ as nbdime_root @@ -76,7 +75,7 @@ def read_notebook(self, arg, fail_on_empty=True): # Currently assuming arg is a filename relative to # where the server was started from, later we may # want to accept urls or full notebooks as well. - if not isinstance(arg, string_types): + if not isinstance(arg, str): raise web.HTTPError(400, 'Expecting a filename or a URL.') try: @@ -102,7 +101,7 @@ def read_notebook(self, arg, fail_on_empty=True): if fail_on_empty: raise # Handle empty notebook file - if isinstance(path, string_types): + if isinstance(path, str): with io.open(path, encoding='utf-8') as fo: if len(fo.read(10)) != 0: raise @@ -173,11 +172,11 @@ def get(self): if 'difftool_args' in self.params: base = self.params['difftool_args']['base'] remote = self.params['difftool_args']['remote'] - if isinstance(base, string_types): + if isinstance(base, str): args['base'] = base else: args['base'] = base.name - if isinstance(remote, string_types): + if isinstance(remote, str): args['remote'] = remote else: args['remote'] = remote.name @@ -236,7 +235,7 @@ def post(self): def get_notebook_argument(self, argname): if 'difftool_args' in self.params: arg = self.params['difftool_args'][argname] - if not isinstance(arg, string_types): + if not isinstance(arg, str): # Assume arg is file-like arg.seek(0) return nbformat.read(arg, as_version=4) diff --git a/nbdime/webapp/nbmergetool.py b/nbdime/webapp/nbmergetool.py index b7510f1c..24a0b8b4 100644 --- a/nbdime/webapp/nbmergetool.py +++ b/nbdime/webapp/nbmergetool.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals + + import sys diff --git a/nbdime/webapp/nbmergeweb.py b/nbdime/webapp/nbmergeweb.py index 223ad0fb..3b9a7a51 100644 --- a/nbdime/webapp/nbmergeweb.py +++ b/nbdime/webapp/nbmergeweb.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals + + import sys diff --git a/nbdime/webapp/webutil.py b/nbdime/webapp/webutil.py index 60f2eb25..bbf4c64d 100644 --- a/nbdime/webapp/webutil.py +++ b/nbdime/webapp/webutil.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -from __future__ import print_function + import logging import threading diff --git a/setup.py b/setup.py index e7a3967f..2769493b 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,6 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. -from __future__ import print_function - import os import sys from glob import glob @@ -122,7 +120,6 @@ install_requires = setup_args['install_requires'] = [ 'nbformat', - 'six', 'colorama', 'pygments', 'tornado',