mcpp 1.0.0__tar.gz → 1.1.1__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mcpp
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: McCabe++ (mcpp): cyclomatic complexity and other vulnerability-related code metrics
5
5
  Author-email: Lukas Pirch <lukas.pirch@tu-berlin.de>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mcpp"
3
- version = "1.0.0"
3
+ version = "1.1.1"
4
4
  description = "McCabe++ (mcpp): cyclomatic complexity and other vulnerability-related code metrics"
5
5
  readme = "README.md"
6
6
  authors = [{name = "Lukas Pirch", email="lukas.pirch@tu-berlin.de"}]
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  from importlib import resources
3
3
 
4
- from mcpp.__main__ import extract, extract_single, METRICS
4
+ from mcpp.__main__ import extract, extract_single, extract_code, METRICS
5
5
 
6
6
 
7
7
  with resources.path("mcpp", "__init__.py") as root_path:
@@ -71,5 +71,18 @@ def extract_single(in_file: Path, metrics: List[str]):
71
71
  return extract([in_file], metrics)
72
72
 
73
73
 
74
+ def extract_code(code: str, metrics: List[str] = list(METRICS.keys())):
75
+ metrics = [fun for name, fun in METRICS.items() if name in metrics]
76
+ sitter = Sitter("c", "cpp")
77
+
78
+ tree, lang = sitter.parse(code)
79
+ root = tree.root_node
80
+ calls = set(get_call_names(sitter, root, lang))
81
+ res = {}
82
+ for fun in metrics:
83
+ res.update(fun(root, sitter, lang, calls))
84
+ return res
85
+
86
+
74
87
  if __name__ == '__main__':
75
88
  main()
@@ -22,7 +22,6 @@ class Sitter(object):
22
22
  self.queries = {}
23
23
  self.queries = {"Q_ERROR_NODE": Q_ERROR_NODE}
24
24
 
25
-
26
25
  def _init_parser(self, language: str):
27
26
  parser = Parser()
28
27
  parser.set_language(self.langs[language])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mcpp
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: McCabe++ (mcpp): cyclomatic complexity and other vulnerability-related code metrics
5
5
  Author-email: Lukas Pirch <lukas.pirch@tu-berlin.de>
6
6
  License: MIT License
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes