Skip to content

Commit dab542b

Browse files
refactoring
1 parent ed48d83 commit dab542b

13 files changed

Lines changed: 2452 additions & 1129 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
poetry.lock
12
examples/reproduction/*
23
examples/output/*
34
bdd_output/*

Makefile

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
.PHONY: help install install-dev install-full clean build test lint format typecheck publish publish-test docs docker
22

3+
POETRY := $(shell command -v poetry 2>/dev/null)
4+
ifeq ($(POETRY),)
5+
RUN :=
36
PYTHON := python3
47
PIP := pip
8+
else
9+
RUN := poetry run
10+
PYTHON := $(RUN) python
11+
PIP :=
12+
endif
513

614
# Colors for terminal output
715
BLUE := \033[34m
@@ -20,19 +28,39 @@ help: ## Show this help message
2028
# ============================================================================
2129

2230
install: ## Install package (minimal)
23-
$(PIP) install -e .
31+
@if [ -n "$(POETRY)" ]; then \
32+
poetry install; \
33+
else \
34+
$(PIP) install -e .; \
35+
fi
2436

2537
install-dev: ## Install with development dependencies
26-
$(PIP) install -e ".[dev]"
38+
@if [ -n "$(POETRY)" ]; then \
39+
poetry install --with dev; \
40+
else \
41+
$(PIP) install -e ".[dev]"; \
42+
fi
2743

2844
install-full: ## Install with all features
29-
$(PIP) install -e ".[full,dev]"
45+
@if [ -n "$(POETRY)" ]; then \
46+
poetry install --with dev -E full; \
47+
else \
48+
$(PIP) install -e ".[full,dev]"; \
49+
fi
3050

3151
install-docs: ## Install documentation dependencies
32-
$(PIP) install -e ".[docs]"
52+
@if [ -n "$(POETRY)" ]; then \
53+
poetry install --with docs; \
54+
else \
55+
$(PIP) install -e ".[docs]"; \
56+
fi
3357

3458
install-llm: ## Install LLM integration dependencies
35-
$(PIP) install httpx litellm python-dotenv
59+
@if [ -n "$(POETRY)" ]; then \
60+
poetry install -E llm; \
61+
else \
62+
$(PIP) install httpx litellm python-dotenv; \
63+
fi
3664

3765
# ============================================================================
3866
# Configuration
@@ -65,36 +93,36 @@ config-check: ## Check which providers are configured
6593
# ============================================================================
6694

6795
test: ## Run tests
68-
pytest tests/ -v -p no:aiohttp
96+
$(RUN) pytest tests/ -v -p no:aiohttp
6997

7098
test-cov: ## Run tests with coverage
71-
pytest tests/ -v -p no:aiohttp --cov=code2logic --cov-report=term-missing --cov-report=html
99+
$(RUN) pytest tests/ -v -p no:aiohttp --cov=code2logic --cov-report=term-missing --cov-report=html
72100

73101
test-fast: ## Run tests without coverage (faster)
74-
pytest tests/ -v -p no:aiohttp --no-cov
102+
$(RUN) pytest tests/ -v -p no:aiohttp --no-cov
75103

76104
test-all: ## Run all tests including integration
77-
pytest tests/ -v -p no:aiohttp --cov=code2logic
105+
$(RUN) pytest tests/ -v -p no:aiohttp --cov=code2logic
78106
@echo "$(GREEN)All tests passed!$(NC)"
79107

80108
# ============================================================================
81109
# Code Quality
82110
# ============================================================================
83111

84112
lint: ## Run linters
85-
ruff check code2logic tests
113+
$(RUN) ruff check code2logic tests
86114

87115
lint-fix: ## Run linters and fix issues
88-
ruff check code2logic tests --fix
116+
$(RUN) ruff check code2logic tests --fix
89117

90118
format: ## Format code with black
91-
black code2logic tests
119+
$(RUN) black code2logic tests
92120

93121
format-check: ## Check code formatting
94-
black code2logic tests --check
122+
$(RUN) black code2logic tests --check
95123

96124
typecheck: ## Run type checking
97-
mypy code2logic --ignore-missing-imports
125+
$(RUN) mypy code2logic --ignore-missing-imports
98126

99127
quality: lint format-check typecheck ## Run all quality checks
100128

@@ -116,7 +144,11 @@ clean: ## Clean build artifacts
116144
find . -type f -name "*.pyc" -delete
117145

118146
build: clean ## Build package
119-
$(PYTHON) -m build
147+
@if [ -n "$(POETRY)" ]; then \
148+
poetry build; \
149+
else \
150+
$(PYTHON) -m build; \
151+
fi
120152
@echo "$(GREEN)Build complete!$(NC)"
121153
@ls -lh dist/
122154

code2logic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
>>> print(output)
1919
"""
2020

21-
__version__ = "1.0.7"
21+
__version__ = "1.0.8"
2222
__author__ = "Softreck"
2323
__email__ = "info@softreck.dev"
2424
__license__ = "MIT"

code2logic/generators.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ def generate_hybrid(self, project: ProjectInfo, detail: str = 'standard') -> str
10041004
# Build detailed module data with enhanced information
10051005
detailed_modules = []
10061006
for m in project.modules:
1007+
file_kb = bytes_to_kb(getattr(m, 'file_bytes', 0))
10071008
mod_data = {
10081009
'p': m.path, # path
10091010
}
@@ -1033,17 +1034,10 @@ def generate_hybrid(self, project: ProjectInfo, detail: str = 'standard') -> str
10331034
for const in m.constants:
10341035
if isinstance(const, str):
10351036
# Handle string constants (from UniversalParser)
1036-
const_dict = {'n': const}
1037+
const_data.append({'n': const})
10371038
else:
10381039
# Handle ConstantInfo objects (from TreeSitter parser)
1039-
const_dict = {'n': const.name}
1040-
if const.type_annotation:
1041-
const_dict['t'] = const.type_annotation
1042-
if const.value_keys: # For dicts, show keys
1043-
const_dict['keys'] = const.value_keys[:10]
1044-
elif const.value and len(const.value) <= 100: # For small values
1045-
const_dict['v'] = const.value
1046-
const_data.append(const_dict)
1040+
const_data.append(self._constant_to_dict(const))
10471041
if const_data:
10481042
mod_data['const'] = const_data
10491043

@@ -1776,7 +1770,9 @@ def _build_compact_signature(self, f: FunctionInfo) -> str:
17761770
if len(f.params) > 6:
17771771
params += f', ...+{len(f.params)-6}'
17781772

1779-
return params if params else ''
1773+
if params:
1774+
return f"({params})"
1775+
return "()"
17801776

17811777
def _constants_for_module(self, module: ModuleInfo, limit: int = 10) -> list:
17821778
"""Convert module constants into compact dictionaries."""

code2logic/toon_format.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ def _generate_modules(self, modules: List[ModuleInfo], detail: str) -> List[str]
8585
lines = []
8686

8787
# Module summary as tabular array
88-
lines.append(f"modules[{len(modules)}]{{path{self.delim_marker}lang{self.delim_marker}lines}}:")
88+
lines.append(f"modules[{len(modules)}]{{path{self.delim_marker}lang{self.delim_marker}lines{self.delim_marker}kb}}:")
8989
for m in modules:
9090
path = self._quote(m.path)
91-
lines.append(f" {path}{self.delimiter}{m.language}{self.delimiter}{m.lines_code}")
91+
kb = round((getattr(m, 'file_bytes', 0) or 0) / 1024, 1)
92+
lines.append(f" {path}{self.delimiter}{m.language}{self.delimiter}{m.lines_code}{self.delimiter}{kb}")
9293

9394
# Detailed module info
9495
if detail in ('standard', 'full'):
@@ -107,6 +108,38 @@ def _generate_modules(self, modules: List[ModuleInfo], detail: str) -> List[str]
107108
if m.exports:
108109
exports_str = self.delimiter.join(self._quote(x) for x in m.exports[:10])
109110
lines.append(f" exports[{len(m.exports)}]: {exports_str}")
111+
112+
# ENHANCED: Add constants with values/keys (critical for reproduction)
113+
constants_attr = getattr(m, 'constants', []) or []
114+
const_rows = []
115+
for c in constants_attr:
116+
if isinstance(c, str):
117+
if c.startswith('conditional:'):
118+
continue
119+
const_rows.append({'n': c, 't': '-', 'v': '-', 'keys': '-'})
120+
else:
121+
keys = getattr(c, 'value_keys', None) or []
122+
v = getattr(c, 'value', None)
123+
t = getattr(c, 'type_annotation', '') or '-'
124+
if keys:
125+
const_rows.append({'n': c.name, 't': t, 'v': '-', 'keys': '|'.join(keys[:10])})
126+
elif v:
127+
v_snip = v.replace('\n', ' ').strip()
128+
if len(v_snip) > 120:
129+
v_snip = v_snip[:117] + '...'
130+
const_rows.append({'n': c.name, 't': t, 'v': v_snip, 'keys': '-'})
131+
else:
132+
const_rows.append({'n': c.name, 't': t, 'v': '-', 'keys': '-'})
133+
if len(const_rows) >= 8:
134+
break
135+
136+
if const_rows:
137+
header = f"n{self.delim_marker}t{self.delim_marker}v{self.delim_marker}keys"
138+
lines.append(f" const[{len(const_rows)}]{{{header}}}:")
139+
for r in const_rows:
140+
lines.append(
141+
f" {self._quote(r['n'])}{self.delimiter}{self._quote(r['t'])}{self.delimiter}{self._quote(r['v'])}{self.delimiter}{self._quote(r['keys'])}"
142+
)
110143

111144
# Classes
112145
if m.classes:
@@ -152,6 +185,19 @@ def _generate_classes(self, classes: List[ClassInfo], detail: str, indent: int =
152185
if c.properties:
153186
props_str = self.delimiter.join(self._quote(x) for x in c.properties[:10])
154187
lines.append(f"{ind} properties[{len(c.properties)}]: {props_str}")
188+
189+
# ENHANCED: Dataclass fields
190+
if getattr(c, 'is_dataclass', False) and getattr(c, 'fields', None):
191+
fields = c.fields[:20]
192+
header = f"n{self.delim_marker}t{self.delim_marker}default{self.delim_marker}factory"
193+
lines.append(f"{ind} fields[{len(fields)}]{{{header}}}:")
194+
for f in fields:
195+
t = getattr(f, 'type_annotation', '') or '-'
196+
dflt = getattr(f, 'default', None) or '-'
197+
fac = getattr(f, 'default_factory', None) or '-'
198+
lines.append(
199+
f"{ind} {self._quote(f.name)}{self.delimiter}{self._quote(t)}{self.delimiter}{self._quote(dflt)}{self.delimiter}{self._quote(fac)}"
200+
)
155201

156202
# Methods with full details
157203
if c.methods:

examples/duplicate_detection.py

Whitespace-only changes.

examples/token_efficiency.py

Whitespace-only changes.

0 commit comments

Comments
 (0)