Skip to content

Commit bc93326

Browse files
committed
refactor: polish Information shims and path helpers
Simplify legacy Information re-exports, drop dead code in paths.py, use prompts_dir consistently in codeql agents, and tighten identity tests.
1 parent 7fec159 commit bc93326

6 files changed

Lines changed: 27 additions & 31 deletions

File tree

Information/ghsa_fetch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""Legacy re-export of ``pure_auto_codeql.information.ghsa_fetch``."""
1+
"""Legacy re-export of ``pure_auto_codeql.information.ghsa_fetch``.
22
3-
from pure_auto_codeql.information.ghsa_fetch import * # noqa: F403
4-
from pure_auto_codeql.information import ghsa_fetch as _impl
3+
``from Information import ghsa_fetch`` and ``import Information.ghsa_fetch``
4+
both resolve to the canonical module object.
5+
"""
56

6-
# Preserve module-level identity for ``from Information import ghsa_fetch``
7-
# callers that access attributes on the submodule.
7+
from pure_auto_codeql.information import ghsa_fetch as _impl
88
import sys as _sys
99

1010
_sys.modules[__name__] = _impl

Information/nvd_info_fetch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
"""Legacy re-export of ``pure_auto_codeql.information.nvd_info_fetch``."""
1+
"""Legacy re-export of ``pure_auto_codeql.information.nvd_info_fetch``.
22
3-
from pure_auto_codeql.information.nvd_info_fetch import * # noqa: F403
4-
from pure_auto_codeql.information import nvd_info_fetch as _impl
3+
``from Information import nvd_info_fetch`` and ``import Information.nvd_info_fetch``
4+
both resolve to the canonical module object.
5+
"""
56

7+
from pure_auto_codeql.information import nvd_info_fetch as _impl
68
import sys as _sys
79

810
_sys.modules[__name__] = _impl

pure_auto_codeql/agents/codeql_gen_agents/source_sink_fallback_agent.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
from typing import TYPE_CHECKING, Dict, Optional
33

4-
from pure_auto_codeql.paths import get_repo_root
4+
from pure_auto_codeql.paths import prompts_dir
55

66
if TYPE_CHECKING:
77
from dataclasses import dataclass
@@ -26,8 +26,6 @@ def __init__(
2626
) -> None:
2727
self.analyzer = analyzer
2828
self.language = language or "java"
29-
30-
self._project_root = get_repo_root()
3129
self.prompt_file = prompt_file
3230

3331
def _resolve_prompt_path(self, language: Optional[str] = None) -> Path:
@@ -43,8 +41,7 @@ def _resolve_prompt_path(self, language: Optional[str] = None) -> Path:
4341
}
4442

4543
filename = mapping.get(lang) or mapping["java"]
46-
prompts_dir = self._project_root / "prompts"
47-
return (prompts_dir / filename).resolve()
44+
return (prompts_dir() / filename).resolve()
4845

4946
def _load_prompt(self, language: Optional[str] = None) -> str:
5047
try:

pure_auto_codeql/agents/codeql_gen_agents/template_refinement_agent.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
from typing import TYPE_CHECKING, Dict, Optional
33

4-
from pure_auto_codeql.paths import get_repo_root, prompts_dir
4+
from pure_auto_codeql.paths import prompts_dir
55

66
if TYPE_CHECKING:
77
from dataclasses import dataclass
@@ -26,8 +26,6 @@ def __init__(
2626
) -> None:
2727
self.analyzer = analyzer
2828
self.language = language or "java"
29-
30-
self._project_root = get_repo_root()
3129
self.prompt_file = prompt_file or (prompts_dir() / "template_refinement.md")
3230

3331
def _load_prompt(self) -> str:
@@ -57,8 +55,7 @@ def _resolve_template_path(self, language: Optional[str] = None) -> Path:
5755
}
5856

5957
filename = mapping.get(lang) or mapping["java"]
60-
prompts_dir = self._project_root / "prompts"
61-
return (prompts_dir / filename).resolve()
58+
return (prompts_dir() / filename).resolve()
6259

6360
def build_prompt(
6461
self,

pure_auto_codeql/paths.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Repository path helpers for PureAutoCodeQL.
22
33
Use these instead of hand-counting ``Path(__file__).parent`` hops when
4-
resolving assets that live at the repository root (prompts/, tools/,
5-
resources/, projects/, config/). Nested packages under
4+
resolving assets that live at the repository root (``prompts/``, ``tools/``,
5+
``resources/``, ``projects/``, ``config/``). Nested packages under
66
``pure_auto_codeql/`` make relative parent walks brittle.
77
"""
88

@@ -11,26 +11,20 @@
1111
from functools import lru_cache
1212
from pathlib import Path
1313

14-
_MARKERS = ("pyproject.toml",)
15-
1614

1715
def _looks_like_repo_root(path: Path) -> bool:
18-
if not (path / "pyproject.toml").is_file():
19-
return False
20-
# Prefer a root that still has the runtime asset layout used in-repo.
21-
if (path / "prompts").is_dir() or (path / "tools").is_dir():
22-
return True
23-
return True
16+
"""True when *path* is the PureAutoCodeQL checkout root."""
17+
return (path / "pyproject.toml").is_file()
2418

2519

2620
@lru_cache(maxsize=1)
2721
def get_repo_root() -> Path:
2822
"""Return the repository root directory.
2923
3024
Walks upward from this file until a directory containing
31-
``pyproject.toml`` is found. Falls back to three parents above this
32-
module (``pure_auto_codeql/paths.py`` → repo root in the normal
33-
checkout layout) if markers are missing (e.g. unusual install).
25+
``pyproject.toml`` is found. Falls back to the parent of the
26+
``pure_auto_codeql`` package (normal checkout layout) if no marker is
27+
found (e.g. unusual install layout).
3428
"""
3529
start = Path(__file__).resolve().parent
3630
for candidate in (start, *start.parents):

test/test_application_services.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def test_canonical_and_legacy_import_surfaces_remain_available():
112112
assert canonical_ghsa.AdvisoryLookupError is legacy_ghsa.AdvisoryLookupError
113113
assert canonical_nvd.CveLookupError is legacy_nvd.CveLookupError
114114

115+
import Information.ghsa_fetch as dotted_ghsa
116+
import pure_auto_codeql.information.ghsa_fetch as dotted_canonical_ghsa
117+
118+
assert dotted_ghsa is dotted_canonical_ghsa
119+
assert dotted_ghsa is canonical_ghsa
120+
115121
# Repo root helper resolves real asset layout
116122
root = get_repo_root()
117123
assert (root / "pyproject.toml").is_file()

0 commit comments

Comments
 (0)