27 @return the entry point for the background client (function) |
27 @return the entry point for the background client (function) |
28 """ |
28 """ |
29 return batchCyclomaticComplexity |
29 return batchCyclomaticComplexity |
30 |
30 |
31 |
31 |
32 def cyclomaticComplexity(file, text=""): # noqa: U100 |
32 def cyclomaticComplexity( |
|
33 file, # noqa: U100 |
|
34 text="", |
|
35 ): |
33 """ |
36 """ |
34 Private function to calculate the cyclomatic complexity of one file. |
37 Private function to calculate the cyclomatic complexity of one file. |
35 |
38 |
36 @param file source filename |
39 @param file source filename |
37 @type str |
40 @type str |
145 @param text source text |
148 @param text source text |
146 @type str |
149 @type str |
147 @return tuple containing the result dictionary |
150 @return tuple containing the result dictionary |
148 @rtype (tuple of dict) |
151 @rtype (tuple of dict) |
149 """ |
152 """ |
150 from radon.complexity import cc_rank, cc_visit |
153 from radon.complexity import cc_rank, cc_visit # noqa: I102 |
151 |
154 |
152 try: |
155 try: |
153 cc = cc_visit(text) |
156 cc = cc_visit(text) |
154 res = {"result": [v for v in map(__cc2Dict, cc) if v["type"] != "method"]} |
157 res = {"result": [v for v in map(__cc2Dict, cc) if v["type"] != "method"]} |
155 totalCC = 0 |
158 totalCC = 0 |
180 @param obj object as returned from cc_visit() |
183 @param obj object as returned from cc_visit() |
181 @type radon.visitors.Function |
184 @type radon.visitors.Function |
182 @return conversion result |
185 @return conversion result |
183 @rtype dict |
186 @rtype dict |
184 """ |
187 """ |
185 from radon.complexity import cc_rank |
188 from radon.complexity import cc_rank # noqa: I102 |
186 from radon.visitors import Function |
189 from radon.visitors import Function # noqa: I102 |
187 |
190 |
188 result = { |
191 result = { |
189 "type": __getType(obj), |
192 "type": __getType(obj), |
190 "rank": cc_rank(obj.complexity), |
193 "rank": cc_rank(obj.complexity), |
191 } |
194 } |
208 @param obj object to be analyzed |
211 @param obj object to be analyzed |
209 @type radon.visitors.Function or radon.visitors.Class |
212 @type radon.visitors.Function or radon.visitors.Class |
210 @return type string for the object |
213 @return type string for the object |
211 @rtype str, one of ["method", "function", "class"] |
214 @rtype str, one of ["method", "function", "class"] |
212 """ |
215 """ |
213 from radon.visitors import Function |
216 from radon.visitors import Function # noqa: I102 |
214 |
217 |
215 if isinstance(obj, Function): |
218 if isinstance(obj, Function): |
216 if obj.is_method: |
219 if obj.is_method: |
217 return "method" |
220 return "method" |
218 else: |
221 else: |