Address @mvanderkamp's comments in the pylint/drop-py2 PR

This commit is contained in:
Andreas Kloeckner 2021-03-26 17:05:59 -05:00
parent 2d38c1bef5
commit 71ffa51a29
6 changed files with 14 additions and 65 deletions

View File

@ -27,15 +27,7 @@ to start pudb.
Insert one of these snippets into the piece of code you want to debug, or Insert one of these snippets into the piece of code you want to debug, or
run the entire script with:: run the entire script with::
pudb my-script.py python -m pudb my-script.py
or, in Python 3::
pudb3 my-script.py
This is equivalent to::
python -m pudb.run my-script.py
which is useful if you want to run PuDB in a version of Python other than the which is useful if you want to run PuDB in a version of Python other than the
one you most recently installed PuDB with. one you most recently installed PuDB with.

View File

@ -58,14 +58,7 @@ def run_with_timeout(code, time, globals=None):
""" """
# Set the signal handler and a ``time``-second alarm # Set the signal handler and a ``time``-second alarm
signal.signal(signal.SIGALRM, lambda s, f: timeout(s, f, time)) signal.signal(signal.SIGALRM, lambda s, f: timeout(s, f, time))
if sys.version_info > (2, 5):
signal.setitimer(signal.ITIMER_REAL, time) signal.setitimer(signal.ITIMER_REAL, time)
else:
# The above only exists in Python 2.6+
# Otherwise, we have to use this, which only supports integer arguments
# Use math.ceil to round a float up.
time = int(math.ceil(time))
signal.alarm(time)
r = eval(code, globals) r = eval(code, globals)
signal.alarm(0) # Disable the alarm signal.alarm(0) # Disable the alarm
return r return r

View File

@ -69,19 +69,6 @@ def _tty_override():
def _open_tty(tty_path): def _open_tty(tty_path):
import io import io
import os import os
import sys
if sys.version_info[0] == 2:
import fcntl
import termios
import struct
tty_file = open(tty_path, "r+b", buffering=0)
try:
s = struct.unpack("hh", fcntl.ioctl(
tty_file.fileno(), termios.TIOCGWINSZ, "1234"))
term_size = (s[1], s[0])
except Exception:
term_size = None
else:
tty_file = io.TextIOWrapper(open(tty_path, "r+b", buffering=0)) tty_file = io.TextIOWrapper(open(tty_path, "r+b", buffering=0))
term_size = os.get_terminal_size(tty_file.fileno()) term_size = os.get_terminal_size(tty_file.fileno())

View File

@ -501,14 +501,9 @@ class Debugger(bdb.Bdb):
def _runmodule(self, module_name): def _runmodule(self, module_name):
# This is basically stolen from the pdb._runmodule from CPython 3.8 # This is basically stolen from the pdb._runmodule from CPython 3.8
# and adapted to work also in Python 2
# https://github.com/python/cpython/blob/a1d3be4623c8ec7069bd34ccdce336be9cdeb644/Lib/pdb.py#L1530 # https://github.com/python/cpython/blob/a1d3be4623c8ec7069bd34ccdce336be9cdeb644/Lib/pdb.py#L1530
import runpy import runpy
mod_name, mod_spec, code = runpy._get_module_details(module_name)
# here we unpack the module details manually, so that it works in PY2 as well
mod_details = runpy._get_module_details(module_name)
mod_spec = mod_details[1]
code = mod_details[2]
self.mainpyfile = self.canonic(code.co_filename) self.mainpyfile = self.canonic(code.co_filename)
import __main__ import __main__
@ -518,9 +513,6 @@ class Debugger(bdb.Bdb):
"__file__": self.mainpyfile, "__file__": self.mainpyfile,
"__spec__": mod_spec, "__spec__": mod_spec,
"__builtins__": __builtins__, "__builtins__": __builtins__,
})
__main__.__dict__.update({
"__package__": mod_spec.parent, "__package__": mod_spec.parent,
"__loader__": mod_spec.loader, "__loader__": mod_spec.loader,
}) })
@ -1734,8 +1726,6 @@ class DebuggerUI(FrameVarInfoKeeper):
sys.stdin = None sys.stdin = None
sys.stderr = sys.stdout = StringIO() sys.stderr = sys.stdout = StringIO()
try: try:
# Don't use cmdline_get_namespace() here in Python 2, as it
# breaks things (issue #166).
eval(compile(cmd, "<pudb command line>", "single"), eval(compile(cmd, "<pudb command line>", "single"),
cmdline_get_namespace()) cmdline_get_namespace())
except Exception: except Exception:

View File

@ -104,18 +104,8 @@ class RemoteDebugger(Debugger):
raw_sock_file = self._client.makefile("rwb", 0) raw_sock_file = self._client.makefile("rwb", 0)
import codecs import codecs
if sys.version_info[0] < 3:
sock_file = codecs.StreamRecoder(
raw_sock_file,
codecs.getencoder("utf-8"),
codecs.getdecoder("utf-8"),
codecs.getreader("utf-8"),
codecs.getwriter("utf-8"),
)
else:
sock_file = codecs.StreamReaderWriter( sock_file = codecs.StreamReaderWriter(
raw_sock_file, codecs.getreader("utf-8"), codecs.getwriter("utf-8") raw_sock_file, codecs.getreader("utf-8"), codecs.getwriter("utf-8"))
)
self._handle = sys.stdin = sys.stdout = sock_file self._handle = sys.stdin = sys.stdout = sock_file

View File

@ -5,12 +5,6 @@ from pudb import VERSION
import sys import sys
py_version_major = sys.version_info[0]
if py_version_major == 3:
PY_VERSION = str(py_version_major)
else:
PY_VERSION = ""
try: try:
readme = open("README.rst") readme = open("README.rst")
long_description = str(readme.read()) long_description = str(readme.read())
@ -54,7 +48,10 @@ setup(
], ],
packages=["pudb"], packages=["pudb"],
entry_points={ entry_points={
"console_scripts": ["pudb" + PY_VERSION + " = pudb.run:main"], "console_scripts": [
# Deprecated. Should really use python -m pudb.
"pudb3 = pudb.run:main",
],
"gui_script": [], "gui_script": [],
}, },
) )