Skip to content

Commit

Permalink
Switch to ruff, fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jul 11, 2024
1 parent e47c406 commit bdfd67f
Show file tree
Hide file tree
Showing 44 changed files with 193 additions and 126 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ on:
- cron: '17 3 * * 0'

jobs:
flake8:
name: Flake8
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
uses: actions/setup-python@v5
with:
# matches compat target in setup.py
python-version: '3.8'
- name: "Main Script"
run: |
curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
. ./prepare-and-run-flake8.sh ./pudb
pipx install ruff
ruff check
pylint:
name: Pylint
Expand Down
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Python 3:
reports:
junit: test/pytest.xml

Flake8:
ruff:
script:
- curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
- ". ./prepare-and-run-flake8.sh pudb"
- pipx install ruff
- ruff check
tags:
- python3
- docker-runner
except:
- tags

Expand Down
27 changes: 17 additions & 10 deletions debug_me.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import namedtuple

Color = namedtuple('Color', ['red', 'green', 'blue', 'alpha'])

Color = namedtuple("Color", ["red", "green", "blue", "alpha"])


class MyClass(object):
Expand All @@ -9,30 +10,35 @@ def __init__(self, a, b):
self.b = b
self._b = [b]


mc = MyClass(15, MyClass(12, None))


from pudb import set_trace; set_trace()
from pudb import set_trace


set_trace()


def simple_func(x):
x += 1

s = range(20)
z = None
w = ()
z = None # noqa: F841
w = () # noqa: F841

y = dict((i, i**2) for i in s)
y = {i: i**2 for i in s} # noqa: F841

k = set(range(5, 99))
c = Color(137, 214, 56, 88)
k = set(range(5, 99)) # noqa: F841
c = Color(137, 214, 56, 88) # noqa: F841

try:
x.invalid
x.invalid # noqa: B018
except AttributeError:
pass

#import sys
#sys.exit(1)
# import sys
# sys.exit(1)

return 2*x

Expand All @@ -52,6 +58,7 @@ def fermat(n):
if x**n + y**n == z**n:
yield x, y, z


print("SF %s" % simple_func(10))

for i in fermat(2):
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from urllib.request import urlopen


_conf_url = \
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
Expand Down
1 change: 1 addition & 0 deletions examples/mpi4py-debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# (when using the default pudb configuration) in another terminal.

from mpi4py import MPI

from pudb.remote import debug_remote_on_single_rank


Expand Down
2 changes: 2 additions & 0 deletions examples/remote-debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ def debugged_function(x):


from pudb.remote import debugger


dbg = debugger()
dbg.runcall(debugged_function, 5)
7 changes: 4 additions & 3 deletions examples/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""


# Define this a function with this name and signature at the module level.
def pudb_shell(_globals, _locals):
"""
Expand All @@ -33,11 +34,11 @@ def pudb_shell(_globals, _locals):
try:
import readline
import rlcompleter
HAVE_READLINE = True
have_readline = True
except ImportError:
HAVE_READLINE = False
have_readline = False

if HAVE_READLINE:
if have_readline:
readline.set_completer(
rlcompleter.Completer(ns).complete)
readline.parse_and_bind("tab: complete")
Expand Down
15 changes: 10 additions & 5 deletions examples/stringifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@
a handful of "safe" types for which it is guaranteed to be fast and not to
fail.
"""
import time
import signal
import sys
import math
import time


class TimeOutError(Exception):
pass


def timeout(signum, frame, time):
raise TimeOutError("Timed out after %d seconds" % time)


def run_with_timeout(code, time, globals=None):
"""
Evaluate ``code``, timing out after ``time`` seconds.
Expand All @@ -63,6 +64,7 @@ def run_with_timeout(code, time, globals=None):
signal.alarm(0) # Disable the alarm
return r


def pudb_stringifier(obj):
"""
This is the custom stringifier.
Expand All @@ -71,21 +73,24 @@ def pudb_stringifier(obj):
in which case it falls back to type(obj).
"""
try:
return run_with_timeout("str(obj)", 0.5, {'obj':obj})
return run_with_timeout("str(obj)", 0.5, {"obj": obj})
except TimeOutError:
return (type(obj), "(str too slow to compute)")

# Example usage


class FastString(object):
def __str__(self):
return "This was fast to compute."


class SlowString(object):
def __str__(self):
time.sleep(10) # Return the string value after ten seconds
time.sleep(10) # Return the string value after ten seconds
return "This was slow to compute."


fast = FastString()
slow = SlowString()

Expand Down
4 changes: 2 additions & 2 deletions examples/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Note, be sure to test your theme in both curses and raw mode (see the bottom
# of the preferences window). Curses mode will be used with screen or tmux.

palette.update({
"source": (add_setting("black", "underline"), "dark green"),
palette.update({ # noqa: F821
"source": (add_setting("black", "underline"), "dark green"), # noqa: F821
"comment": ("h250", "default")
})
5 changes: 4 additions & 1 deletion manual-tests/test-api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
def f():
fail
fail # noqa: B018, F821


from pudb import runcall


runcall(f)
5 changes: 0 additions & 5 deletions manual-tests/test-encoding.py

This file was deleted.

5 changes: 3 additions & 2 deletions manual-tests/test-postmortem.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
def f():
fail
fail # noqa: B018, F821


try:
f()
except:
except Exception:
from pudb import post_mortem
post_mortem()
18 changes: 12 additions & 6 deletions pudb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
"""


from pudb.settings import load_config
import sys

from pudb.settings import load_config


NUM_VERSION = (2024, 1, 1)
VERSION = ".".join(str(nv) for nv in NUM_VERSION)
Expand Down Expand Up @@ -54,6 +55,8 @@ def go(self):


import builtins


builtins.__dict__["pu"] = PudbShortcuts()


Expand Down Expand Up @@ -292,23 +295,26 @@ def set_interrupt_handler(interrupt_signal=None):
old_handler = "not installed from python"
return warn("A non-default handler for signal %d is already installed (%s). "
"Skipping pudb interrupt support."
% (interrupt_signal, old_handler))
% (interrupt_signal, old_handler),
stacklevel=2)

import threading
if not isinstance(threading.current_thread(), threading._MainThread):
from warnings import warn
# Setting signals from a non-main thread will not work
return warn("Setting the interrupt handler can only be done on the main "
"thread. The interrupt handler was NOT installed.")
"thread. The interrupt handler was NOT installed.",
stacklevel=2)

try:
signal.signal(interrupt_signal, _interrupt_handler)
except ValueError:
from traceback import format_exception
import sys
from traceback import format_exception
from warnings import warn
warn("setting interrupt handler on signal %d failed: %s"
% (interrupt_signal, "".join(format_exception(*sys.exc_info()))))
% (interrupt_signal, "".join(format_exception(*sys.exc_info()))),
stacklevel=2)


def post_mortem(tb=None, e_type=None, e_value=None):
Expand All @@ -325,7 +331,7 @@ def post_mortem(tb=None, e_type=None, e_value=None):

def pm():
import sys
exc_type, exc_val, tb = sys.exc_info()
exc_type, _exc_val, _tb = sys.exc_info()

if exc_type is None:
# No exception on record. Do nothing.
Expand Down
Loading

0 comments on commit bdfd67f

Please sign in to comment.