Skip to content

refactor: split constants.py into constants/ submodule (#501)#641

Open
ChetanyaRathi wants to merge 2 commits into
vitali87:mainfrom
ChetanyaRathi:refactor/split-constants-501-final
Open

refactor: split constants.py into constants/ submodule (#501)#641
ChetanyaRathi wants to merge 2 commits into
vitali87:mainfrom
ChetanyaRathi:refactor/split-constants-501-final

Conversation

@ChetanyaRathi

Copy link
Copy Markdown
Contributor

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.

  • Zero API changes: all 1480 public symbols remain importable via
    from codebase_rag.constants import X, from codebase_rag import constants,
    and the cs alias. Verified programmatically against the pre-split file.
  • ruff check + format pass.
  • The remaining ty/pytest failures on my machine are pre-existing and
    come from optional deps (torch/numpy/qdrant/clang/tree-sitter grammars)
    not installed in a minimal venv — identical on untouched main.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +107 to +112
_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."
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
_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
  1. 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.

Comment thread codebase_rag/constants/cli.py Outdated
)

# (H) Build system directory regex pattern dynamically
_SYSTEM_DIRS_PATTERN = "|".join(SHELL_SYSTEM_DIRECTORIES)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
_SYSTEM_DIRS_PATTERN = "|".join(SHELL_SYSTEM_DIRECTORIES)
_SYSTEM_DIRS_PATTERN = "|".join(sorted(SHELL_SYSTEM_DIRECTORIES))

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR splits the old monolithic constants module into a package of focused constants files. The main changes are:

  • codebase_rag.constants now re-exports the split symbols for compatibility.
  • AST, CLI, graph, language, operator, and core constants are grouped into separate submodules.
  • Existing imports such as from codebase_rag.constants import X and from codebase_rag import constants as cs remain supported.

Confidence Score: 5/5

Safe 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.

T-Rex T-Rex Logs

What T-Rex did

  • The team validated current-head compatibility for the constants API and confirmed the imports succeed with public_count 1492, same_module True, representative symbols imported, and submodule identity checks passing.
  • The team compared base-head symbols against the SHA 723bfe4 and confirmed missing_in_head_count is 0 with a successful exit.
  • A Ruff lint check was run on the codebase_rag/constants folder and all checks passed with exit code 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
codebase_rag/constants/init.py Adds the package-level compatibility facade that re-exports constants split across submodules; no blocking issues found.
codebase_rag/constants/ast_nodes.py Moves AST, tree-sitter, capture, and parser-loader constants into a focused submodule; no blocking issues found.
codebase_rag/constants/cli.py Moves CLI, UI, shell-safety, and interactive prompt constants into a focused submodule; no blocking issues found.
codebase_rag/constants/core.py Retains the renamed core constants file while importing language enums needed by remaining derived constants; no blocking issues found.
codebase_rag/constants/graph.py Moves graph schema, Cypher, relationship, and node-label constants into a focused submodule; no blocking issues found.
codebase_rag/constants/languages.py Moves language metadata and extension constants into a focused submodule; no blocking issues found.
codebase_rag/constants/operators.py Moves dead-code/root-detection and operator-related constants into a focused submodule; no blocking issues found.

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]
Loading
%%{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]
Loading

Reviews (1): Last reviewed commit: "refactor: split constants.py into consta..." | Re-trigger Greptile

@codecov-commenter

codecov-commenter commented Jul 7, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 99.83526% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
codebase_rag/constants/graph.py 99.27% 1 Missing ⚠️

📢 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

refactor: split constants.py (2876 lines) into submodules

2 participants