Skip to content

Commit 0fd09b4

Browse files
committed
Remove CodeQL re-introduced by merge with main
Strips the using_codeql flag, --codeql/--no-codeql CLI option, CodeQL __enter__ setup block, and codeql_edges call from analyze() that were brought in when merging main. CodeQL is incompatible with open-source distribution (proprietary CLI, licensed query packs); this branch uses PyCG as the level-2 call-graph backend instead. Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
1 parent c85c457 commit 0fd09b4

2 files changed

Lines changed: 3 additions & 65 deletions

File tree

codeanalyzer/__main__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ def main(
8383
help="Neo4j database name (default: server default). [env: NEO4J_DATABASE]",
8484
),
8585
] = None,
86-
using_codeql: Annotated[
87-
bool, typer.Option("--codeql/--no-codeql", help="Enable CodeQL-based analysis.")
88-
] = False,
8986
analysis_level: Annotated[
9087
int,
9188
typer.Option(
@@ -200,7 +197,6 @@ def main(
200197
neo4j_user=neo4j_user,
201198
neo4j_password=neo4j_password,
202199
neo4j_database=neo4j_database,
203-
using_codeql=using_codeql,
204200
analysis_level=analysis_level,
205201
using_ray=using_ray,
206202
rebuild_analysis=rebuild_analysis,
@@ -286,7 +282,7 @@ def _write_output(artifacts, output_dir: Path, format: OutputFormat):
286282
app = typer.Typer(
287283
callback=main,
288284
name="canpy",
289-
help="Static Analysis on Python source code using Jedi, PyCG, CodeQL and Tree sitter.",
285+
help="Static Analysis on Python source code using Jedi, PyCG and Tree sitter.",
290286
invoke_without_command=True,
291287
no_args_is_help=True,
292288
add_completion=False,

codeanalyzer/core.py

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -326,60 +326,6 @@ def __enter__(self) -> "Codeanalyzer":
326326
if not self.no_venv and venv_path.exists():
327327
self.virtualenv = venv_path
328328

329-
if self.using_codeql:
330-
logger.info(f"(Re-)initializing CodeQL analysis for {self.project_dir}")
331-
332-
# Resolve the CLI binary before anything else uses it: DB build
333-
# below needs it, and so does every subsequent query run.
334-
self.codeql_bin = self._ensure_codeql_bin()
335-
# Download the standard query library pack (idempotent). The
336-
# CLI install ships only the language extractors; the
337-
# ``codeql/python-all`` library pack must be fetched separately.
338-
self.codeql_packs_dir = self._ensure_codeql_packs(self.codeql_bin)
339-
340-
cache_root = self.cache_dir / "codeql"
341-
cache_root.mkdir(parents=True, exist_ok=True)
342-
self.db_path = cache_root / f"{self.project_dir.name}-db"
343-
self.db_path.mkdir(exist_ok=True)
344-
345-
checksum_file = self.db_path / ".checksum"
346-
current_checksum = self._compute_checksum(self.project_dir)
347-
348-
def is_cache_valid() -> bool:
349-
if not (self.db_path / "db-python").exists():
350-
return False
351-
if not checksum_file.exists():
352-
return False
353-
return checksum_file.read_text().strip() == current_checksum
354-
355-
if self.rebuild_analysis or not is_cache_valid():
356-
logger.info("Creating new CodeQL database...")
357-
358-
cmd = [
359-
str(self.codeql_bin),
360-
"database",
361-
"create",
362-
str(self.db_path),
363-
f"--source-root={self.project_dir}",
364-
"--language=python",
365-
"--overwrite",
366-
]
367-
368-
proc = subprocess.Popen(
369-
cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE
370-
)
371-
_, err = proc.communicate()
372-
373-
if proc.returncode != 0:
374-
raise CodeQLExceptions.CodeQLDatabaseBuildException(
375-
f"Error building CodeQL database:\n{err.decode()}"
376-
)
377-
378-
checksum_file.write_text(current_checksum)
379-
380-
else:
381-
logger.info(f"Reusing cached CodeQL DB at {self.db_path}")
382-
383329
return self
384330

385331
def __exit__(self, *args, **kwargs) -> None:
@@ -444,15 +390,11 @@ def analyze(self) -> PyApplication:
444390
# Build symbol table from cached application if available (if no available, the build a new one)
445391
symbol_table = self._build_symbol_table(cached_pyapplication.symbol_table if cached_pyapplication else {})
446392

447-
# Optional CodeQL pass: augments PyCallsites in-place before Jedi runs,
448-
# so Jedi edges benefit from CodeQL's resolved callee_signatures.
449-
codeql_edges = self._get_call_graph(symbol_table, augment_sites=True)
450-
451393
resolve_unresolved_constructors(symbol_table)
452394

453-
# Level 1: Jedi + CodeQL call graph.
395+
# Level 1: Jedi call graph.
454396
jedi_edges = jedi_call_graph_edges(symbol_table)
455-
call_graph = merge_edges(jedi_edges, codeql_edges)
397+
call_graph = list(jedi_edges)
456398

457399
if self.analysis_level >= 2:
458400
# Level 2: also add PyCG edges.

0 commit comments

Comments
 (0)