Skip to content

Commit 143f18d

Browse files
committed
Merge remote-tracking branch 'origin/main' into existing-test-pr-comment
2 parents 587c80c + 681fa17 commit 143f18d

File tree

102 files changed

+3049
-2128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+3049
-2128
lines changed

.github/workflows/deploy-docs-to-azure.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/unit-tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ["3.9", "3.10", "3.11", "3.12"]
14+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1515
continue-on-error: true
1616
runs-on: ubuntu-latest
1717
steps:
@@ -30,4 +30,4 @@ jobs:
3030
run: uv sync
3131

3232
- name: Unit tests
33-
run: uv run pytest tests/ --benchmark-skip -m "not ci_skip"
33+
run: uv run pytest tests/

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.11.0"
4-
hooks:
5-
- id: ruff
6-
args: [--fix, --exit-non-zero-on-fix, --config=pyproject.toml]
7-
- id: ruff-format
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.12.7
4+
hooks:
5+
# Run the linter.
6+
- id: ruff-check
7+
# Run the formatter.
8+
- id: ruff-format

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ For detailed installation and usage instructions, visit our documentation at [do
6565

6666
https://github.com/user-attachments/assets/38f44f4e-be1c-4f84-8db9-63d5ee3e61e5
6767

68+
- Optiming a workflow end to end automatically with `codeflash optimize`
69+
70+
71+
https://github.com/user-attachments/assets/355ba295-eb5a-453a-8968-7fb35c70d16c
72+
73+
74+
6875
## Support
6976

7077
Join our community for support and discussions. If you have any questions, feel free to reach out to us using one of the following methods:

SECURITY.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Security Policy
2+
3+
This document outlines Codeflash's vulnerability disclosure policy. For more information about Codeflash's approach to security, please visit [codeflash.ai/security](https://www.codeflash.ai/security).
4+
5+
## Supported Versions
6+
7+
Since Codeflash is moving quickly, we can only commit to fixing security issues for the latest version of codeflash client.
8+
If a vulnerability is discovered in our backend, we will release the fix for all the users.
9+
10+
## Reporting a Vulnerability
11+
12+
13+
Please do not report security vulnerabilities through public GitHub issues.
14+
15+
Instead, please report them to our [GitHub Security page](https://github.com/codeflash-ai/codeflash/security). If you prefer to submit one without using GitHub, you can also email us at [email protected].
16+
17+
We commit to acknowledging vulnerability reports immediately, and will work to fix active vulnerabilities as soon as we can. We will publish resolved vulnerabilities in the form of security advisories on our GitHub security page. Critical incidents will be communicated both on the GitHub security page and via email to all affected users.
18+
19+
We appreciate your help in making Codeflash more secure for everyone. Thank you for your support and responsible disclosure.

WARP.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# WARP.md
2+
3+
This file provides guidance to WARP (warp.dev) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Codeflash is a general-purpose optimizer for Python that helps improve code performance while maintaining correctness. It uses advanced LLMs to generate optimization ideas, tests them for correctness, and benchmarks them for performance, then creates merge-ready pull requests.
8+
9+
## Development Environment Setup
10+
11+
### Prerequisites
12+
- Python 3.9+ (project uses uv for dependency management)
13+
- Git (for version control and PR creation)
14+
- Codeflash API key (for AI services)
15+
16+
### Initial Setup
17+
```bash
18+
# Install dependencies using uv (preferred over pip)
19+
uv sync
20+
21+
# Initialize codeflash configuration
22+
uv run codeflash init
23+
```
24+
25+
## Core Development Commands
26+
27+
### Code Quality & Linting
28+
```bash
29+
# Format code with ruff (includes check and format)
30+
uv run ruff check --fix codeflash/
31+
uv run ruff format codeflash/
32+
33+
# Type checking with mypy
34+
uv run mypy codeflash/
35+
36+
# Pre-commit hooks (ruff check + format)
37+
uv run pre-commit run --all-files
38+
```
39+
40+
### Testing
41+
```bash
42+
# Run all tests
43+
uv run pytest
44+
45+
# Run specific test file
46+
uv run pytest tests/test_specific_file.py
47+
48+
# Run tests matching pattern
49+
uv run pytest -k "pattern"
50+
51+
```
52+
53+
### Running Codeflash
54+
```bash
55+
# Optimize entire codebase
56+
uv run codeflash --all
57+
58+
# Optimize specific file
59+
uv run codeflash --file path/to/file.py
60+
61+
# Optimize specific function
62+
uv run codeflash --function "module.function"
63+
64+
# Optimize a script end-to-end
65+
uv run codeflash optimize script.py
66+
67+
# Run with benchmarking
68+
uv run codeflash --benchmark
69+
70+
# Verify setup
71+
uv run codeflash --verify-setup
72+
```
73+
74+
## Architecture Overview
75+
76+
### Main Components
77+
78+
**Core Modules:**
79+
- `codeflash/main.py` - CLI entry point and command coordination
80+
- `codeflash/cli_cmds/` - Command-line interface implementations
81+
- `codeflash/optimization/` - Core optimization engine and algorithms
82+
- `codeflash/verification/` - Code correctness verification
83+
- `codeflash/benchmarking/` - Performance measurement and comparison
84+
- `codeflash/discovery/` - Code analysis and function discovery
85+
- `codeflash/tracing/` - Runtime tracing and profiling
86+
- `codeflash/context/` - Code context extraction and analysis
87+
- `codeflash/result/` - Result processing, PR creation, and explanations
88+
89+
**Supporting Systems:**
90+
- `codeflash/api/` - Backend API communication
91+
- `codeflash/github/` - GitHub integration for PR creation
92+
- `codeflash/models/` - Data models and schemas
93+
- `codeflash/telemetry/` - Analytics and error reporting
94+
- `codeflash/code_utils/` - Code parsing, formatting, and manipulation utilities
95+
96+
### Key Workflows
97+
98+
1. **Code Discovery**: Analyzes codebase to identify optimization candidates
99+
2. **Context Extraction**: Extracts relevant code context and dependencies
100+
3. **Optimization Generation**: Uses LLMs to generate optimization candidates
101+
4. **Verification**: Tests optimizations for correctness using existing tests
102+
5. **Benchmarking**: Measures performance improvements
103+
6. **Result Processing**: Creates explanations and pull requests
104+
105+
### Configuration
106+
107+
Configuration is stored in `pyproject.toml` under `[tool.codeflash]`:
108+
- `module-root` - Source code location (default: "codeflash")
109+
- `tests-root` - Test location (default: "tests")
110+
- `benchmarks-root` - Benchmark location (default: "tests/benchmarks")
111+
- `test-framework` - Testing framework ("pytest" or "unittest")
112+
- `formatter-cmds` - Commands for code formatting
113+
114+
## Project Structure
115+
116+
```
117+
codeflash/
118+
├── api/ # Backend API communication
119+
├── benchmarking/ # Performance measurement
120+
├── cli_cmds/ # CLI command implementations
121+
├── code_utils/ # Code analysis and manipulation
122+
├── context/ # Code context extraction
123+
├── discovery/ # Function and test discovery
124+
├── github/ # GitHub API integration
125+
├── lsp/ # Language server protocol support
126+
├── models/ # Data models and schemas
127+
├── optimization/ # Core optimization engine
128+
├── result/ # Result processing and PR creation
129+
├── telemetry/ # Analytics and monitoring
130+
├── tracing/ # Runtime tracing and profiling
131+
├── verification/ # Correctness verification
132+
└── main.py # CLI entry point
133+
134+
tests/ # Test suite
135+
├── benchmarks/ # Performance benchmarks
136+
└── scripts/ # Test utilities
137+
138+
docs/ # Documentation
139+
code_to_optimize/ # Example code for optimization
140+
codeflash-benchmark/ # Benchmark workspace member
141+
```
142+
143+
## Development Notes
144+
145+
### Code Style
146+
- Uses ruff for linting and formatting (configured in pyproject.toml)
147+
- Strict mypy type checking enabled
148+
- Pre-commit hooks enforce code quality
149+
150+
### Testing
151+
- pytest-based test suite with extensive coverage
152+
- Parameterized tests for multiple scenarios
153+
- Benchmarking tests for performance validation
154+
- Test discovery supports both pytest and unittest frameworks
155+
156+
### Workspace Structure
157+
- Uses uv workspace with `codeflash-benchmark` as a member
158+
- Dependencies managed through uv.lock
159+
- Dynamic versioning from git tags using uv-dynamic-versioning
160+
161+
### Build & Distribution
162+
- Uses hatchling as build backend
163+
- BSL-1.1 license
164+
- Excludes development files from distribution packages
165+
166+
### CI/CD Integration
167+
- GitHub Actions workflow for automatic optimization of PR code
168+
- Pre-commit hooks for code quality enforcement
169+
- Automated testing and benchmarking
170+
171+
## Important Patterns
172+
173+
### Error Handling
174+
- Uses `either.py` for functional error handling patterns
175+
- Comprehensive error tracking through Sentry integration
176+
- Graceful degradation when AI services are unavailable
177+
178+
### Instrumentation
179+
- Extensive tracing capabilities for performance analysis
180+
- Line profiler integration for detailed performance metrics
181+
- Custom tracer implementation for code execution analysis
182+
183+
### AI Integration
184+
- Structured prompts and response handling for LLM interactions
185+
- Critic module for evaluating optimization quality
186+
- Context-aware code generation and explanation
187+
188+
### Git Integration
189+
- GitPython for repository operations
190+
- Automated PR creation with detailed explanations
191+
- Branch management for optimization experiments
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
DEFAULT_API_URL = "https://api.galileo.ai/"
22
DEFAULT_APP_URL = "https://app.galileo.ai/"
3-
4-
5-
# function_names: GalileoApiClient.get_console_url
6-
# module_abs_path : /home/mohammed/Work/galileo-python/src/galileo/api_client.py
7-
# preexisting_objects: {('GalileoApiClient', ()), ('_set_destination', ()), ('get_console_url', (FunctionParent(name='GalileoApiClient', type='ClassDef'),))}
8-
# project_root_path: /home/mohammed/Work/galileo-python/src
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""CodeFlash Benchmark - Pytest benchmarking plugin for codeflash.ai."""
2+
3+
__version__ = "0.1.0"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from __future__ import annotations
2+
3+
import importlib.util
4+
5+
import pytest
6+
7+
from codeflash.benchmarking.plugin.plugin import codeflash_benchmark_plugin
8+
9+
PYTEST_BENCHMARK_INSTALLED = importlib.util.find_spec("pytest_benchmark") is not None
10+
11+
benchmark_options = [
12+
("--benchmark-columns", "store", None, "Benchmark columns"),
13+
("--benchmark-group-by", "store", None, "Benchmark group by"),
14+
("--benchmark-name", "store", None, "Benchmark name pattern"),
15+
("--benchmark-sort", "store", None, "Benchmark sort column"),
16+
("--benchmark-json", "store", None, "Benchmark JSON output file"),
17+
("--benchmark-save", "store", None, "Benchmark save name"),
18+
("--benchmark-warmup", "store", None, "Benchmark warmup"),
19+
("--benchmark-warmup-iterations", "store", None, "Benchmark warmup iterations"),
20+
("--benchmark-min-time", "store", None, "Benchmark minimum time"),
21+
("--benchmark-max-time", "store", None, "Benchmark maximum time"),
22+
("--benchmark-min-rounds", "store", None, "Benchmark minimum rounds"),
23+
("--benchmark-timer", "store", None, "Benchmark timer"),
24+
("--benchmark-calibration-precision", "store", None, "Benchmark calibration precision"),
25+
("--benchmark-disable", "store_true", False, "Disable benchmarks"),
26+
("--benchmark-skip", "store_true", False, "Skip benchmarks"),
27+
("--benchmark-only", "store_true", False, "Only run benchmarks"),
28+
("--benchmark-verbose", "store_true", False, "Verbose benchmark output"),
29+
("--benchmark-histogram", "store", None, "Benchmark histogram"),
30+
("--benchmark-compare", "store", None, "Benchmark compare"),
31+
("--benchmark-compare-fail", "store", None, "Benchmark compare fail threshold"),
32+
]
33+
34+
35+
def pytest_configure(config: pytest.Config) -> None:
36+
"""Register the benchmark marker and disable conflicting plugins."""
37+
config.addinivalue_line("markers", "benchmark: mark test as a benchmark that should be run with codeflash tracing")
38+
39+
if config.getoption("--codeflash-trace"):
40+
# When --codeflash-trace is used, ignore all benchmark options by resetting them to defaults
41+
for option, _, default, _ in benchmark_options:
42+
option_name = option.replace("--", "").replace("-", "_")
43+
if hasattr(config.option, option_name):
44+
setattr(config.option, option_name, default)
45+
46+
if PYTEST_BENCHMARK_INSTALLED:
47+
config.pluginmanager.set_blocked("pytest_benchmark")
48+
config.pluginmanager.set_blocked("pytest-benchmark")
49+
50+
51+
def pytest_addoption(parser: pytest.Parser) -> None:
52+
parser.addoption(
53+
"--codeflash-trace", action="store_true", default=False, help="Enable CodeFlash tracing for benchmarks"
54+
)
55+
# These options are ignored when --codeflash-trace is used
56+
for option, action, default, help_text in benchmark_options:
57+
help_suffix = " (ignored when --codeflash-trace is used)"
58+
parser.addoption(option, action=action, default=default, help=help_text + help_suffix)
59+
60+
61+
@pytest.fixture
62+
def benchmark(request: pytest.FixtureRequest) -> object:
63+
"""Benchmark fixture that works with or without pytest-benchmark installed."""
64+
config = request.config
65+
66+
# If --codeflash-trace is enabled, use our implementation
67+
if config.getoption("--codeflash-trace"):
68+
return codeflash_benchmark_plugin.Benchmark(request)
69+
70+
# If pytest-benchmark is installed and --codeflash-trace is not enabled,
71+
# return the normal pytest-benchmark fixture
72+
if PYTEST_BENCHMARK_INSTALLED:
73+
from pytest_benchmark.fixture import BenchmarkFixture as BSF # pyright: ignore[reportMissingImports] # noqa: I001, N814
74+
75+
bs = getattr(config, "_benchmarksession", None)
76+
if bs and bs.skip:
77+
pytest.skip("Benchmarks are skipped (--benchmark-skip was used).")
78+
79+
node = request.node
80+
marker = node.get_closest_marker("benchmark")
81+
options = dict(marker.kwargs) if marker else {}
82+
83+
if bs:
84+
return BSF(
85+
node,
86+
add_stats=bs.benchmarks.append,
87+
logger=bs.logger,
88+
warner=request.node.warn,
89+
disabled=bs.disabled,
90+
**dict(bs.options, **options),
91+
)
92+
return lambda func, *args, **kwargs: func(*args, **kwargs)
93+
94+
return lambda func, *args, **kwargs: func(*args, **kwargs)

0 commit comments

Comments
 (0)