Skip to content

Commit bbfb6a9

Browse files
committed
Reverted change to retrieve package version from PyPI , PR #16, due to WASM incompatibility.
1 parent 5932b27 commit bbfb6a9

10 files changed

Lines changed: 45 additions & 42 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Issues = "https://github.com/nocomplexity/codeaudit/issues"
3737
Source = "https://github.com/nocomplexity/codeaudit"
3838

3939
[tool.hatch.version]
40-
source = "vcs"
40+
path = "src/codeaudit/__about__.py"
4141

4242

4343
[tool.hatch.build.targets.wheel]
@@ -46,7 +46,8 @@ include = ["src/codeaudit/data/*.csv"]
4646

4747

4848
[project.scripts]
49-
codeaudit = "codeaudit.codeaudit:main"
49+
codeaudit = "codeaudit.corecli:main"
50+
5051

5152
[tool.hatch.envs.types]
5253
extra-dependencies = [

src/codeaudit/__about__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: 2025-present Maikel Mardjan
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
__version__ = "1.6.5rc2"

src/codeaudit/api_interfaces.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import platform
2020
from collections import Counter
2121
from pathlib import Path
22-
from importlib.metadata import version
2322

2423
import altair as alt
2524
import pandas as pd
2625

26+
from codeaudit.__about__ import __version__
27+
2728

2829
from codeaudit.checkmodules import (
2930
check_module_vulnerability,
@@ -47,13 +48,13 @@
4748
total_modules,
4849
)
4950

50-
51-
def version_info():
52-
"""Returns the version of Python Code Audit"""
53-
ca_version = version("codeaudit")
51+
def version():
52+
"""Returns the version of Python Code Audit - WASM safe"""
53+
ca_version = __version__
5454
return {"name": "Python_Code_Audit", "version": ca_version}
5555

5656

57+
5758
def filescan(input_path, nosec=False):
5859
"""
5960
Scan a Python source file, a local directory, or a **PyPI package** from PyPI.org for
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
"""
1515

1616
import sys
17-
from importlib.metadata import version
1817

1918
import fire # for working CLI with this PoC-thing (The Google way)
2019

20+
from codeaudit.__about__ import __version__
2121
from codeaudit.reporting import (
2222
overview_report,
2323
report_implemented_tests,
2424
report_module_information,
2525
scan_report,
2626
)
2727

28-
CA_VERSION = version("codeaudit")
28+
CA_VERSION = __version__
2929

3030
codeaudit_ascii_art = r"""
3131
----------------------------------------------------

src/codeaudit/dashboard_reports.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
API functions: Used for dashboard reporting (Panel / WASM) and notebooks, or to build custom reports.
1313
"""
1414

15-
import panel as pn
16-
pn.extension()
1715

18-
from codeaudit.api_interfaces import version_info
16+
from codeaudit.__about__ import __version__
1917

2018
SAST_REPORT_CSS = """
2119
<style>
@@ -84,26 +82,16 @@
8482
</style>
8583
"""
8684

87-
8885
def _require_panel():
89-
"""Import the optional Panel dependency.
90-
91-
Returns:
92-
module: The imported panel module.
93-
94-
Raises:
95-
ImportError: If the panel package is not installed. The error message
96-
instructs the user to install the optional dependency.
97-
"""
86+
"""Import the optional Panel dependency safely."""
9887
try:
9988
import panel as pn
10089
pn.extension()
101-
10290
return pn
10391
except ImportError:
10492
raise ImportError(
105-
"Optional dependency Python package 'panel' not installed. "
106-
"Run: pip install panel"
93+
"Optional dependency 'panel' is not available in this environment "
94+
"(e.g. WASM/Pyodide). Install it with: pip install panel"
10795
)
10896

10997

@@ -432,9 +420,8 @@ def get_disclaimer_text():
432420
"""defines the sidebar disclaimer text"""
433421
pn = _require_panel() # Panel module is needed for this function
434422

435-
# Get the version string from version_info
436-
v_info = version_info()
437-
version_id = v_info['version']
423+
# Get the version string
424+
version_id = __version__
438425

439426
disclaimer = (
440427
f"<br><b>Disclaimer:</b> This scan only evaluates Python files. "

src/codeaudit/privacy_lint.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import datetime
1717
import re
1818
from importlib.resources import files
19-
from importlib.metadata import version
2019
from pathlib import Path
2120

21+
from codeaudit.__about__ import __version__
22+
2223

2324
from codeaudit.filehelpfunctions import (
2425
collect_python_source_files,
@@ -62,8 +63,8 @@ def data_egress_scan(input_path):
6263
returned dictionary.
6364
"""
6465
file_output = {}
65-
file_path = Path(input_path)
66-
ca_version_info = {"name": "Python_Code_Audit", "version": version("codeaudit")}
66+
file_path = Path(input_path)
67+
ca_version_info = {"name": "Python_Code_Audit", "version": __version__}
6768
now = datetime.datetime.now()
6869
timestamp_str = now.strftime("%Y-%m-%d %H:%M")
6970
output = ca_version_info | {"generated_on": timestamp_str}

src/codeaudit/pypi_package_scan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
CA_VERSION = version("codeaudit")
2727

28+
2829
NOCX_HEADERS = {
2930
"user-agent": f"Python Code Audit /{CA_VERSION} (https://github.com/nocomplexity/codeaudit)",
3031
"Accept": "text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8",

src/codeaudit/reporting.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
from pathlib import Path
1919
import sys
2020

21-
from importlib.metadata import version
2221

2322
import pandas as pd
2423
import html
2524
import datetime
25+
from importlib.resources import files
26+
27+
from codeaudit.__about__ import __version__
2628

2729
from codeaudit.security_checks import perform_validations, ast_security_checks
2830
from codeaudit.filehelpfunctions import (
@@ -52,9 +54,8 @@
5254
from codeaudit.suppression import filter_sast_results
5355
from codeaudit.api_interfaces import _collect_issue_lines
5456

55-
from importlib.resources import files
5657

57-
CA_VERSION = version("codeaudit")
58+
CA_VERSION = __version__
5859

5960
PYTHON_CODE_AUDIT_TEXT = '<a href="https://github.com/nocomplexity/codeaudit" target="_blank"><b>Python Code Audit</b></a>'
6061
DISCLAIMER_TEXT = (

src/dashboard/dashboardapp.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
WASM Dashboard version of codeaudit - limited functionality -
1414
"""
1515

16+
import panel as pn
17+
pn.extension("vega")
18+
1619
import asyncio
1720
import datetime
1821
import inspect
1922
import json
2023
import sys
2124

22-
import panel as pn
23-
24-
pn.extension("vega")
2525

26+
from codeaudit.__about__ import __version__
2627

2728
from codeaudit.altairplots import (
2829
ast_nodes_overview,
@@ -36,7 +37,8 @@
3637
)
3738
from codeaudit.api_helpers import _codeaudit_directory_scan_wasm
3839

39-
from codeaudit.api_interfaces import get_package_source , version_info
40+
from codeaudit.api_interfaces import get_package_source
41+
4042

4143
from codeaudit.dashboard_reports import (
4244
create_statistics_overview,
@@ -46,6 +48,10 @@
4648
report_used_modules,
4749
)
4850

51+
#------- <TMP fix> ----------
52+
53+
#------- </TMP fix> ----------
54+
4955
# --- Environment Detection ---
5056
IS_PYODIDE = "pyodide" in sys.modules
5157

@@ -133,8 +139,8 @@ async def filescan_wasm(input_path, nosec=False):
133139
Matches the behaviour of the original implementation for PyPI scans.
134140
135141
PYPI PACKAGE ONLY (for now)
136-
"""
137-
ca_version_info = version_info()
142+
"""
143+
ca_version_info = {"name": "Python_Code_Audit", "version": __version__}
138144
now = datetime.datetime.now()
139145
timestamp_str = now.strftime("%Y-%m-%d %H:%M")
140146
output = ca_version_info | {"generated_on": timestamp_str}
@@ -202,6 +208,7 @@ async def filescan_wasm(input_path, nosec=False):
202208

203209
overview_visuals = create_statistics_overview(result_pane.object)
204210

211+
205212
tabs = pn.Tabs(
206213
("Package Overview", overview_visuals),
207214
("Used Modules", overview_visuals),

tests/test_apicalls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import pytest
66
from pathlib import Path
77

8-
from codeaudit.api_interfaces import version_info, get_overview
8+
from codeaudit.api_interfaces import version, get_overview
99

1010
from codeaudit.filehelpfunctions import read_in_source_file
1111
from codeaudit.checkmodules import get_imported_modules
1212

1313

1414
def test_api_version():
1515

16-
actual_data = version_info()
16+
actual_data = version()
1717
assert "name" in actual_data
1818
assert "version" in actual_data
1919
assert actual_data["name"] == "Python_Code_Audit"

0 commit comments

Comments
 (0)