Skip to content

Commit d659f7a

Browse files
committed
Algolio reability fix and document refinement
1 parent 20a5176 commit d659f7a

File tree

3 files changed

+132
-11
lines changed

3 files changed

+132
-11
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
from enum import Enum, auto
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any, Union, cast
10+
from typing import TYPE_CHECKING, Any, cast
1111

1212
import click
1313
import git
@@ -50,7 +50,7 @@
5050
class SetupInfo:
5151
module_root: str
5252
tests_root: str
53-
benchmarks_root: Union[str, None]
53+
benchmarks_root: str | None
5454
test_framework: str
5555
ignore_paths: list[str]
5656
formatter: str
@@ -750,7 +750,7 @@ def install_github_app() -> None:
750750

751751
else:
752752
click.prompt(
753-
f"Finally, you'll need install the Codeflash GitHub app by choosing the repository you want to install Codeflash on.{LF}"
753+
f"Finally, you'll need to install the Codeflash GitHub app by choosing the repository you want to install Codeflash on.{LF}"
754754
f"I will attempt to open the github app page - https://github.com/apps/codeflash-ai/installations/select_target {LF}"
755755
f"Press Enter to open the page to let you install the app…{LF}",
756756
default="",

docs/docs/getting-started/local-installation.md

Lines changed: 124 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ Codeflash is installed and configured on a per-project basis.
88

99
You can install Codeflash locally for a project by running the following command in the project's virtual environment:
1010

11+
### Prerequisites
12+
13+
Before installing Codeflash, ensure you have:
14+
15+
1. **Python 3.8 or higher** installed
16+
2. **A Python project** with a virtual environment
17+
3. **Project dependencies installed** in your virtual environment
18+
4. **Tests** (optional) for your code (Codeflash uses tests to verify optimizations)
19+
20+
:::important[Virtual Environment Required]
21+
Always install Codeflash in your project's virtual environment, not globally. Make sure your virtual environment is activated before proceeding.
22+
23+
```bash
24+
# Example: Activate your virtual environment
25+
source venv/bin/activate # On Linux/Mac
26+
# or
27+
venv\Scripts\activate # On Windows
28+
```
29+
:::
30+
### Step 1: Install Codeflash
1131
```bash
1232
pip install codeflash
1333
```
@@ -16,22 +36,39 @@ pip install codeflash
1636
We recommend installing Codeflash as a development dependency.
1737
It doesn't need to be installed as part of your package requirements.
1838
Codeflash is intended to be used locally and as part of development workflows such as CI.
39+
If using pyproject.toml:
40+
```toml
41+
[tool.poetry.dependencies.dev]
42+
codeflash = "^latest"
43+
```
44+
Or with pip:
45+
```bash
46+
pip install --dev codeflash
47+
````
1948
:::
2049

21-
## Generate a Codeflash API Key
50+
### Step 2: Generate a Codeflash API Key
2251

23-
Since Codeflash uses advanced Large Language Models (LLMs) that are hosted in the cloud, you will need to generate an API key to use Codeflash.
52+
Codeflash uses cloud-hosted AI models to optimize your code. You'll need an API key to use it.
2453
25-
To generate an API key, visit the [Codeflash Web App](https://app.codeflash.ai/) and sign up for an account with GitHub login.
54+
1. Visit the [Codeflash Web App](https://app.codeflash.ai/)
55+
2. Sign up with your GitHub account (free)
56+
3. Navigate to the [API Key](https://app.codeflash.ai/app/apikeys) page to generate your API key
2657
<!--- TODO: Do we ask for access to specific repositories here? --->
27-
Once you have signed up, you will be able to generate an API key from the [API Key](https://app.codeflash.ai/app/apikeys) page.
28-
You will need the API key in the next step.
2958
30-
## Automatic Configuration
59+
:::note[Free Tier Available]
60+
Codeflash offers a **free tier** with a limited number of optimizations per month. Perfect for trying it out or small projects!
61+
:::
62+
63+
### Step 3: Automatic Configuration
3164
32-
To configure Codeflash for a project, in the root directory of your project where your `pyproject.toml` file is located, run the following command :
65+
Navigate to your project's root directory (where your `pyproject.toml` file is or should be) and run:
3366

3467
```bash
68+
# Make sure you're in your project root
69+
cd /path/to/your/project
70+
71+
# Run the initialization
3572
codeflash init
3673
```
3774

@@ -56,11 +93,90 @@ After you have answered these questions, Codeflash will be configured for your p
5693
The configuration will be saved in the `pyproject.toml` file in the root directory of your project.
5794
To understand the configuration options, and set more advanced options, see the [Configuration](/configuration) page.
5895
59-
## Install the Codeflash GitHub App
96+
### Step 4: Install the Codeflash GitHub App
6097
98+
<!--- TODO: Justify to users Why we need the user to install Github App even in local Installation or local optimization? --->
6199
Finally, if you have not done so already, Codeflash will ask you to install the Github App in your repository. The Codeflash GitHub App allows access to your repository to the codeflash-ai bot to open PRs, review code, and provide optimization suggestions.
62100
63101
Please [install the Codeflash GitHub
64102
app](https://github.com/apps/codeflash-ai/installations/select_target) by choosing the repository you want to install
65103
Codeflash on.
66104
##
105+
106+
## Try It Out!
107+
108+
Once configured, you can start optimizing your code:
109+
110+
```bash
111+
# Optimize a specific function
112+
codeflash --file path/to/your/file.py --function function_name
113+
114+
# Or if want to optimize only locally without creating a PR
115+
codeflash --file path/to/your/file.py --function function_name --no-pr
116+
```
117+
118+
### Example Project
119+
120+
Want to see Codeflash in action? Check out our example repository:
121+
122+
🔗 [github.com/codeflash-ai/optimize-me](https://github.com/codeflash-ai/optimize-me)
123+
124+
This repo includes:
125+
- Sample Python code with performance issues
126+
- Tests for verification
127+
- Pre-configured `pyproject.toml`
128+
- Before/after optimization examples in PRs
129+
130+
Clone it and try running:
131+
```bash
132+
git clone https://github.com/codeflash-ai/optimize-me.git
133+
cd optimize-me
134+
python -m venv .venv
135+
source .venv/bin/activate # or venv\Scripts\activate on Windows
136+
pip install -r requirements.txt
137+
pip install codeflash
138+
codeflash init # Use your own API key
139+
codeflash --all # optimize the entire repo
140+
```
141+
142+
### 🔧 Troubleshooting
143+
144+
#### 📦 "Module not found" errors
145+
Make sure:
146+
- ✅ Your virtual environment is activated
147+
- ✅ All project dependencies are installed
148+
- ✅ You're running `codeflash` from your project root
149+
150+
#### 🧪 "No optimizations found" or debugging issues
151+
Use the `--verbose` flag for detailed output:
152+
```bash
153+
codeflash optimize --verbose
154+
```
155+
156+
This will show:
157+
- 🔍 Which functions are being analyzed
158+
- 🚫 Why certain functions were skipped
159+
- ⚠️ Detailed error messages
160+
- 📊 Performance analysis results
161+
162+
#### 🔍 "No tests found" errors
163+
Verify:
164+
- 📁 Your test directory path is correct in `pyproject.toml`
165+
- 🔍 Tests are discoverable by your test framework
166+
- 📝 Test files follow naming conventions (`test_*.py` for pytest)
167+
168+
#### ⚙️ Configuration issues
169+
Check your `pyproject.toml`:
170+
```toml
171+
[tool.codeflash]
172+
module = "my_package"
173+
test-framework = "pytest"
174+
tests = "tests/"
175+
```
176+
177+
### Next Steps
178+
179+
- Learn about [Codeflash Concepts](/codeflash-concepts/how-codeflash-works)
180+
- Explore [optimization workflows](/optimizing-with-codeflash/one-function)
181+
- Set up [GitHub Actions integration](/getting-started/codeflash-github-actions)
182+
- Read [configuration options](/configuration) for advanced setups

docs/src/css/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@
2828
--ifm-color-primary-lightest: #FFECB3;
2929
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
3030
}
31+
32+
[data-theme='dark'] {
33+
/* Attempt to override Algolia's own CSS variables for the selected item's background */
34+
--docsearch-highlight-color: #d08e0d !important;
35+
}

0 commit comments

Comments
 (0)