Skip to content

Commit

Permalink
Merge from 5.x: PR #20366
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jan 23, 2023
2 parents 70b1982 + 44ce22d commit 0dc8fa8
Show file tree
Hide file tree
Showing 86 changed files with 772 additions and 1,268 deletions.
7 changes: 1 addition & 6 deletions scripts/spyder_win_post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import sys
import os.path as osp
import struct
try:
# Python 2
import _winreg as winreg
except ImportError:
# Python 3
import winreg # analysis:ignore
import winreg


EWS = "Edit with Spyder"
Expand Down
6 changes: 3 additions & 3 deletions spyder/api/config/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_conf(self,
Raises
------
spyder.py3compat.configparser.NoOptionError
configparser.NoOptionError
If the section does not exist in the configuration.
"""
section = self.CONF_SECTION if section is None else section
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_conf_options(self, section: Optional[str] = None):
Raises
------
spyder.py3compat.configparser.NoOptionError
configparser.NoOptionError
If the section does not exist in the configuration.
"""
section = self.CONF_SECTION if section is None else section
Expand Down Expand Up @@ -207,7 +207,7 @@ def get_shortcut(
Raises
------
spyder.py3compat.configparser.NoOptionError
configparser.NoOptionError
If the section does not exist in the configuration.
"""
context = self.CONF_SECTION if context is None else context
Expand Down
5 changes: 3 additions & 2 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Stdlib imports
# =============================================================================
from collections import OrderedDict
import configparser as cp
from enum import Enum
import errno
import gc
Expand Down Expand Up @@ -81,7 +82,7 @@
from spyder.config.manager import CONF
from spyder.config.utils import IMPORT_EXT, is_gtk_desktop
from spyder.otherplugins import get_spyderplugins_mods
from spyder.py3compat import configparser as cp, PY3, to_text_string
from spyder.py3compat import to_text_string
from spyder.utils import encoding, programs
from spyder.utils.icon_manager import ima
from spyder.utils.misc import (select_port, getcwd_or_home,
Expand Down Expand Up @@ -1786,7 +1787,7 @@ def main(options, args):
# **** Create main window ****
mainwindow = None
try:
if PY3 and options.report_segfault:
if options.report_segfault:
import faulthandler
with open(faulthandler_file, 'w') as f:
faulthandler.enable(file=f)
Expand Down
1 change: 0 additions & 1 deletion spyder/app/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from spyder.config.manager import CONF


PY2 = sys.version[0] == '2'
IS_WINDOWS = os.name == 'nt'
SLEEP_TIME = 0.2 # Seconds for throttling control
CLOSE_ERROR, RESET_ERROR, RESTART_ERROR = [1, 2, 3] # Spyder error codes
Expand Down
4 changes: 2 additions & 2 deletions spyder/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from spyder.config.base import (get_conf_path, running_in_mac_app,
reset_config_files, running_under_pytest)
from spyder.utils.external import lockfile
from spyder.py3compat import is_unicode
from spyder.py3compat import is_text_string


# Get argv
Expand Down Expand Up @@ -91,7 +91,7 @@ def send_args_to_spyder(args):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
socket.IPPROTO_TCP)
client.connect(("127.0.0.1", port))
if is_unicode(arg):
if is_text_string(arg):
arg = arg.encode('utf-8')
client.send(osp.abspath(arg))
client.close()
Expand Down
13 changes: 5 additions & 8 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from spyder.plugins.ipythonconsole.utils.kernel_handler import KernelHandler
from spyder.plugins.layout.layouts import DefaultLayouts
from spyder.plugins.toolbar.api import ApplicationToolbars
from spyder.py3compat import PY2, qbytearray_to_str, to_text_string
from spyder.py3compat import qbytearray_to_str, to_text_string
from spyder.utils.misc import remove_backslashes
from spyder.utils.clipboard_helper import CLIPBOARD_HELPER
from spyder.widgets.dock import DockTitleBar
Expand Down Expand Up @@ -315,7 +315,7 @@ def test_opengl_implementation(main_window, qtbot):
@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(
np.__version__ < '1.14.0' or (os.name == 'nt' and PY2),
np.__version__ < '1.14.0',
reason="This only happens in Numpy 1.14+"
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -352,8 +352,8 @@ def test_filter_numpy_warning(main_window, qtbot):

@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(PY2 or not sys.platform == 'darwin',
reason="Times out in PY2 and fails on other than macOS")
@pytest.mark.skipif(not sys.platform == 'darwin',
reason="Fails on other than macOS")
@pytest.mark.known_leak # Opens Spyder/QtWebEngine/Default/Cookies
def test_get_help_combo(main_window, qtbot):
"""
Expand Down Expand Up @@ -409,7 +409,6 @@ def test_get_help_combo(main_window, qtbot):


@pytest.mark.slow
@pytest.mark.skipif(PY2, reason="Invalid definition of function in Python 2.")
@pytest.mark.known_leak # Opens Spyder/QtWebEngine/Default/Cookies
def test_get_help_ipython_console_dot_notation(main_window, qtbot, tmpdir):
"""
Expand Down Expand Up @@ -2035,7 +2034,6 @@ def test_varexp_magic_dbg(main_window, qtbot):

@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(PY2, reason="It times out sometimes")
@pytest.mark.parametrize(
'main_window',
[{'spy_config': ('ipython_console', 'pylab/inline/figure_format', 1)},
Expand Down Expand Up @@ -3116,8 +3114,7 @@ def _get_filenames():

@pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.skipif(sys.platform == 'darwin' and not PY2,
reason="It times out on macOS/PY3")
@pytest.mark.skipif(sys.platform == 'darwin', reason="It times out on macOS")
def test_debug_unsaved_file(main_window, qtbot):
"""Test that we can debug an unsaved file."""
# Wait until the window is fully up
Expand Down
24 changes: 9 additions & 15 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Local imports
from spyder import __version__
from spyder.py3compat import is_unicode, PY3, to_text_string, is_text_string
from spyder.py3compat import is_text_string, to_text_string
from spyder.utils import encoding

#==============================================================================
Expand Down Expand Up @@ -102,7 +102,7 @@ def use_dev_config_dir(use_dev_config_dir=USE_DEV_CONFIG_DIR):
# Debug helpers
#==============================================================================
# This is needed after restarting and using debug_print
STDOUT = sys.stdout if PY3 else codecs.getwriter('utf-8')(sys.stdout)
STDOUT = sys.stdout
STDERR = sys.stderr


Expand All @@ -118,13 +118,10 @@ def debug_print(*message):
warnings.warn("debug_print is deprecated; use the logging module instead.")
if get_debug_level():
ss = STDOUT
if PY3:
# This is needed after restarting and using debug_print
for m in message:
ss.buffer.write(str(m).encode('utf-8'))
print('', file=ss)
else:
print(*message, file=ss)
# This is needed after restarting and using debug_print
for m in message:
ss.buffer.write(str(m).encode('utf-8'))
print('', file=ss)


#==============================================================================
Expand All @@ -147,8 +144,7 @@ def get_conf_subfolder():
# embed a PY2 interpreter in PY3)
# 2. We need to save the list of installed modules (for code
# completion) separately for each version
if PY3:
SUBFOLDER = SUBFOLDER + '-py3'
SUBFOLDER = SUBFOLDER + '-py3'

# If running a development/beta version, save config in a separate
# directory to avoid wiping or contaiminating the user's saved stable
Expand Down Expand Up @@ -490,7 +486,7 @@ def get_translation(modname, dirname=None):

def translate_dumb(x):
"""Dumb function to not use translations."""
if not is_unicode(x):
if not is_text_string(x):
return to_text_string(x, "utf-8")
return x

Expand All @@ -517,10 +513,8 @@ def translate_dumb(x):
lgettext = _trans.lgettext

def translate_gettext(x):
if not PY3 and is_unicode(x):
x = x.encode("utf-8")
y = lgettext(x)
if is_text_string(y) and PY3:
if is_text_string(y):
return y
else:
return to_text_string(y, "utf-8")
Expand Down
36 changes: 5 additions & 31 deletions spyder/config/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# Local imports
from spyder.config.base import get_conf_path
from spyder.config.user import DefaultsConfig, SpyderUserConfig, UserConfig
from spyder.py3compat import PY2


@pytest.fixture
Expand All @@ -37,11 +36,7 @@ def defaultconfig(tmpdir, request):
@pytest.fixture
def userconfig(tmpdir, request):
ini_contents = '[main]\nversion = 1.0.0\n\n'
if PY2:
# strings are quoted in Python2 but not in Python3
ini_contents += "[section]\noption = 'value'\n\n"
else:
ini_contents += "[section]\noption = value\n\n"
ini_contents += "[section]\noption = value\n\n"

name = 'spyder-test'
path = str(tmpdir)
Expand Down Expand Up @@ -72,14 +67,7 @@ def userconfig(tmpdir, request):
@pytest.fixture
def spyderconfig(tmpdir, request):
ini_contents = '[main]\nversion = 1.0.0\n\n'
if PY2:
# strings are quoted in Python2 but not in Python3
ini_contents += """[ipython_console]
startup/run_lines = 'value1,value2'
"""
else:
ini_contents += """[ipython_console]
ini_contents += """[ipython_console]
startup/run_lines = value1,value2
"""
Expand Down Expand Up @@ -114,12 +102,7 @@ def spyderconfig(tmpdir, request):
@pytest.fixture
def spyderconfig_patches_42(tmpdir):
ini_contents = '[main]\nversion = 42.0.0\n\n'
if PY2:
# Strings are quoted in Python2 but not in Python3
ini_contents += ("[ipython_console]\nstartup/run_lines = "
"'value1,value2'")
else:
ini_contents += '[ipython_console]\nstartup/run_lines = value1,value2'
ini_contents += '[ipython_console]\nstartup/run_lines = value1,value2'

name = 'spyder'
inifile = tmpdir.join('{}.ini'.format(name))
Expand All @@ -133,12 +116,7 @@ def spyderconfig_patches_42(tmpdir):
@pytest.fixture
def spyderconfig_patches_45(tmpdir):
ini_contents = '[main]\nversion = 45.0.0\n\n'
if PY2:
# Strings are quoted in Python2 but not in Python3
ini_contents += ("[ipython_console]\nstartup/run_lines = "
"'value1,value2'")
else:
ini_contents += '[ipython_console]\nstartup/run_lines = value1,value2'
ini_contents += '[ipython_console]\nstartup/run_lines = value1,value2'

name = 'spyder'
inifile = tmpdir.join('{}.ini'.format(name))
Expand All @@ -152,11 +130,7 @@ def spyderconfig_patches_45(tmpdir):
@pytest.fixture
def spyderconfig_previous(tmpdir, mocker):
ini_contents = '[main]\nversion = 50.0.0\n\n'
if PY2:
# Strings are quoted in Python2 but not in Python3
ini_contents += "[section]\noption = 'value'"
else:
ini_contents += "[section]\noption = value"
ini_contents += "[section]\noption = value"

name = 'spyder'
path = str(tmpdir)
Expand Down
2 changes: 1 addition & 1 deletion spyder/config/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""Tests for config/manager.py."""

# Standard library imports
import configparser
import os
import os.path as osp
import shutil
Expand All @@ -19,7 +20,6 @@
from spyder.config.base import get_conf_path, get_conf_paths
from spyder.config.manager import ConfigurationManager
from spyder.plugins.console.plugin import Console
from spyder.py3compat import configparser


def clear_site_config():
Expand Down
13 changes: 4 additions & 9 deletions spyder/config/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""Tests for config/user.py."""

# Standard library imports
import configparser as cp
import os

# Third party imports
Expand All @@ -15,8 +16,6 @@
# Local imports
from spyder.config.main import CONF_VERSION, DEFAULTS
from spyder.config.user import NoDefault, UserConfig
from spyder.py3compat import PY2
from spyder.py3compat import configparser as cp
from spyder.utils.fixtures import tmpconfig


Expand All @@ -29,8 +28,7 @@
(('sec', 'opt', 50), '[sec][opt] = 50\n'),
(('sec', 'opt', [50]), '[sec][opt] = [50]\n'),
(('sec', 'opt', (50, 2)), '[sec][opt] = (50, 2)\n'),
(('sec', 'opt', {50}), '[sec][opt] = {}\n'.format(
'set([50])' if PY2 else '{50}')),
(('sec', 'opt', {50}), '[sec][opt] = {50}\n'),
(('sec', 'opt', {'k': 50}), "[sec][opt] = {'k': 50}\n"),
(('sec', 'opt', False), '[sec][opt] = False\n'),
(('sec', 'opt', True), '[sec][opt] = True\n'),
Expand Down Expand Up @@ -292,7 +290,7 @@ def test_userconfig_set_default(userconfig):

userconfig.set_as_defaults()
value = userconfig.get_default('section', 'option')
expected = "'value'" if PY2 else 'value'
expected = 'value'
assert value == expected
value = userconfig.set_default('section', 'option', default_value)
value = userconfig.get_default('section', 'option')
Expand Down Expand Up @@ -349,10 +347,7 @@ def test_userconfig_set_with_string(self, userconfig):
ini_contents = inifile.read()

expected = '[main]\nversion = 1.0.0\n\n'
if PY2:
expected += "[section]\noption = 'new value'\n\n"
else:
expected += "[section]\noption = new value\n\n"
expected += "[section]\noption = new value\n\n"

assert ini_contents == expected

Expand Down
Loading

0 comments on commit 0dc8fa8

Please sign in to comment.