Skip to content

Commit 18e981e

Browse files
committed
address review comments
1 parent 3edf2e9 commit 18e981e

File tree

5 files changed

+152
-196
lines changed

5 files changed

+152
-196
lines changed

devtools/debug.py

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,6 @@
2222
StrType = str
2323

2424

25-
class DebugFrame:
26-
__slots__ = 'function', 'path', 'lineno'
27-
28-
@staticmethod
29-
def from_call_frame(call_frame: 'FrameType') -> 'DebugFrame':
30-
from pathlib import Path
31-
32-
function = call_frame.f_code.co_name
33-
34-
path = Path(call_frame.f_code.co_filename)
35-
if path.is_absolute():
36-
# make the path relative
37-
cwd = Path('.').resolve()
38-
try:
39-
path = path.relative_to(cwd)
40-
except ValueError:
41-
# happens if filename path is not within CWD
42-
pass
43-
44-
lineno = call_frame.f_lineno
45-
46-
return DebugFrame(function, str(path), lineno)
47-
48-
def __init__(self, function: str, path: str, lineno: int):
49-
self.function = function
50-
self.path = path
51-
self.lineno = lineno
52-
53-
def __str__(self) -> StrType:
54-
return self.str()
55-
56-
def str(self, highlight: bool = False) -> StrType:
57-
if highlight:
58-
return (
59-
f'{sformat(self.path, sformat.magenta)}:{sformat(self.lineno, sformat.green)} '
60-
f'{sformat(self.function, sformat.green, sformat.italic)}'
61-
)
62-
else:
63-
return f'{self.path}:{self.lineno} {self.function}'
64-
65-
6625
class DebugArgument:
6726
__slots__ = 'value', 'name', 'extra'
6827

@@ -129,7 +88,7 @@ def str(self, highlight: bool = False) -> StrType:
12988
else:
13089
prefix += f' ({self.warning})'
13190

132-
return prefix + '\n ' + '\n '.join(a.str(highlight) for a in self.arguments)
91+
return f'{prefix}\n ' + '\n '.join(a.str(highlight) for a in self.arguments)
13392

13493
def __str__(self) -> StrType:
13594
return self.str()
@@ -202,8 +161,7 @@ def _process(self, args: 'Any', kwargs: 'Any', frame_depth: int, trace: bool) ->
202161
try:
203162
call_frame: 'FrameType' = sys._getframe(frame_depth)
204163
except ValueError:
205-
# "If [the given frame depth] is deeper than the call stack,
206-
# ValueError is raised"
164+
# "If [ValueError] is deeper than the call stack, ValueError is raised"
207165
return self.output_class(
208166
call_context=[DebugFrame(function='', path='<unknown>', lineno=0)],
209167
arguments=list(self._args_inspection_failed(args, kwargs)),
@@ -262,6 +220,47 @@ def _process_args(self, ex: 'Any', args: 'Any', kwargs: 'Any') -> 'Generator[Deb
262220
yield self.output_class.arg_class(value, name=name, variable=kw_arg_names.get(name))
263221

264222

223+
class DebugFrame:
224+
__slots__ = 'function', 'path', 'lineno'
225+
226+
def __init__(self, function: str, path: str, lineno: int):
227+
self.function = function
228+
self.path = path
229+
self.lineno = lineno
230+
231+
@staticmethod
232+
def from_call_frame(call_frame: 'FrameType') -> 'DebugFrame':
233+
from pathlib import Path
234+
235+
function = call_frame.f_code.co_name
236+
237+
path = Path(call_frame.f_code.co_filename)
238+
if path.is_absolute():
239+
# make the path relative
240+
cwd = Path('.').resolve()
241+
try:
242+
path = path.relative_to(cwd)
243+
except ValueError:
244+
# happens if filename path is not within CWD
245+
pass
246+
247+
lineno = call_frame.f_lineno
248+
249+
return DebugFrame(function, str(path), lineno)
250+
251+
def __str__(self) -> StrType:
252+
return self.str()
253+
254+
def str(self, highlight: bool = False) -> StrType:
255+
if highlight:
256+
return (
257+
f'{sformat(self.path, sformat.magenta)}:{sformat(self.lineno, sformat.green)} '
258+
f'{sformat(self.function, sformat.green, sformat.italic)}'
259+
)
260+
else:
261+
return f'{self.path}:{self.lineno} {self.function}'
262+
263+
265264
def _make_call_context(call_frame: 'Optional[FrameType]', trace: bool) -> 'List[DebugFrame]':
266265
call_context: 'List[DebugFrame]' = []
267266

requirements/testing.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ coverage[toml]
22
pytest
33
pytest-mock
44
pytest-pretty
5-
pytest-tmp-files
6-
parametrize-from-file
75
# these packages are used in tests so install the latest version
86
# no binaries for 3.7
97
asyncpg; python_version>='3.8'

requirements/testing.txt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile --output-file=requirements/testing.txt requirements/testing.in
5+
# pip-compile --output-file=requirements/testing.txt --resolver=backtracking requirements/testing.in
66
#
7-
arrow==1.3.0
8-
# via inform
97
asyncpg==0.27.0 ; python_version >= "3.8"
108
# via -r requirements/testing.in
119
attrs==22.2.0
@@ -16,38 +14,24 @@ click==8.1.3
1614
# via black
1715
coverage[toml]==7.2.2
1816
# via -r requirements/testing.in
19-
decopatch==1.4.10
20-
# via parametrize-from-file
2117
exceptiongroup==1.1.3
2218
# via pytest
23-
greenlet==3.0.0
24-
# via sqlalchemy
25-
inform==1.28
26-
# via nestedtext
2719
iniconfig==2.0.0
2820
# via pytest
29-
makefun==1.15.1
30-
# via decopatch
3121
markdown-it-py==2.2.0
3222
# via rich
3323
mdurl==0.1.2
3424
# via markdown-it-py
35-
more-itertools==8.14.0
36-
# via parametrize-from-file
3725
multidict==6.0.4 ; python_version >= "3.8"
3826
# via -r requirements/testing.in
3927
mypy-extensions==1.0.0
4028
# via black
41-
nestedtext==3.6
42-
# via parametrize-from-file
4329
numpy==1.24.2 ; python_version >= "3.8"
4430
# via -r requirements/testing.in
4531
packaging==23.0
4632
# via
4733
# black
4834
# pytest
49-
parametrize-from-file==0.18.0
50-
# via -r requirements/testing.in
5135
pathspec==0.11.1
5236
# via black
5337
platformdirs==3.2.0
@@ -61,41 +45,21 @@ pygments==2.15.0
6145
pytest==7.2.2
6246
# via
6347
# -r requirements/testing.in
64-
# parametrize-from-file
6548
# pytest-mock
6649
# pytest-pretty
67-
# pytest-tmp-files
6850
pytest-mock==3.10.0
6951
# via -r requirements/testing.in
7052
pytest-pretty==1.2.0
7153
# via -r requirements/testing.in
72-
pytest-tmp-files==0.0.1
73-
# via -r requirements/testing.in
74-
python-dateutil==2.8.2
75-
# via
76-
# arrow
77-
# pytest-tmp-files
78-
pyyaml==6.0.1
79-
# via parametrize-from-file
8054
rich==13.3.3
8155
# via pytest-pretty
82-
six==1.16.0
83-
# via
84-
# inform
85-
# python-dateutil
8656
sqlalchemy==2.0.8
8757
# via -r requirements/testing.in
88-
tidyexc==0.10.0
89-
# via parametrize-from-file
90-
toml==0.10.2
91-
# via parametrize-from-file
9258
tomli==2.0.1
9359
# via
9460
# black
9561
# coverage
9662
# pytest
97-
types-python-dateutil==2.8.19.14
98-
# via arrow
9963
typing-extensions==4.5.0
10064
# via
10165
# pydantic

tests/test_main.nt

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)