orchestrata_tools.context.config_collector
Reference › orchestrata_tools › context › config_collector
This module reads a project's build and tooling configuration for the LLM context in project_context. ConfigCollector is built over a project root, and collect returns a ConfigContext. When pyproject.toml exists it is parsed with tomllib, giving the required Python version, runtime dependencies, the dev or test optional dependencies, project scripts, and the build backend. The test framework, linter and formatter are recorded as pytest, ruff or black when the matching tool table is present. If the file is missing or cannot be parsed, those fields stay empty without an error. When no dependencies came from pyproject.toml, a requirements.txt is read, skipping blank and comment lines.
At a glance
| Source | src/orchestrata_tools/context/config_collector.py |
| Lines of code | 76 |
| Classes | 2 |
| Functions | 0 |
| Imports (internal) | none |
| Imported by | orchestrata_tools.context.project_context |
| Tests that import it | tests/test_orchestrata_tools.py |
Class diagram
Dependency diagram
API
Classes
ConfigContext (dataclass)
Decorators: dataclass · Line 10
Collected project configuration.
| Attribute | Type | Default |
|---|---|---|
build_system |
str |
'' |
python_version |
str |
'' |
dependencies |
list[str] |
field(default_factory=list) |
dev_dependencies |
list[str] |
field(default_factory=list) |
scripts |
dict[str, str] |
field(default_factory=dict) |
test_framework |
str |
'' |
linter |
str |
'' |
formatter |
str |
'' |
ConfigCollector
Line 23
Collect project configuration from pyproject.toml, setup.py, etc.
| Method | Signature | Summary |
|---|---|---|
__init__ |
__init__(root_path: str | Path) |
|
collect |
collect() -> ConfigContext |
Source
"""Collect project configuration files for LLM context."""
from __future__ import annotations
from dataclasses import dataclass, field
from pathlib import Path
@dataclass
class ConfigContext:
"""Collected project configuration."""
build_system: str = ""
python_version: str = ""
dependencies: list[str] = field(default_factory=list)
dev_dependencies: list[str] = field(default_factory=list)
scripts: dict[str, str] = field(default_factory=dict)
test_framework: str = ""
linter: str = ""
formatter: str = ""
class ConfigCollector:
"""Collect project configuration from pyproject.toml, setup.py, etc."""
def __init__(self, root_path: str | Path):
self.root = Path(root_path)
def collect(self) -> ConfigContext:
ctx = ConfigContext()
pyproject = self.root / "pyproject.toml"
if pyproject.exists():
try:
import tomllib
with open(pyproject, "rb") as f:
data = tomllib.load(f)
project = data.get("project", {})
ctx.python_version = project.get("requires-python", "")
deps = project.get("dependencies", [])
ctx.dependencies = [str(d) for d in deps]
optional = project.get("optional-dependencies", {})
dev_deps = optional.get("dev", optional.get("test", []))
ctx.dev_dependencies = [str(d) for d in dev_deps]
ctx.scripts = {k: str(v) for k, v in project.get("scripts", {}).items()}
build = data.get("build-system", {})
ctx.build_system = build.get("build-backend", "")
# Tool config
tools = data.get("tool", {})
if "pytest" in tools:
ctx.test_framework = "pytest"
if "ruff" in tools:
ctx.linter = "ruff"
if "black" in tools:
ctx.formatter = "black"
except Exception:
pass
# Fallback: requirements.txt
req_file = self.root / "requirements.txt"
if req_file.exists() and not ctx.dependencies:
with open(req_file) as f:
ctx.dependencies = [
line.strip()
for line in f
if line.strip() and not line.startswith("#")
]
return ctx