refactor: split constants.py into constants/ submodule (#501)#641
refactor: split constants.py into constants/ submodule (#501)#641ChetanyaRathi wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the constants package in codebase_rag by splitting a large, monolithic constants file into smaller, domain-specific modules (ast_nodes.py, cli.py, core.py, graph.py, languages.py, operators.py). The review identified two issues where non-deterministic iteration order of sets (containing StrEnum members or strings) could lead to inconsistent behavior or output; these have been addressed by applying sorted() to ensure deterministic results.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| _missing_keys = set(NodeLabel) - set(_NODE_LABEL_UNIQUE_KEYS.keys()) | ||
| if _missing_keys: | ||
| raise RuntimeError( | ||
| f"NodeLabel(s) missing from _NODE_LABEL_UNIQUE_KEYS: {_missing_keys}. " | ||
| "Every NodeLabel MUST have a unique key defined." | ||
| ) |
There was a problem hiding this comment.
The set _missing_keys contains StrEnum members (NodeLabel). Formatting it directly in the f-string (which implicitly iterates over the set) is non-deterministic because of Python's hash randomization. To ensure deterministic output, sort the set using sorted() before formatting it.
| _missing_keys = set(NodeLabel) - set(_NODE_LABEL_UNIQUE_KEYS.keys()) | |
| if _missing_keys: | |
| raise RuntimeError( | |
| f"NodeLabel(s) missing from _NODE_LABEL_UNIQUE_KEYS: {_missing_keys}. " | |
| "Every NodeLabel MUST have a unique key defined." | |
| ) | |
| _missing_keys = set(NodeLabel) - set(_NODE_LABEL_UNIQUE_KEYS.keys()) | |
| if _missing_keys: | |
| raise RuntimeError( | |
| f"NodeLabel(s) missing from _NODE_LABEL_UNIQUE_KEYS: {sorted(_missing_keys)}. " | |
| "Every NodeLabel MUST have a unique key defined." | |
| ) |
References
- Ensure deterministic iteration order when iterating over a frozenset or set of StrEnum members by sorting them first (e.g., using sorted()), because StrEnum members hash by string and their hash order varies across runs due to Python's hash randomization.
| ) | ||
|
|
||
| # (H) Build system directory regex pattern dynamically | ||
| _SYSTEM_DIRS_PATTERN = "|".join(SHELL_SYSTEM_DIRECTORIES) |
There was a problem hiding this comment.
The SHELL_SYSTEM_DIRECTORIES set is joined directly to build _SYSTEM_DIRS_PATTERN. Because of Python's hash randomization, the order of elements in the resulting regex pattern will be non-deterministic across runs. Sort the set first using sorted() to ensure a deterministic regex pattern.
| _SYSTEM_DIRS_PATTERN = "|".join(SHELL_SYSTEM_DIRECTORIES) | |
| _SYSTEM_DIRS_PATTERN = "|".join(sorted(SHELL_SYSTEM_DIRECTORIES)) |
Greptile SummaryThis PR splits the old monolithic constants module into a package of focused constants files. The main changes are:
Confidence Score: 5/5Safe to merge with minimal risk. The change is a mechanical constants split with package-level re-exports preserving the existing public API. No functional, security, or compatibility issues were identified in the changed files. No files require special attention.
What T-Rex did
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Old[codebase_rag/constants.py] --> Split[constants package]
Split --> Init[constants/__init__.py compatibility facade]
Split --> Ast[ast_nodes.py]
Split --> Cli[cli.py]
Split --> Core[core.py]
Split --> Graph[graph.py]
Split --> Languages[languages.py]
Split --> Operators[operators.py]
Init --> PublicAPI[from codebase_rag.constants import X]
Init --> AliasAPI[from codebase_rag import constants as cs]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
Old[codebase_rag/constants.py] --> Split[constants package]
Split --> Init[constants/__init__.py compatibility facade]
Split --> Ast[ast_nodes.py]
Split --> Cli[cli.py]
Split --> Core[core.py]
Split --> Graph[graph.py]
Split --> Languages[languages.py]
Split --> Operators[operators.py]
Init --> PublicAPI[from codebase_rag.constants import X]
Init --> AliasAPI[from codebase_rag import constants as cs]
Reviews (1): Last reviewed commit: "refactor: split constants.py into consta..." | Re-trigger Greptile |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…tants-501-final # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Closes #501
Splits the 2876-line constants.py into a constants/ package
(ast_nodes, languages, operators, graph, cli, plus a core catch-all),
with init.py re-exporting every symbol for full backwards compatibility.
from codebase_rag.constants import X,from codebase_rag import constants,and the
csalias. Verified programmatically against the pre-split file.come from optional deps (torch/numpy/qdrant/clang/tree-sitter grammars)
not installed in a minimal venv — identical on untouched main.