codeanalyzer-python 0.1.10__py3-none-any.whl → 0.1.11__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.
codeanalyzer/__main__.py CHANGED
@@ -6,6 +6,7 @@ import typer
6
6
  from codeanalyzer.core import Codeanalyzer
7
7
  from codeanalyzer.utils import _set_log_level, logger
8
8
  from codeanalyzer.config import OutputFormat
9
+ from codeanalyzer.schema import model_dump_json
9
10
 
10
11
  def main(
11
12
  input: Annotated[
@@ -102,7 +103,7 @@ def main(
102
103
  # Handle output based on format
103
104
  if output is None:
104
105
  # Output to stdout (only for JSON)
105
- print(artifacts.json(separators=(",", ":")))
106
+ print(model_dump_json(artifacts, separators=(",", ":")))
106
107
  else:
107
108
  # Output to file
108
109
  output.mkdir(parents=True, exist_ok=True)
@@ -113,8 +114,8 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
113
114
  """Write artifacts to file in the specified format."""
114
115
  if format == OutputFormat.JSON:
115
116
  output_file = output_dir / "analysis.json"
116
- # Use Pydantic's json() with separators for compact output
117
- json_str = artifacts.json(indent=None)
117
+ # Use Pydantic's model_dump_json() for compact output
118
+ json_str = model_dump_json(artifacts, indent=None)
118
119
  with output_file.open("w") as f:
119
120
  f.write(json_str)
120
121
  logger.info(f"Analysis saved to {output_file}")
codeanalyzer/core.py CHANGED
@@ -8,7 +8,7 @@ from typing import Any, Dict, Optional, Union, List
8
8
 
9
9
  import ray
10
10
  from codeanalyzer.utils import logger
11
- from codeanalyzer.schema import PyApplication, PyModule
11
+ from codeanalyzer.schema import PyApplication, PyModule, model_dump_json, model_validate_json
12
12
  from codeanalyzer.semantic_analysis.codeql import CodeQLLoader
13
13
  from codeanalyzer.semantic_analysis.codeql.codeql_exceptions import CodeQLExceptions
14
14
  from codeanalyzer.syntactic_analysis.exceptions import SymbolTableBuilderRayError
@@ -408,7 +408,7 @@ class Codeanalyzer:
408
408
  """
409
409
  with cache_file.open('r') as f:
410
410
  data = f.read()
411
- return PyApplication.parse_raw(data)
411
+ return model_validate_json(PyApplication, data)
412
412
 
413
413
  def _save_analysis_cache(self, app: PyApplication, cache_file: Path) -> None:
414
414
  """Save analysis to cache file.
@@ -421,8 +421,8 @@ class Codeanalyzer:
421
421
  cache_file.parent.mkdir(parents=True, exist_ok=True)
422
422
 
423
423
  with cache_file.open('w') as f:
424
- f.write(app.json(indent=2))
425
-
424
+ f.write(model_dump_json(app, indent=2))
425
+
426
426
  logger.info(f"Analysis cached to {cache_file}")
427
427
 
428
428
  def _file_unchanged(self, file_path: Path, cached_module: PyModule) -> bool:
@@ -1,3 +1,6 @@
1
+ from importlib.metadata import version, PackageNotFoundError
2
+ from packaging.version import parse as parse_version
3
+
1
4
  from .py_schema import (
2
5
  PyApplication,
3
6
  PyCallable,
@@ -22,12 +25,48 @@ __all__ = [
22
25
  "PyCallableParameter",
23
26
  ]
24
27
 
25
- # Resolve forward references
26
- PyCallable.update_forward_refs(PyClass=PyClass)
27
- PyClass.update_forward_refs(PyCallable=PyCallable)
28
- PyModule.update_forward_refs(PyCallable=PyCallable, PyClass=PyClass)
29
- PyApplication.update_forward_refs(
30
- PyCallable=PyCallable,
31
- PyClass=PyClass,
32
- PyModule=PyModule
33
- )
28
+ try:
29
+ pydantic_version = version("pydantic")
30
+ except PackageNotFoundError:
31
+ pydantic_version = "0.0.0" # fallback or raise if appropriate
32
+
33
+ PYDANTIC_V2 = parse_version(pydantic_version) >= parse_version("2.0.0")
34
+
35
+ if not PYDANTIC_V2:
36
+ # Safe to pass localns
37
+ PyCallable.update_forward_refs(PyClass=PyClass)
38
+ PyClass.update_forward_refs(PyCallable=PyCallable)
39
+ PyModule.update_forward_refs(PyCallable=PyCallable, PyClass=PyClass)
40
+ PyApplication.update_forward_refs(
41
+ PyCallable=PyCallable,
42
+ PyClass=PyClass,
43
+ PyModule=PyModule
44
+ )
45
+
46
+ # Compatibility helpers for Pydantic v1/v2
47
+ def model_dump_json(model, **kwargs):
48
+ """Compatibility helper for JSON serialization."""
49
+ if PYDANTIC_V2:
50
+ return model.model_dump_json(**kwargs)
51
+ else:
52
+ # Map Pydantic v2 parameters to v1 equivalents
53
+ v1_kwargs = {}
54
+ if 'indent' in kwargs:
55
+ v1_kwargs['indent'] = kwargs['indent']
56
+ if 'separators' in kwargs:
57
+ # In v1, separators is passed to dumps_kwargs
58
+ v1_kwargs['separators'] = kwargs['separators']
59
+ return model.json(**v1_kwargs)
60
+
61
+ def model_validate_json(model_class, json_data):
62
+ """Compatibility helper for JSON deserialization."""
63
+ if PYDANTIC_V2:
64
+ return model_class.model_validate_json(json_data)
65
+ else:
66
+ return model_class.parse_raw(json_data)
67
+
68
+ __all__.extend([
69
+ "PYDANTIC_V2",
70
+ "model_dump_json",
71
+ "model_validate_json"
72
+ ])
@@ -1,22 +1,34 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeanalyzer-python
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: Static Analysis on Python source code using Jedi, CodeQL and Treesitter.
5
5
  Author-email: Rahul Krishna <i.m.ralk@gmail.com>
6
6
  License-File: LICENSE
7
7
  License-File: NOTICE
8
8
  Requires-Python: >=3.9
9
- Requires-Dist: jedi<0.20.0,>=0.18.0
10
- Requires-Dist: msgpack<1.0.7,>=1.0.0
11
- Requires-Dist: networkx<3.2.0,>=2.6.0
12
- Requires-Dist: numpy<1.24.0,>=1.21.0
13
- Requires-Dist: pandas<2.0.0,>=1.3.0
14
- Requires-Dist: pydantic<2.0.0,>=1.8.0
15
- Requires-Dist: ray<3.0.0,>=2.0.0
16
- Requires-Dist: requests<3.0.0,>=2.20.0
17
- Requires-Dist: rich<14.0.0,>=12.6.0
18
- Requires-Dist: typer<1.0.0,>=0.9.0
19
- Requires-Dist: typing-extensions>=4.0.0
9
+ Requires-Dist: jedi<0.20.0,>=0.18.0; python_version < '3.11'
10
+ Requires-Dist: jedi<=0.19.2; python_version >= '3.11'
11
+ Requires-Dist: msgpack<1.0.7,>=1.0.0; python_version < '3.11'
12
+ Requires-Dist: msgpack<2.0.0,>=1.0.7; python_version >= '3.11'
13
+ Requires-Dist: networkx<3.2.0,>=2.6.0; python_version < '3.11'
14
+ Requires-Dist: networkx<4.0.0,>=3.0.0; python_version >= '3.11'
15
+ Requires-Dist: numpy<1.24.0,>=1.21.0; python_version < '3.11'
16
+ Requires-Dist: numpy<2.0.0,>=1.24.0; python_version >= '3.11' and python_version < '3.12'
17
+ Requires-Dist: numpy<2.0.0,>=1.26.0; python_version >= '3.12'
18
+ Requires-Dist: packaging>=25.0
19
+ Requires-Dist: pandas<2.0.0,>=1.3.0; python_version < '3.11'
20
+ Requires-Dist: pandas<3.0.0,>=2.0.0; python_version >= '3.11'
21
+ Requires-Dist: pydantic<2.0.0,>=1.8.0; python_version < '3.11'
22
+ Requires-Dist: pydantic<3.0.0,>=2.0.0; python_version >= '3.11'
23
+ Requires-Dist: ray<3.0.0,>=2.10.0; python_version >= '3.11'
24
+ Requires-Dist: ray==2.0.0; python_version < '3.11'
25
+ Requires-Dist: requests<3.0.0,>=2.20.0; python_version >= '3.11'
26
+ Requires-Dist: rich<14.0.0,>=12.6.0; python_version < '3.11'
27
+ Requires-Dist: rich<15.0.0,>=14.0.0; python_version >= '3.11'
28
+ Requires-Dist: typer<1.0.0,>=0.9.0; python_version < '3.11'
29
+ Requires-Dist: typer<2.0.0,>=0.9.0; python_version >= '3.11'
30
+ Requires-Dist: typing-extensions<5.0.0,>=4.0.0; python_version < '3.11'
31
+ Requires-Dist: typing-extensions<6.0.0,>=4.5.0; python_version >= '3.11'
20
32
  Description-Content-Type: text/markdown
21
33
 
22
34
  ![logo](https://github.com/codellm-devkit/codeanalyzer-python/blob/main/docs/assets/logo.png?raw=true)
@@ -1,12 +1,12 @@
1
1
  codeanalyzer/__init__.py,sha256=BZ3Kuwl-F_F-8H8cepLnVJ4Ku4NNUjjqg0Y6ujPQSsI,108
2
- codeanalyzer/__main__.py,sha256=x2LNDxYndzV2LkauBz7-_0qR58seRx-yJ07-obs4o9Q,4855
3
- codeanalyzer/core.py,sha256=RUJrtmtCFAxBLyI_eHp3Oi0tWAU09DeI7wUD7vfQwi0,24926
2
+ codeanalyzer/__main__.py,sha256=e-AMzR5uR1IsUKhsfk17_qPJkwORRqe9tBxCXwwlxBY,4922
3
+ codeanalyzer/core.py,sha256=swFc-6ICs_rijj7P0bbJv3um2Gr-R8_roGK0P3qo1xc,24979
4
4
  codeanalyzer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  codeanalyzer/config/__init__.py,sha256=9XBxAn1oWGRuhg3bEBUuVGs3hFNXEAKrr-Ce7tq9a2k,61
6
6
  codeanalyzer/config/config.py,sha256=ZiKzc5uEUCIvih58-6BDtLLI1hPij41wGQjBcj9KNQM,188
7
7
  codeanalyzer/jedi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  codeanalyzer/jedi/jedi.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- codeanalyzer/schema/__init__.py,sha256=k6N1AfXe1J7cSFBdRJlYo1FPVrr4HeXgzEmVy8MUhC4,694
9
+ codeanalyzer/schema/__init__.py,sha256=HB7y4y-49dkEo-H9GREam1_9Cr1N-GF6MYwx9yoU878,1978
10
10
  codeanalyzer/schema/py_schema.py,sha256=04K19tDtmg2tPXjwu_8BcmVpenk1ibVwNv6bHWZHOLY,10851
11
11
  codeanalyzer/semantic_analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  codeanalyzer/semantic_analysis/codeql/__init__.py,sha256=ODMkdGvs3ebJdfIZle8T4VcHoCBhH_ZehWuWFpNh3NI,1022
@@ -21,9 +21,9 @@ codeanalyzer/syntactic_analysis/symbol_table_builder.py,sha256=0FE_ZdlyP77P1B70Q
21
21
  codeanalyzer/utils/__init__.py,sha256=hC6VWdR5rerSqBxzu9KQHTASWqwrrYJv-CMDwrTlzkc,137
22
22
  codeanalyzer/utils/logging.py,sha256=0vTkGSl5EZN8yhhWa_5Mrn1n_twRCSW53rNwjzQ9RbI,601
23
23
  codeanalyzer/utils/progress_bar.py,sha256=ZHJzGiCo5q4dyXq4CtsrJeq9Ip7sD84T3yZjNX7TBys,2443
24
- codeanalyzer_python-0.1.10.dist-info/METADATA,sha256=hZtJ0nMdkzF9Bm1JTzaypIFLWpl9bOL1xrtrvdKBjRU,15261
25
- codeanalyzer_python-0.1.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
- codeanalyzer_python-0.1.10.dist-info/entry_points.txt,sha256=eUrB7Jq5Oav6RblMX_RYfVLSw_h15NbzC3fNSnGsPuM,59
27
- codeanalyzer_python-0.1.10.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
- codeanalyzer_python-0.1.10.dist-info/licenses/NOTICE,sha256=YU0Z9NDWqKY-2jfFcbxeZ6fbnzz0oZeKmnUcO8a-bcQ,901
29
- codeanalyzer_python-0.1.10.dist-info/RECORD,,
24
+ codeanalyzer_python-0.1.11.dist-info/METADATA,sha256=yqQiVgSsG1k262sigcRo51BScmuVQywLOtL9rEX5ATI,16283
25
+ codeanalyzer_python-0.1.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
+ codeanalyzer_python-0.1.11.dist-info/entry_points.txt,sha256=eUrB7Jq5Oav6RblMX_RYfVLSw_h15NbzC3fNSnGsPuM,59
27
+ codeanalyzer_python-0.1.11.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
28
+ codeanalyzer_python-0.1.11.dist-info/licenses/NOTICE,sha256=YU0Z9NDWqKY-2jfFcbxeZ6fbnzz0oZeKmnUcO8a-bcQ,901
29
+ codeanalyzer_python-0.1.11.dist-info/RECORD,,