2
2
from collections .abc import Iterable
3
3
from pathlib import Path
4
4
5
- import _pytask
6
- import pluggy
7
-
8
-
9
- _PLUGGY_DIRECTORY = Path (pluggy .__file__ ).parent
10
- _PYTASK_DIRECTORY = Path (_pytask .__file__ ).parent
11
-
12
5
13
6
def to_list (scalar_or_iter ):
14
7
"""Convert scalars and iterables to list.
@@ -85,23 +78,13 @@ def get_first_non_none_value(*configs, key, default=None, callback=None):
85
78
>>> get_first_non_none_value({}, {}, key="a", default="default")
86
79
'default'
87
80
88
- >>> get_first_non_none_value({"a": None}, {"a": "b"}, key="a", callback=to_list )
89
- [ 'b']
81
+ >>> get_first_non_none_value({"a": None}, {"a": "b"}, key="a")
82
+ 'b'
90
83
91
84
"""
92
- return next (
93
- (
94
- config [key ] if callback is None else callback (config [key ])
95
- for config in configs
96
- if config .get (key ) is not None
97
- ),
98
- default ,
99
- )
100
-
101
-
102
- def remove_traceback_from_exc_info (exc_info ):
103
- """Remove traceback from exception."""
104
- return (* exc_info [:2 ], None )
85
+ callback = (lambda x : x ) if callback is None else callback # noqa: E731
86
+ processed_values = (callback (config .get (key )) for config in configs )
87
+ return next ((value for value in processed_values if value is not None ), default )
105
88
106
89
107
90
def parse_value_or_multiline_option (value ):
@@ -110,48 +93,6 @@ def parse_value_or_multiline_option(value):
110
93
return value
111
94
112
95
113
- def is_internal_traceback_frame (frame ):
114
- """Returns ``True`` if traceback frame belongs to internal packages.
115
-
116
- Internal packages are ``_pytask`` and ``pluggy``.
117
-
118
- """
119
- path = Path (frame .tb_frame .f_code .co_filename )
120
- return any (root in path .parents for root in [_PLUGGY_DIRECTORY , _PYTASK_DIRECTORY ])
121
-
122
-
123
- def filter_internal_traceback_frames (frame ):
124
- """Filter internal traceback frames from traceback.
125
-
126
- If the first external frame is visited, return the frame. Else return ``None``.
127
-
128
- """
129
- for frame in yield_traceback_frames (frame ):
130
- if frame is None or not is_internal_traceback_frame (frame ):
131
- return frame
132
-
133
-
134
- def remove_internal_traceback_frames_from_exc_info (exc_info ):
135
- """Remove internal traceback frames from exception info.
136
-
137
- If a non-internal traceback frame is found, return the traceback from the first
138
- occurrence downwards. Otherwise, return the whole traceback.
139
-
140
- """
141
- if exc_info is not None :
142
- filtered_traceback = filter_internal_traceback_frames (exc_info [2 ])
143
- if filtered_traceback is not None :
144
- exc_info = (* exc_info [:2 ], filtered_traceback )
145
-
146
- return exc_info
147
-
148
-
149
- def yield_traceback_frames (frame ):
150
- """Yield traceback frames."""
151
- yield frame
152
- yield from yield_traceback_frames (frame .tb_next )
153
-
154
-
155
96
def convert_truthy_or_falsy_to_bool (x ):
156
97
"""Convert truthy or falsy value in .ini to Python boolean."""
157
98
if x in [True , "True" , "true" , "1" ]:
0 commit comments