codeaudit 0.9.0__tar.gz → 0.9.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.
Files changed (126) hide show
  1. {codeaudit-0.9.0 → codeaudit-0.9.1}/PKG-INFO +1 -1
  2. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/modulescan.md +1 -1
  3. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/__about__.py +1 -1
  4. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/altairplots.py +1 -1
  5. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/checkmodules.py +2 -7
  6. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/reporting.py +8 -4
  7. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/totals.py +31 -9
  8. {codeaudit-0.9.0 → codeaudit-0.9.1}/.gitignore +0 -0
  9. {codeaudit-0.9.0 → codeaudit-0.9.1}/CONTRIBUTE.md +0 -0
  10. {codeaudit-0.9.0 → codeaudit-0.9.1}/LICENSE.txt +0 -0
  11. {codeaudit-0.9.0 → codeaudit-0.9.1}/README.md +0 -0
  12. {codeaudit-0.9.0 → codeaudit-0.9.1}/SECURITY.md +0 -0
  13. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/CLIcommands.ipynb +0 -0
  14. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/CONTRIBUTE.md +0 -0
  15. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/_config.yml +0 -0
  16. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/_static/nocxstyle.css +0 -0
  17. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/_toc.yml +0 -0
  18. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/about.md +0 -0
  19. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/astlines.md +0 -0
  20. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/astlines2.md +0 -0
  21. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/assert_check.md +0 -0
  22. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/base64_check.md +0 -0
  23. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/binding_check.md +0 -0
  24. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/builtinfunctions_check.md +0 -0
  25. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/chmod_check.md +0 -0
  26. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/directorycreation_check.md +0 -0
  27. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/exception_check.md +0 -0
  28. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/hash_check.md +0 -0
  29. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/httpserver_check.md +0 -0
  30. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/input_check.md +0 -0
  31. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/loggingconf_check.md +0 -0
  32. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/marshal_check.md +0 -0
  33. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/mktemp_check.md +0 -0
  34. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/multiprocessing_check.md +0 -0
  35. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/pickle_check.md +0 -0
  36. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/random_check.md +0 -0
  37. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/shelve_check.md +0 -0
  38. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/shutil_check.md +0 -0
  39. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/subprocess_check.md +0 -0
  40. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/syscalls_check.md +0 -0
  41. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/systemcalls_check.md +0 -0
  42. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/tarfile_extract_check.md +0 -0
  43. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/xml_check.md +0 -0
  44. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checks/zipfile_check.md +0 -0
  45. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/checksinformation.md +0 -0
  46. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/codeauditchecks.md +0 -0
  47. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/codeauditcommands.md +0 -0
  48. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/codeauditoverview.md +0 -0
  49. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/complexitycheck.md +0 -0
  50. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/directoryscan.md +0 -0
  51. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/examples/checks_example.html +0 -0
  52. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/examples/directoryscan.html +0 -0
  53. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/examples/filescan.html +0 -0
  54. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/examples/modulescan.html +0 -0
  55. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/examples/overview.html +0 -0
  56. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/features.md +0 -0
  57. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/filescan.md +0 -0
  58. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/filescan.png +0 -0
  59. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/help.md +0 -0
  60. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/OO.png +0 -0
  61. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/ROI_logo.png +0 -0
  62. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/YourLogoHere.png +0 -0
  63. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/codeauditlogo.png +0 -0
  64. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/nocxbanner.png +0 -0
  65. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/images/overview_linkaudit.png +0 -0
  66. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/intro.md +0 -0
  67. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/license.md +0 -0
  68. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/overviewplot.png +0 -0
  69. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/sponsors.md +0 -0
  70. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/userguide.md +0 -0
  71. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/warnings.md +0 -0
  72. {codeaudit-0.9.0 → codeaudit-0.9.1}/docs/whysast.md +0 -0
  73. {codeaudit-0.9.0 → codeaudit-0.9.1}/filescan.png +0 -0
  74. {codeaudit-0.9.0 → codeaudit-0.9.1}/pyproject.toml +0 -0
  75. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/__init__.py +0 -0
  76. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/codeaudit.py +0 -0
  77. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/complexitycheck.py +0 -0
  78. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/data/sastchecks.csv +0 -0
  79. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/filehelpfunctions.py +0 -0
  80. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/htmlhelpfunctions.py +0 -0
  81. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/issuevalidations.py +0 -0
  82. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/security_checks.py +0 -0
  83. {codeaudit-0.9.0 → codeaudit-0.9.1}/src/codeaudit/simple.css +0 -0
  84. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/__init__.py +0 -0
  85. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/count_lines_file1.py +0 -0
  86. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_basicpatterns.py +0 -0
  87. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_chmod.py +0 -0
  88. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_constructspart2.py +0 -0
  89. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_correctexceptionuse.py +0 -0
  90. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_count_commentlines.py +0 -0
  91. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_directorycreation.py +0 -0
  92. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_directorycreation2.py +0 -0
  93. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_hashstrenght.py +0 -0
  94. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_modulecheck.py +0 -0
  95. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_oschecks.py +0 -0
  96. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_random.py +0 -0
  97. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/test_standardlibconstructs.py +0 -0
  98. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/allshit.py +0 -0
  99. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/assert.py +0 -0
  100. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/base64.py +0 -0
  101. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/chmod_things.py +0 -0
  102. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/directorycreation.py +0 -0
  103. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/directorycreation2.py +0 -0
  104. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/exception.py +0 -0
  105. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/file3.py +0 -0
  106. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/file_with_warnings.py +0 -0
  107. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/hashcheck.py +0 -0
  108. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/httpserver.py +0 -0
  109. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/inputstatement.py +0 -0
  110. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/marshal.py +0 -0
  111. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/modulecheck.py +0 -0
  112. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/multiprocessing.py +0 -0
  113. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/oschecks.py +0 -0
  114. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/pickle.py +0 -0
  115. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/python2_file_willnotwork.py +0 -0
  116. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/random.py +0 -0
  117. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/shelve.py +0 -0
  118. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/shutil.py +0 -0
  119. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/subprocess.py +0 -0
  120. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/syslibrary.py +0 -0
  121. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/tarfilevalidation.py +0 -0
  122. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/tempcheck.py +0 -0
  123. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/validation1.py +0 -0
  124. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/validation2.py +0 -0
  125. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/xml.py +0 -0
  126. {codeaudit-0.9.0 → codeaudit-0.9.1}/tests/validationfiles/zipfile.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeaudit
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: Simplified static security checks for Python
5
5
  Project-URL: Documentation, https://github.com/nocomplexity/codeaudit#readme
6
6
  Project-URL: Issues, https://github.com/nocomplexity/codeaudit/issues
@@ -15,7 +15,7 @@ The `<INPUTFILE>` is mandatory. Codeaudit will create a modulescan report for th
15
15
  If you do not specify [OUTPUTFILE], a HTML output file, a HTML report file is created in the current directory and will be named `codeaudit-report.html`.
16
16
 
17
17
  When running `codeaudit modulescan` detailed information is determined for a Python file of:
18
- * Core modules used and
18
+ * Core modules used (aka "built-in modules" or "standard modules") and
19
19
  * Imported modules used (aka external modules that are not part of the Python Standard Library)
20
20
  * Vulnerability information (**if available**) for all imported modules. The OSV (Open Source Vulnerability Data is used) for retrieving vulnerability information. OSV is a Google FOSS project to improve the security of FOSS projects. See the [Open Security Architecture](https://nocomplexity.com/documents/securityarchitecture/references/vulnerabilitydatabases.html#vulnerability-databases) for more information.
21
21
 
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2025-present Maikel Mardjan <mike@bm-support.org>
2
2
  #
3
3
  # SPDX-License-Identifier: GPL-3.0-or-later
4
- __version__ = "0.9.0"
4
+ __version__ = "0.9.1"
@@ -51,7 +51,7 @@ def multi_bar_chart(df):
51
51
  metrics = [
52
52
  "Number_Of_Lines",
53
53
  "AST_Nodes",
54
- "Modules",
54
+ "External-Modules",
55
55
  "Functions",
56
56
  "Comment_Lines",
57
57
  "Complexity_Score",
@@ -120,16 +120,11 @@ def get_all_modules(directory_to_scan):
120
120
 
121
121
 
122
122
  def get_imported_modules_by_file(python_file_name):
123
- "Function to get all modules of a package or directory of Python files - never trust requirements.txt or project.toml"
124
- #total_result=[]
123
+ "Function to get all modules of a single Python file - never trust requirements.txt or project.toml"
125
124
  source = read_in_source_file(python_file_name)
126
125
  used_modules = get_imported_modules(source)
127
126
  core_modules = used_modules['core_modules']
128
- external_modules = used_modules['imported_modules']
129
- # result = { "filename" : python_file ,
130
- # "used_modules" : core_modules,
131
- # "external_modules": external_modules }
132
- #total_result.append(result)
127
+ external_modules = used_modules['imported_modules']
133
128
  all_modules_discovered = {
134
129
  "core_modules": sorted(core_modules),
135
130
  "imported_modules": sorted(external_modules) }
@@ -22,7 +22,7 @@ import datetime
22
22
  from codeaudit.security_checks import perform_validations , ast_security_checks
23
23
  from codeaudit.filehelpfunctions import get_filename_from_path , collect_python_source_files , read_in_source_file
24
24
  from codeaudit.altairplots import multi_bar_chart
25
- from codeaudit.totals import get_statistics , overview_count , overview_per_file
25
+ from codeaudit.totals import get_statistics , overview_count , overview_per_file , total_modules
26
26
  from codeaudit.checkmodules import get_imported_modules , check_module_on_vuln , get_all_modules , get_imported_modules_by_file
27
27
  from codeaudit.htmlhelpfunctions import dict_to_html , json_to_html , dict_list_to_html_table
28
28
  from codeaudit import __version__
@@ -51,8 +51,11 @@ def overview_report(directory, filename=DEFAULT_OUTPUT_FILE):
51
51
  print(f"ERROR: '{directory}' is not a directory (maybe you try to run it for a single file)")
52
52
  print(f"This function only works for directories which contains one or more Python source code files (*.py). ")
53
53
  exit(1)
54
- result = get_statistics(directory)
54
+ result = get_statistics(directory)
55
+ modules = total_modules(directory)
55
56
  df = pd.DataFrame(result)
57
+ df['Std-Modules'] = modules['Std-Modules']
58
+ df['External-Modules'] = modules['External-Modules']
56
59
  overview_df = overview_count(df)
57
60
  html = '<h1>' + f'Codeaudit overview report' + '</h1><br>'
58
61
  html += f'<p>Codeaudit overview scan of the directory:<b> {directory}</b></p>'
@@ -83,8 +86,9 @@ def overview_report(directory, filename=DEFAULT_OUTPUT_FILE):
83
86
  html += df.to_html(escape=True,index=False)
84
87
  html += '</details>'
85
88
  # I now want only a plot for LoC, so drop other columns from Dataframe
86
- df = df.drop(columns=['FilePath'])
87
- plot = multi_bar_chart(df)
89
+ df_plot = pd.DataFrame(result) # again make the df from the result variable
90
+ df_plot = df_plot.drop(columns=['FilePath'])
91
+ plot = multi_bar_chart(df_plot)
88
92
  plot_html = plot.to_html()
89
93
  html += '<br><br>'
90
94
  html += '<h2>Visual Overview</h2>'
@@ -25,6 +25,8 @@ from codeaudit.complexitycheck import (
25
25
  count_static_warnings_in_file,
26
26
  )
27
27
 
28
+ from codeaudit.checkmodules import get_imported_modules , get_all_modules
29
+
28
30
 
29
31
  def count_ast_objects(source):
30
32
  """
@@ -37,23 +39,27 @@ def count_ast_objects(source):
37
39
  tree = ast.parse(source)
38
40
 
39
41
  ast_nodes = 0
40
- ast_functions = 0
41
- ast_modules = 0
42
+ ast_functions = 0
42
43
  ast_classes = 0
43
-
44
+
44
45
  for node in ast.walk(tree):
45
46
  if hasattr(node, "lineno") and isinstance(node, (ast.stmt, ast.Expr)):
46
47
  ast_nodes += 1
47
48
  if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
48
49
  ast_functions += 1
49
- if isinstance(node, (ast.Import, ast.ImportFrom)):
50
- ast_modules += 1
50
+ # if isinstance(node, (ast.Import, ast.ImportFrom)):
51
+ # ast_modules += 1
51
52
  if isinstance(node, ast.ClassDef):
52
53
  ast_classes += 1
54
+
55
+ used_modules = get_imported_modules(source)
56
+ number_core_modules = len(used_modules.get('core_modules',[]))
57
+ number_external_modules = len(used_modules.get('imported_modules',[]))
53
58
 
54
59
  result = {
55
60
  "AST_Nodes": ast_nodes,
56
- "Modules": ast_modules,
61
+ "Std-Modules": number_core_modules,
62
+ "External-Modules" : number_external_modules,
57
63
  "Functions": ast_functions,
58
64
  "Classes": ast_classes,
59
65
  }
@@ -111,9 +117,18 @@ def get_statistics(directory):
111
117
  total_result = []
112
118
  for python_file in files_to_check:
113
119
  result = overview_per_file(python_file)
114
- total_result.append(result)
120
+ total_result.append(result)
115
121
  return total_result
116
122
 
123
+ def total_modules(directory):
124
+ """get the total number of modules (core and imported) for the overview"""
125
+ used_modules = get_all_modules(directory)
126
+ number_core_modules = len(used_modules.get('core_modules',[]))
127
+ number_external_modules = len(used_modules.get('imported_modules',[]))
128
+ module_result = {"Std-Modules": number_core_modules,
129
+ "External-Modules" : number_external_modules}
130
+ return module_result
131
+
117
132
 
118
133
  def overview_per_file(python_file):
119
134
  """gets the overview per file."""
@@ -143,8 +158,7 @@ def overview_count(df):
143
158
  """returns a dataframe with simple overview of all files"""
144
159
  columns_to_sum = [
145
160
  "Number_Of_Lines",
146
- "AST_Nodes",
147
- "Modules",
161
+ "AST_Nodes",
148
162
  "Functions",
149
163
  "Classes",
150
164
  "Comment_Lines",
@@ -154,6 +168,14 @@ def overview_count(df):
154
168
  df_totals.insert(
155
169
  0, "Number_Of_Files", total_number_of_files
156
170
  ) # insert new column as first colum
171
+ number_cm = df.at[0, "Std-Modules"]
172
+ df_totals.insert(
173
+ 3, "Core Modules", number_cm
174
+ )
175
+ number_em = df.at[0, "External-Modules"]
176
+ df_totals.insert(
177
+ 4, "External Modules", number_em
178
+ )
157
179
  median_complexity = round(df["Complexity_Score"].mean(), 1)
158
180
  df_totals["Median_Complexity"] = median_complexity
159
181
  maximum_complexity = df["Complexity_Score"].max()
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
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
File without changes
File without changes
File without changes
File without changes