codeanalyzer-python 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,15 @@
1
+ import ast
2
+ import tokenize
3
+ from ast import AST, ClassDef
1
4
  from io import StringIO
2
5
  from pathlib import Path
3
- import tokenize
4
6
  from typing import Dict, List, Optional
7
+
5
8
  import astor
6
9
  import jedi
7
- from codeanalyzer.utils import logger
8
- from jedi.api.project import Project
9
10
  from jedi.api import Script
10
- from rich.progress import track
11
+ from jedi.api.project import Project
12
+
11
13
  from codeanalyzer.schema.py_schema import (
12
14
  PyCallable,
13
15
  PyCallableParameter,
@@ -20,9 +22,7 @@ from codeanalyzer.schema.py_schema import (
20
22
  PySymbol,
21
23
  PyVariableDeclaration,
22
24
  )
23
- import ast
24
- from ast import AST, ClassDef
25
-
25
+ from codeanalyzer.utils import logger
26
26
  from codeanalyzer.utils.progress_bar import ProgressBar
27
27
 
28
28
 
@@ -98,13 +98,13 @@ class SymbolTableBuilder:
98
98
 
99
99
  return (
100
100
  PyModule.builder()
101
- .with_file_path(str(py_file))
102
- .with_module_name(py_file.stem)
103
- .with_comments(self._pycomments(module, source))
104
- .with_imports(self._imports(module))
105
- .with_variables(self._module_variables(module, script))
106
- .with_classes(classes)
107
- .with_functions(functions)
101
+ .file_path(str(py_file))
102
+ .module_name(py_file.stem)
103
+ .comments(self._pycomments(module, source))
104
+ .imports(self._imports(module))
105
+ .variables(self._module_variables(module, script))
106
+ .classes(classes)
107
+ .functions(functions)
108
108
  .build()
109
109
  )
110
110
 
@@ -126,13 +126,13 @@ class SymbolTableBuilder:
126
126
  for alias in node.names:
127
127
  imports.append(
128
128
  PyImport.builder()
129
- .with_module(alias.name) # for "import os", alias.name = "os"
130
- .with_name(alias.asname or alias.name) # name in local scope
131
- .with_alias(alias.name if alias.asname else None)
132
- .with_start_line(getattr(node, "lineno", -1))
133
- .with_end_line(getattr(node, "end_lineno", node.lineno))
134
- .with_start_column(getattr(node, "col_offset", -1))
135
- .with_end_column(getattr(node, "end_col_offset", -1))
129
+ .module(alias.name) # for "import os", alias.name = "os"
130
+ .name(alias.asname or alias.name) # name in local scope
131
+ .alias(alias.name if alias.asname else None)
132
+ .start_line(getattr(node, "lineno", -1))
133
+ .end_line(getattr(node, "end_lineno", node.lineno))
134
+ .start_column(getattr(node, "col_offset", -1))
135
+ .end_column(getattr(node, "end_col_offset", -1))
136
136
  .build()
137
137
  )
138
138
 
@@ -145,13 +145,13 @@ class SymbolTableBuilder:
145
145
  qualified_module = "." * node.level + (module_name or "")
146
146
  imports.append(
147
147
  PyImport.builder()
148
- .with_module(qualified_module)
149
- .with_name(alias.asname or alias.name)
150
- .with_alias(alias.name if alias.asname else None)
151
- .with_start_line(getattr(node, "lineno", -1))
152
- .with_end_line(getattr(node, "end_lineno", node.lineno))
153
- .with_start_column(getattr(node, "col_offset", -1))
154
- .with_end_column(getattr(node, "end_col_offset", -1))
148
+ .module(qualified_module)
149
+ .name(alias.asname or alias.name)
150
+ .alias(alias.name if alias.asname else None)
151
+ .start_line(getattr(node, "lineno", -1))
152
+ .end_line(getattr(node, "end_lineno", node.lineno))
153
+ .start_column(getattr(node, "col_offset", -1))
154
+ .end_column(getattr(node, "end_col_offset", -1))
155
155
  .build()
156
156
  )
157
157
 
@@ -187,26 +187,26 @@ class SymbolTableBuilder:
187
187
 
188
188
  py_class = (
189
189
  PyClass.builder()
190
- .with_name(class_node.name)
191
- .with_signature(signature)
192
- .with_start_line(class_node.lineno)
193
- .with_end_line(
190
+ .name(class_node.name)
191
+ .signature(signature)
192
+ .start_line(class_node.lineno)
193
+ .end_line(
194
194
  getattr(
195
195
  class_node, "end_lineno", class_node.lineno + len(class_node.body)
196
196
  )
197
197
  )
198
- .with_comments(self._pycomments(class_node, code))
199
- .with_code(code)
200
- .with_base_classes(
198
+ .comments(self._pycomments(class_node, code))
199
+ .code(code)
200
+ .base_classes(
201
201
  [
202
202
  ast.unparse(base)
203
203
  for base in class_node.bases
204
204
  if isinstance(base, ast.expr)
205
205
  ]
206
206
  )
207
- .with_methods(self._callables(class_node, script))
208
- .with_attributes(self._class_attributes(class_node, script))
209
- .with_inner_classes(
207
+ .methods(self._callables(class_node, script))
208
+ .attributes(self._class_attributes(class_node, script))
209
+ .inner_classes(
210
210
  {
211
211
  k: v
212
212
  for child in class_node.body
@@ -260,27 +260,27 @@ class SymbolTableBuilder:
260
260
 
261
261
  callables[method_name] = (
262
262
  PyCallable.builder()
263
- .with_name(method_name)
264
- .with_path(script.path.__str__())
265
- .with_signature(signature)
266
- .with_decorators(decorators)
267
- .with_code(code)
268
- .with_start_line(start_line)
269
- .with_end_line(end_line)
270
- .with_code_start_line(code_start_line)
271
- .with_accessed_symbols(self._accessed_symbols(child, script))
272
- .with_call_sites(self._call_sites(child, script))
273
- .with_local_variables(self._local_variables(child, script))
274
- .with_cyclomatic_complexity(self._cyclomatic_complexity(child))
275
- .with_parameters(self._callable_parameters(child, script))
276
- .with_return_type(
263
+ .name(method_name)
264
+ .path(script.path.__str__())
265
+ .signature(signature)
266
+ .decorators(decorators)
267
+ .code(code)
268
+ .start_line(start_line)
269
+ .end_line(end_line)
270
+ .code_start_line(code_start_line)
271
+ .accessed_symbols(self._accessed_symbols(child, script))
272
+ .call_sites(self._call_sites(child, script))
273
+ .local_variables(self._local_variables(child, script))
274
+ .cyclomatic_complexity(self._cyclomatic_complexity(child))
275
+ .parameters(self._callable_parameters(child, script))
276
+ .return_type(
277
277
  ast.unparse(child.returns)
278
278
  if child.returns
279
279
  else self._infer_type(
280
280
  script, child.lineno, child.col_offset
281
281
  )
282
282
  )
283
- .with_comments(self._pycomments(child, code))
283
+ .comments(self._pycomments(child, code))
284
284
  .build()
285
285
  )
286
286
 
@@ -327,12 +327,12 @@ class SymbolTableBuilder:
327
327
 
328
328
  comments.append(
329
329
  PyComment.builder()
330
- .with_content(docstring_content)
331
- .with_start_line(start_line)
332
- .with_end_line(end_line)
333
- .with_start_column(start_column)
334
- .with_end_column(end_column)
335
- .with_is_docstring(True)
330
+ .content(docstring_content)
331
+ .start_line(start_line)
332
+ .end_line(end_line)
333
+ .start_column(start_column)
334
+ .end_column(end_column)
335
+ .is_docstring(True)
336
336
  .build()
337
337
  )
338
338
 
@@ -348,12 +348,12 @@ class SymbolTableBuilder:
348
348
  comment_text = tok.string.lstrip("#").strip()
349
349
  comments.append(
350
350
  PyComment.builder()
351
- .with_content(comment_text)
352
- .with_start_line(tok_line)
353
- .with_end_line(tok_line)
354
- .with_start_column(tok_col)
355
- .with_end_column(tok_col + len(tok.string))
356
- .with_is_docstring(False)
351
+ .content(comment_text)
352
+ .start_line(tok_line)
353
+ .end_line(tok_line)
354
+ .start_column(tok_col)
355
+ .end_column(tok_col + len(tok.string))
356
+ .is_docstring(False)
357
357
  .build()
358
358
  )
359
359
 
@@ -380,14 +380,14 @@ class SymbolTableBuilder:
380
380
  if isinstance(target, ast.Name):
381
381
  attributes[target.id] = (
382
382
  PyClassAttribute.builder()
383
- .with_name(target.id)
384
- .with_type(
383
+ .name(target.id)
384
+ .type(
385
385
  self._infer_type(
386
386
  script, target.lineno, target.col_offset
387
387
  )
388
388
  )
389
- .with_start_line(getattr(target, "lineno", -1))
390
- .with_end_line(getattr(stmt, "end_lineno", stmt.lineno))
389
+ .start_line(getattr(target, "lineno", -1))
390
+ .end_line(getattr(stmt, "end_lineno", stmt.lineno))
391
391
  .build()
392
392
  )
393
393
 
@@ -396,16 +396,16 @@ class SymbolTableBuilder:
396
396
  if isinstance(target, ast.Name):
397
397
  attributes[target.id] = (
398
398
  PyClassAttribute.builder()
399
- .with_name(target.id)
400
- .with_type(
399
+ .name(target.id)
400
+ .type(
401
401
  ast.unparse(stmt.annotation)
402
402
  if stmt.annotation
403
403
  else self._infer_type(
404
404
  script, target.lineno, target.col_offset
405
405
  )
406
406
  )
407
- .with_start_line(getattr(target, "lineno", -1))
408
- .with_end_line(getattr(stmt, "end_lineno", stmt.lineno))
407
+ .start_line(getattr(target, "lineno", -1))
408
+ .end_line(getattr(stmt, "end_lineno", stmt.lineno))
409
409
  .build()
410
410
  )
411
411
  # We may also encounter `__slots__` in class definitions.
@@ -428,10 +428,10 @@ class SymbolTableBuilder:
428
428
  value = elt.s if isinstance(elt, ast.Str) else elt.value
429
429
  attributes[value] = (
430
430
  PyClassAttribute.builder()
431
- .with_name(value)
432
- .with_type("slot")
433
- .with_start_line(getattr(stmt, "lineno", -1))
434
- .with_end_line(getattr(stmt, "end_lineno", stmt.lineno))
431
+ .name(value)
432
+ .type("slot")
433
+ .start_line(getattr(stmt, "lineno", -1))
434
+ .end_line(getattr(stmt, "end_lineno", stmt.lineno))
435
435
  .build()
436
436
  )
437
437
 
@@ -472,15 +472,15 @@ class SymbolTableBuilder:
472
472
  ) -> PyCallableParameter:
473
473
  return (
474
474
  PyCallableParameter.builder()
475
- .with_name(arg_node.arg)
476
- .with_type(resolve_type(arg_node))
477
- .with_default_value(ast.unparse(default) if default else None)
478
- .with_start_line(getattr(arg_node, "lineno", -1))
479
- .with_end_line(
475
+ .name(arg_node.arg)
476
+ .type(resolve_type(arg_node))
477
+ .default_value(ast.unparse(default) if default else None)
478
+ .start_line(getattr(arg_node, "lineno", -1))
479
+ .end_line(
480
480
  getattr(arg_node, "end_lineno", getattr(arg_node, "lineno", -1))
481
481
  )
482
- .with_start_column(getattr(arg_node, "col_offset", -1))
483
- .with_end_column(getattr(arg_node, "end_col_offset", -1))
482
+ .start_column(getattr(arg_node, "col_offset", -1))
483
+ .end_column(getattr(arg_node, "end_col_offset", -1))
484
484
  .build()
485
485
  )
486
486
 
@@ -559,17 +559,17 @@ class SymbolTableBuilder:
559
559
 
560
560
  call_sites.append(
561
561
  PyCallsite.builder()
562
- .with_method_name(method_name)
563
- .with_receiver_expr(receiver_expr)
564
- .with_receiver_type(receiver_type)
565
- .with_argument_types(argument_types)
566
- .with_return_type(return_type)
567
- .with_callee_signature(callee_signature)
568
- .with_is_constructor_call(method_name == "__init__")
569
- .with_start_line(getattr(node, "lineno", -1))
570
- .with_start_column(getattr(node, "col_offset", -1))
571
- .with_end_line(getattr(node, "end_lineno", -1))
572
- .with_end_column(getattr(node, "end_col_offset", -1))
562
+ .method_name(method_name)
563
+ .receiver_expr(receiver_expr)
564
+ .receiver_type(receiver_type)
565
+ .argument_types(argument_types)
566
+ .return_type(return_type)
567
+ .callee_signature(callee_signature)
568
+ .is_constructor_call(method_name == "__init__")
569
+ .start_line(getattr(node, "lineno", -1))
570
+ .start_column(getattr(node, "col_offset", -1))
571
+ .end_line(getattr(node, "end_lineno", -1))
572
+ .end_column(getattr(node, "end_col_offset", -1))
573
573
  .build()
574
574
  )
575
575
 
@@ -611,23 +611,23 @@ class SymbolTableBuilder:
611
611
  if isinstance(target, ast.Name):
612
612
  module_vars.append(
613
613
  PyVariableDeclaration.builder()
614
- .with_name(target.id)
615
- .with_type(
614
+ .name(target.id)
615
+ .type(
616
616
  self._infer_type(
617
617
  script, target.lineno, target.col_offset
618
618
  )
619
619
  )
620
- .with_initializer(
620
+ .initializer(
621
621
  ast.unparse(node.value) if node.value else None
622
622
  )
623
- .with_value(None)
624
- .with_scope("module")
625
- .with_start_line(getattr(target, "lineno", -1))
626
- .with_end_line(
623
+ .value(None)
624
+ .scope("module")
625
+ .start_line(getattr(target, "lineno", -1))
626
+ .end_line(
627
627
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
628
628
  )
629
- .with_start_column(getattr(target, "col_offset", -1))
630
- .with_end_column(getattr(target, "end_col_offset", -1))
629
+ .start_column(getattr(target, "col_offset", -1))
630
+ .end_column(getattr(target, "end_col_offset", -1))
631
631
  .build()
632
632
  )
633
633
 
@@ -638,23 +638,21 @@ class SymbolTableBuilder:
638
638
  if isinstance(target, ast.Name):
639
639
  module_vars.append(
640
640
  PyVariableDeclaration.builder()
641
- .with_name(target.id)
642
- .with_type(
641
+ .name(target.id)
642
+ .type(
643
643
  ast.unparse(node.annotation)
644
644
  if node.annotation
645
645
  else self._infer_type(script, node.lineno, node.col_offset)
646
646
  )
647
- .with_initializer(
648
- ast.unparse(node.value) if node.value else None
649
- )
650
- .with_value(None)
651
- .with_scope("module")
652
- .with_start_line(getattr(target, "lineno", -1))
653
- .with_end_line(
647
+ .initializer(ast.unparse(node.value) if node.value else None)
648
+ .value(None)
649
+ .scope("module")
650
+ .start_line(getattr(target, "lineno", -1))
651
+ .end_line(
654
652
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
655
653
  )
656
- .with_start_column(getattr(target, "col_offset", -1))
657
- .with_end_column(getattr(target, "end_col_offset", -1))
654
+ .start_column(getattr(target, "col_offset", -1))
655
+ .end_column(getattr(target, "end_col_offset", -1))
658
656
  .build()
659
657
  )
660
658
 
@@ -682,23 +680,23 @@ class SymbolTableBuilder:
682
680
  if isinstance(target, ast.Name):
683
681
  local_vars.append(
684
682
  PyVariableDeclaration.builder()
685
- .with_name(target.id)
686
- .with_type(
683
+ .name(target.id)
684
+ .type(
687
685
  self._infer_type(
688
686
  script, target.lineno, target.col_offset
689
687
  )
690
688
  )
691
- .with_initializer(
689
+ .initializer(
692
690
  ast.unparse(node.value) if node.value else None
693
691
  )
694
- .with_value(None)
695
- .with_scope("function")
696
- .with_start_line(getattr(target, "lineno", -1))
697
- .with_end_line(
692
+ .value(None)
693
+ .scope("function")
694
+ .start_line(getattr(target, "lineno", -1))
695
+ .end_line(
698
696
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
699
697
  )
700
- .with_start_column(getattr(target, "col_offset", -1))
701
- .with_end_column(getattr(target, "end_col_offset", -1))
698
+ .start_column(getattr(target, "col_offset", -1))
699
+ .end_column(getattr(target, "end_col_offset", -1))
702
700
  .build()
703
701
  )
704
702
  # This handles instance attribute assignments like self.attr = value
@@ -709,23 +707,23 @@ class SymbolTableBuilder:
709
707
  ):
710
708
  local_vars.append(
711
709
  PyVariableDeclaration.builder()
712
- .with_name(target.attr)
713
- .with_type(
710
+ .name(target.attr)
711
+ .type(
714
712
  self._infer_type(
715
713
  script, target.lineno, target.col_offset
716
714
  )
717
715
  )
718
- .with_initializer(
716
+ .initializer(
719
717
  ast.unparse(node.value) if node.value else None
720
718
  )
721
- .with_value(None)
722
- .with_scope("class")
723
- .with_start_line(getattr(target, "lineno", -1))
724
- .with_end_line(
719
+ .value(None)
720
+ .scope("class")
721
+ .start_line(getattr(target, "lineno", -1))
722
+ .end_line(
725
723
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
726
724
  )
727
- .with_start_column(getattr(target, "col_offset", -1))
728
- .with_end_column(getattr(target, "end_col_offset", -1))
725
+ .start_column(getattr(target, "col_offset", -1))
726
+ .end_column(getattr(target, "end_col_offset", -1))
729
727
  .build()
730
728
  )
731
729
 
@@ -741,17 +739,17 @@ class SymbolTableBuilder:
741
739
  if isinstance(target, ast.Name):
742
740
  local_vars.append(
743
741
  PyVariableDeclaration.builder()
744
- .with_name(target.id)
745
- .with_type(annotation_str)
746
- .with_initializer(initializer_str)
747
- .with_value(None)
748
- .with_scope("function")
749
- .with_start_line(getattr(target, "lineno", -1))
750
- .with_end_line(
742
+ .name(target.id)
743
+ .type(annotation_str)
744
+ .initializer(initializer_str)
745
+ .value(None)
746
+ .scope("function")
747
+ .start_line(getattr(target, "lineno", -1))
748
+ .end_line(
751
749
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
752
750
  )
753
- .with_start_column(getattr(target, "col_offset", -1))
754
- .with_end_column(getattr(target, "end_col_offset", -1))
751
+ .start_column(getattr(target, "col_offset", -1))
752
+ .end_column(getattr(target, "end_col_offset", -1))
755
753
  .build()
756
754
  )
757
755
  # Annotated instance attribute: self.attr: int = SOME_VALUE
@@ -762,17 +760,17 @@ class SymbolTableBuilder:
762
760
  ):
763
761
  local_vars.append(
764
762
  PyVariableDeclaration.builder()
765
- .with_name(target.attr)
766
- .with_type(annotation_str)
767
- .with_initializer(initializer_str)
768
- .with_value(None)
769
- .with_scope("class")
770
- .with_start_line(getattr(target, "lineno", -1))
771
- .with_end_line(
763
+ .name(target.attr)
764
+ .type(annotation_str)
765
+ .initializer(initializer_str)
766
+ .value(None)
767
+ .scope("class")
768
+ .start_line(getattr(target, "lineno", -1))
769
+ .end_line(
772
770
  getattr(node, "end_lineno", getattr(node, "lineno", -1))
773
771
  )
774
- .with_start_column(getattr(target, "col_offset", -1))
775
- .with_end_column(getattr(target, "end_col_offset", -1))
772
+ .start_column(getattr(target, "col_offset", -1))
773
+ .end_column(getattr(target, "end_col_offset", -1))
776
774
  .build()
777
775
  )
778
776
 
@@ -859,14 +857,14 @@ class SymbolTableBuilder:
859
857
 
860
858
  return (
861
859
  PySymbol.builder()
862
- .with_name(name)
863
- .with_scope(scope)
864
- .with_kind(kind)
865
- .with_type(inferred_type)
866
- .with_qualified_name(qname)
867
- .with_is_builtin(is_builtin)
868
- .with_lineno(lineno)
869
- .with_col_offset(col_offset)
860
+ .name(name)
861
+ .scope(scope)
862
+ .kind(kind)
863
+ .type(inferred_type)
864
+ .qualified_name(qname)
865
+ .is_builtin(is_builtin)
866
+ .lineno(lineno)
867
+ .col_offset(col_offset)
870
868
  .build()
871
869
  )
872
870
 
@@ -1,5 +1,4 @@
1
- from .logging import logger
2
- from .logging import _set_log_level
1
+ from .logging import _set_log_level, logger
3
2
  from .progress_bar import ProgressBar
4
3
 
5
4
  __all__ = ["logger", "_set_log_level", "ProgressBar"]
@@ -1,6 +1,7 @@
1
+ import logging
2
+
1
3
  from rich.console import Console
2
4
  from rich.logging import RichHandler
3
- import logging
4
5
 
5
6
  # Set up base logger with RichHandler
6
7
  console = Console()
@@ -1,15 +1,16 @@
1
+ import logging
2
+ from typing import Optional
3
+
1
4
  from rich.console import Console
2
5
  from rich.progress import (
6
+ BarColumn,
3
7
  Progress,
4
8
  SpinnerColumn,
9
+ TaskID,
5
10
  TextColumn,
6
- BarColumn,
7
11
  TimeElapsedColumn,
8
12
  TimeRemainingColumn,
9
- TaskID,
10
13
  )
11
- from typing import Optional
12
- import logging
13
14
 
14
15
 
15
16
  class ProgressBar: