Skip to content

Commit 119e8ec

Browse files
authored
Merge branch 'main' into test_cache_revival
2 parents 924de86 + 1f31b08 commit 119e8ec

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,30 @@ def ask_run_end_to_end_test(args: Namespace) -> None:
155155
run_end_to_end_test(args, bubble_sort_path, bubble_sort_test_path)
156156

157157

158-
def is_valid_pyproject_toml(pyproject_toml_path: Path) -> dict[str, Any] | None:
158+
def is_valid_pyproject_toml(pyproject_toml_path: Path) -> tuple[dict[str, Any] | None, str]: # noqa: PLR0911
159159
if not pyproject_toml_path.exists():
160-
return None
160+
return None, f"Configuration file not found: {pyproject_toml_path}"
161+
161162
try:
162163
config, _ = parse_config_file(pyproject_toml_path)
163-
except Exception:
164-
return None
164+
except Exception as e:
165+
return None, f"Failed to parse configuration: {e}"
166+
167+
module_root = config.get("module_root")
168+
if not module_root:
169+
return None, "Missing required field: 'module_root'"
170+
171+
if not Path(module_root).is_dir():
172+
return None, f"Invalid 'module_root': directory does not exist at {module_root}"
173+
174+
tests_root = config.get("tests_root")
175+
if not tests_root:
176+
return None, "Missing required field: 'tests_root'"
165177

166-
if "module_root" not in config or config["module_root"] is None or not Path(config["module_root"]).is_dir():
167-
return None
168-
if "tests_root" not in config or config["tests_root"] is None or not Path(config["tests_root"]).is_dir():
169-
return None
178+
if not Path(tests_root).is_dir():
179+
return None, f"Invalid 'tests_root': directory does not exist at {tests_root}"
170180

171-
return config
181+
return config, ""
172182

173183

174184
def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]:
@@ -180,7 +190,7 @@ def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]:
180190

181191
pyproject_toml_path = Path.cwd() / "pyproject.toml"
182192

183-
config = is_valid_pyproject_toml(pyproject_toml_path)
193+
config, _message = is_valid_pyproject_toml(pyproject_toml_path)
184194
if config is None:
185195
return True, None
186196

@@ -631,7 +641,7 @@ def check_for_toml_or_setup_file() -> str | None:
631641

632642
def install_github_actions(override_formatter_check: bool = False) -> None: # noqa: FBT001, FBT002
633643
try:
634-
config, config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
644+
config, _config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
635645

636646
ph("cli-github-actions-install-started")
637647
try:

codeflash/lsp/beta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams)
191191
}
192192

193193
server.show_message_log("Validating project...", "Info")
194-
config = is_valid_pyproject_toml(pyproject_toml_path)
194+
config, reason = is_valid_pyproject_toml(pyproject_toml_path)
195195
if config is None:
196196
server.show_message_log("pyproject.toml is not valid", "Error")
197-
return {"status": "error", "message": "not valid", "pyprojectPath": pyproject_toml_path}
197+
return {"status": "error", "message": f"reason: {reason}", "pyprojectPath": pyproject_toml_path}
198198

199199
args = process_args(server)
200200

docs/optimizing-with-codeflash/codeflash-github-actions.mdx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ icon: "github"
55
---
66

77

8-
Optimizing new code in Pull Requests is the best way to ensure that all code you and your team ship is performant
9-
in the future. Automating optimization in the Pull Request stage how most teams use Codeflash, to
8+
Optimizing new code in Pull Requests is the best way to ensure that all code you and your team ship is always performant.
9+
Automating optimization in the Pull Request stage is how most teams use Codeflash, to
1010
continuously find optimizations for their new code.
1111

1212
To scan new code for performance optimizations, Codeflash uses a GitHub Action workflow which runs
1313
the Codeflash optimization logic on the new code in every pull request.
1414
If the action workflow finds an optimization, it communicates with the Codeflash GitHub
1515
App and asks it to suggest new changes to the pull request.
1616

17-
This is the most useful way of using Codeflash, where you set it up once and all your new code gets optimized.
18-
So setting this up is highly recommended.
17+
We highly recommend setting this up, since once you set it up all your new code gets optimized.
1918

2019
## Pull Request Optimization 30 seconds demo
2120
<iframe width="640" height="400" src="https://www.youtube.com/embed/nqa-uewizkU?si=H1wb1RvPp-JqvKPh" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
@@ -68,8 +67,15 @@ name: Codeflash
6867

6968
on:
7069
pull_request:
70+
paths:
71+
- '**' # Modify this to the path of your project in a mono-repo. Codeflash will only run when code in this directory is modified.
7172
workflow_dispatch:
7273

74+
concurrency:
75+
# Any new push to the PR will cancel the previous run, so that only the latest code is optimized
76+
group: ${{ github.workflow }}-${{ github.ref }}
77+
cancel-in-progress: true
78+
7379
jobs:
7480
optimize:
7581
name: Optimize new code in this PR
@@ -103,11 +109,17 @@ jobs:
103109
<Warning>
104110
**Replace the TODOs** in the workflow file above with your project's specific setup commands.
105111
</Warning>
112+
Set the `working-directory` parameter in the yaml file, if the commands are meant to be run from some other directory.
106113
</Step>
107114

108115
<Step title="Choose Your Package Manager">
109116
Customize the dependency installation based on your Python package manager:
110117

118+
The workflow will need to be set up in such a way the Codeflash can create and
119+
run tests for functionality and speed, so the stock YAML may need to be altered to
120+
suit the specific codebase. Typically the setup steps for a unit test workflow can
121+
be copied.
122+
111123
<CodeGroup>
112124
```yaml Poetry
113125
- name: Install Project Dependencies

0 commit comments

Comments
 (0)