Skip to content
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
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Top-most EditorConfig file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Carreau @gnestor thoughts on adding this file? It seems reasonable to me, but I know people sometimes take issue with ever more config files in the repo root directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok adding it, but I don't know of a lot of people using that. It may likely just rot as the tox.ini file which is never used and still test on Python 27 as shown further in this PR.

root = true

[*]
# Unix-style newlines with a newline ending every file
end_of_line = lf
insert_final_newline = true
charset = utf-8

# Four-space indentation
indent_size = 4
indent_style = space

trim_trailing_whitespace = false

[*.yml]
# Two-space indentation
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ __pycache__
.DS_Store
\#*#
.#*
.cache
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that also be in your system global .gitignore if you feel the need to add it ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, but it's in the common Python one --https://github.com/github/gitignore/blob/master/Python.gitignore#L43 -- and ignored in some other Python projects I just checked. And it showed up after running the tests for this project (iptest --coverage xml ), so it can show up for others too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure exactly what creates it, but I see it quite often when running tests, so I'm fine with adding it to gitignore.

.coverage
*.swp
4 changes: 2 additions & 2 deletions IPython/core/magics/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def shebang(self, line, cell):
print("Error while terminating subprocess (pid=%i): %s" \
% (p.pid, e))
return
out = py3compat.bytes_to_str(out)
err = py3compat.bytes_to_str(err)
out = py3compat.decode(out)
err = py3compat.decode(err)
if args.out:
self.shell.user_ns[args.out] = out
else:
Expand Down
1 change: 0 additions & 1 deletion IPython/core/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from IPython.core.application import BaseIPythonApplication
from IPython.testing import decorators as dec
from IPython.utils import py3compat
from IPython.utils.tempdir import TemporaryDirectory


Expand Down
1 change: 0 additions & 1 deletion IPython/core/tests/test_compilerop.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

# Our own imports
from IPython.core import compilerop
from IPython.utils import py3compat

#-----------------------------------------------------------------------------
# Test functions
Expand Down
1 change: 0 additions & 1 deletion IPython/core/tests/test_completerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import nose.tools as nt

from IPython.core.completerlib import magic_run_completer, module_completion
from IPython.utils import py3compat
from IPython.utils.tempdir import TemporaryDirectory
from IPython.testing.decorators import onlyif_unicode_paths

Expand Down
1 change: 0 additions & 1 deletion IPython/core/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from traitlets.config.loader import Config
from IPython.utils.tempdir import TemporaryDirectory
from IPython.core.history import HistoryManager, extract_hist_ranges
from IPython.utils import py3compat

def setUp():
nt.assert_equal(sys.getdefaultencoding(), "utf-8")
Expand Down
2 changes: 0 additions & 2 deletions IPython/core/tests/test_interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import tempfile
import unittest
from unittest import mock
from io import StringIO

from os.path import join

Expand All @@ -30,7 +29,6 @@
)
from IPython.testing import tools as tt
from IPython.utils.process import find_cmd
from IPython.utils import py3compat

#-----------------------------------------------------------------------------
# Globals
Expand Down
6 changes: 2 additions & 4 deletions IPython/core/tests/test_oinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
register_line_cell_magic)
from decorator import decorator
from IPython import get_ipython
from IPython.testing.decorators import skipif
from IPython.testing.tools import AssertPrints, AssertNotPrints
from IPython.utils.path import compress_user
from IPython.utils import py3compat


#-----------------------------------------------------------------------------
Expand All @@ -40,14 +38,14 @@
# defined, if any code is inserted above, the following line will need to be
# updated. Do NOT insert any whitespace between the next line and the function
# definition below.
THIS_LINE_NUMBER = 43 # Put here the actual number of this line
THIS_LINE_NUMBER = 41 # Put here the actual number of this line

from unittest import TestCase

class Test(TestCase):

def test_find_source_lines(self):
self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines),
self.assertEqual(oinspect.find_source_lines(Test.test_find_source_lines),
THIS_LINE_NUMBER+6)


Expand Down
1 change: 0 additions & 1 deletion IPython/core/tests/test_splitinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from IPython.core.splitinput import split_user_input, LineInfo
from IPython.testing import tools as tt
from IPython.utils import py3compat

tests = [
('x=1', ('', '', 'x', '=1')),
Expand Down
43 changes: 20 additions & 23 deletions IPython/core/ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,35 +1136,32 @@ def structured_traceback(self, etype, evalue, etb, tb_offset=None,
colorsnormal = colors.Normal # used a lot
head = '%s%s%s' % (colors.topline, '-' * min(75, get_terminal_size()[0]), colorsnormal)
structured_traceback_parts = [head]
if py3compat.PY3:
chained_exceptions_tb_offset = 0
lines_of_context = 3
formatted_exceptions = formatted_exception
chained_exceptions_tb_offset = 0
lines_of_context = 3
formatted_exceptions = formatted_exception
exception = self.get_parts_of_chained_exception(evalue)
if exception:
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
etype, evalue, etb = exception
else:
evalue = None
chained_exc_ids = set()
while evalue:
formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
chained_exceptions_tb_offset)
exception = self.get_parts_of_chained_exception(evalue)
if exception:

if exception and not id(exception[1]) in chained_exc_ids:
chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
etype, evalue, etb = exception
else:
evalue = None
chained_exc_ids = set()
while evalue:
formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
chained_exceptions_tb_offset)
exception = self.get_parts_of_chained_exception(evalue)

if exception and not id(exception[1]) in chained_exc_ids:
chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop
formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__)
etype, evalue, etb = exception
else:
evalue = None

# we want to see exceptions in a reversed order:
# the first exception should be on top
for formatted_exception in reversed(formatted_exceptions):
structured_traceback_parts += formatted_exception
else:
structured_traceback_parts += formatted_exception[0]
# we want to see exceptions in a reversed order:
# the first exception should be on top
for formatted_exception in reversed(formatted_exceptions):
structured_traceback_parts += formatted_exception

return structured_traceback_parts

Expand Down
1 change: 0 additions & 1 deletion IPython/extensions/autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
import types
import weakref
from importlib import import_module
from IPython.utils.py3compat import PY3
from imp import reload

from IPython.utils import openpy
Expand Down
6 changes: 3 additions & 3 deletions IPython/lib/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Our own
from IPython.core.error import UsageError
from IPython.utils.py3compat import cast_bytes, str_to_bytes
from IPython.utils.py3compat import encode

#-----------------------------------------------------------------------------
# Globals
Expand Down Expand Up @@ -65,7 +65,7 @@ def passwd(passphrase=None, algorithm='sha1'):

h = hashlib.new(algorithm)
salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len)
h.update(cast_bytes(passphrase, 'utf-8') + str_to_bytes(salt, 'ascii'))
h.update(encode(passphrase, 'utf-8') + encode(salt, 'ascii'))

return ':'.join((algorithm, salt, h.hexdigest()))

Expand Down Expand Up @@ -109,6 +109,6 @@ def passwd_check(hashed_passphrase, passphrase):
if len(pw_digest) == 0:
return False

h.update(cast_bytes(passphrase, 'utf-8') + cast_bytes(salt, 'ascii'))
h.update(encode(passphrase, 'utf-8') + encode(salt, 'ascii'))

return h.hexdigest() == pw_digest
4 changes: 2 additions & 2 deletions IPython/terminal/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
from IPython.utils import io
from IPython.utils.py3compat import input, cast_unicode_py2
from IPython.utils.py3compat import input
from IPython.utils.terminal import toggle_set_term_title, set_term_title
from IPython.utils.process import abbrev_cwd
from traitlets import (
Expand Down Expand Up @@ -233,7 +233,7 @@ def prompt():
prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens())
prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens())
while isp.push_accepts_more():
line = cast_unicode_py2(input(prompt_text))
line = input(prompt_text)
isp.push(line)
prompt_text = prompt_continuation
return isp.source_reset()
Expand Down
10 changes: 4 additions & 6 deletions IPython/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import sys
import os
import shutil
import sys
import tempfile
import unittest
import warnings
Expand All @@ -48,9 +49,6 @@
# numpy.testing.decorators, we expose all of it here.
from IPython.external.decorators import *

# For onlyif_cmd_exists decorator
from IPython.utils.py3compat import which

#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -360,7 +358,7 @@ def onlyif_cmds_exist(*commands):
Decorator to skip test when at least one of `commands` is not found.
"""
for cmd in commands:
if not which(cmd):
if not shutil.which(cmd):
return skip("This test runs only if command '{0}' "
"is installed".format(cmd))
return null_deco
Expand All @@ -372,7 +370,7 @@ def onlyif_any_cmd_exists(*commands):
warnings.warn("The function `onlyif_any_cmd_exists` is deprecated since IPython 4.0",
DeprecationWarning, stacklevel=2)
for cmd in commands:
if which(cmd):
if shutil.which(cmd):
return null_deco
return skip("This test runs only if one of the commands {0} "
"is installed".format(commands))
8 changes: 4 additions & 4 deletions IPython/testing/globalipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

import builtins as builtin_mod
import sys
import types
import warnings

from . import tools

from IPython.core import page
from IPython.utils import io
from IPython.utils import py3compat
from IPython.terminal.interactiveshell import TerminalInteractiveShell


Expand Down Expand Up @@ -104,9 +104,9 @@ def start_ipython():
# Modify the IPython system call with one that uses getoutput, so that we
# can capture subcommands and print them to Python's stdout, otherwise the
# doctest machinery would miss them.
shell.system = py3compat.MethodType(xsys, shell)
shell._showtraceback = py3compat.MethodType(_showtraceback, shell)
shell.system = types.MethodType(xsys, shell)

shell._showtraceback = types.MethodType(_showtraceback, shell)

# IPython is ready, now clean up some global state...

Expand Down
6 changes: 3 additions & 3 deletions IPython/testing/iptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from nose.util import safe_str

from IPython import version_info
from IPython.utils.py3compat import bytes_to_str
from IPython.utils.py3compat import decode
from IPython.utils.importstring import import_item
from IPython.testing.plugin.ipdoctest import IPythonDoctest
from IPython.external.decorators import KnownFailure, knownfailureif
Expand Down Expand Up @@ -299,8 +299,8 @@ def run(self):
with self.buffer_lock:
self.buffer.write(chunk)
if self.echo:
sys.stdout.write(bytes_to_str(chunk))
sys.stdout.write(decode(chunk))

os.close(self.readfd)
os.close(self.writefd)

Expand Down
4 changes: 2 additions & 2 deletions IPython/testing/iptestcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
have, test_group_names as py_test_group_names, test_sections, StreamCapturer,
)
from IPython.utils.path import compress_user
from IPython.utils.py3compat import bytes_to_str
from IPython.utils.py3compat import decode
from IPython.utils.sysinfo import get_sys_info
from IPython.utils.tempdir import TemporaryDirectory

Expand Down Expand Up @@ -371,7 +371,7 @@ def justify(ltext, rtext, width=70, fill='-'):
print(justify('Test group: ' + controller.section, res_string))
if res:
controller.print_extra_info()
print(bytes_to_str(controller.stdout))
print(decode(controller.stdout))
failed.append(controller)
if res == -signal.SIGINT:
print("Interrupted")
Expand Down
5 changes: 2 additions & 3 deletions IPython/testing/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from IPython.utils.text import list_strings
from IPython.utils.io import temp_pyfile, Tee
from IPython.utils import py3compat
from IPython.utils.encoding import DEFAULT_ENCODING

from . import decorators as dec
from . import skipdoctest
Expand Down Expand Up @@ -210,8 +209,8 @@ def ipexec(fname, options=None, commands=()):
if not isinstance(v, str):
print(k, v)
p = Popen(full_cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE, env=env)
out, err = p.communicate(input=py3compat.str_to_bytes('\n'.join(commands)) or None)
out, err = py3compat.bytes_to_str(out), py3compat.bytes_to_str(err)
out, err = p.communicate(input=py3compat.encode('\n'.join(commands)) or None)
out, err = py3compat.decode(out), py3compat.decode(err)
# `import readline` causes 'ESC[?1034h' to be output sometimes,
# so strip that out before doing comparisons
if out:
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/_process_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _find_cmd(cmd):
for path in paths:
filename = os.path.join(path, cmd)
if System.IO.File.Exists(filename):
return py3compat.bytes_to_str(filename)
return py3compat.decode(filename)
raise OSError("command %r not found" % cmd)

def system(cmd):
Expand Down
4 changes: 2 additions & 2 deletions IPython/utils/_process_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def getoutput(cmd):
out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
if out is None:
return ''
return py3compat.bytes_to_str(out)
return py3compat.decode(out)


def getoutputerror(cmd):
Expand Down Expand Up @@ -172,7 +172,7 @@ def get_output_error_code(cmd):
if out_err is None:
return '', '', p.returncode
out, err = out_err
return py3compat.bytes_to_str(out), py3compat.bytes_to_str(err), p.returncode
return py3compat.decode(out), py3compat.decode(err), p.returncode

def arg_split(s, posix=False, strict=True):
"""Split a command line's arguments in a shell-like manner.
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/_process_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _find_cmd(cmd):

path = sp.Popen(['/usr/bin/env', 'which', cmd],
stdout=sp.PIPE, stderr=sp.PIPE).communicate()[0]
return py3compat.bytes_to_str(path)
return py3compat.decode(path)


class ProcessHandler(object):
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/_process_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def getoutput(cmd):

if out is None:
out = b''
return py3compat.bytes_to_str(out)
return py3compat.decode(out)

try:
CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
Expand Down
Loading