Skip to content

Commit 23f8cc0

Browse files
authored
ops: add a script to automatically check things before PR creation (#632)
1 parent 1cec966 commit 23f8cc0

File tree

23 files changed

+93
-71
lines changed

23 files changed

+93
-71
lines changed

check.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash -e
2+
3+
maturin develop
4+
mypy
5+
6+
cargo test
7+
pytest
8+
9+
cargo fmt
10+
ruff format
11+
12+
echo "All checks passed"

docs/docs/about/contributing.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,36 @@ Following the steps below to get cocoindex build on latest codebase locally - if
2626
- 🦀 [Install Rust](https://rust-lang.org/tools/install)
2727

2828
If you don't have Rust installed, run
29-
```bash
29+
```sh
3030
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
3131
```
3232
Already have Rust? Make sure it's up to date
33-
```bash
33+
```sh
3434
rustup update
3535
```
3636
37-
- (Recommended) Setup Python virtual environment:
38-
```bash
37+
- Setup Python virtual environment:
38+
```sh
3939
python3 -m venv .venv
4040
```
4141
Activate the virtual environment, before any installing / building / running:
4242
43-
```bash
43+
```sh
4444
. .venv/bin/activate
4545
```
4646
47-
- Install maturin:
48-
```bash
49-
pip install maturin
47+
- Install required tools:
48+
```sh
49+
pip install maturin mypy ruff
5050
```
5151
5252
- Build the library. Run at the root of cocoindex directory:
53-
```bash
53+
```sh
5454
maturin develop
5555
```
5656
57-
- (Optional) Before running a specific example, set extra environment variables, for exposing extra traces, allowing dev UI, etc.
58-
```bash
57+
- Before running a specific example, set extra environment variables, for exposing extra traces, allowing dev UI, etc.
58+
```sh
5959
. ./.env.lib_debug
6060
```
6161
@@ -67,7 +67,12 @@ To submit your code:
6767
1. Fork the [CocoIndex repository](https://github.com/cocoindex-io/cocoindex)
6868
2. [Create a new branch](https://docs.github.com/en/desktop/making-changes-in-a-branch/managing-branches-in-github-desktop) on your fork
6969
3. Make your changes
70-
4. [Open a Pull Request (PR)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) when your work is ready for review
70+
4. Make sure all tests and linting pass by running
71+
```sh
72+
./check.sh
73+
```
74+
75+
5. [Open a Pull Request (PR)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) when your work is ready for review
7176
7277
In your PR description, please include:
7378
- Description of the changes

src/builder/flow_builder.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,14 @@ impl FlowBuilder {
258258
#[new]
259259
pub fn new(name: &str) -> PyResult<Self> {
260260
let lib_context = get_lib_context().into_py_result()?;
261-
let existing_flow_ss = lib_context
262-
.persistence_ctx
263-
.as_ref()
264-
.and_then(|ctx| {
265-
ctx.all_setup_states
266-
.read()
267-
.unwrap()
268-
.flows
269-
.get(name)
270-
.cloned()
271-
});
261+
let existing_flow_ss = lib_context.persistence_ctx.as_ref().and_then(|ctx| {
262+
ctx.all_setup_states
263+
.read()
264+
.unwrap()
265+
.flows
266+
.get(name)
267+
.cloned()
268+
});
272269
let root_op_scope = OpScope::new(
273270
spec::ROOT_SCOPE_NAME.to_string(),
274271
None,

src/execution/db_tracking_setup.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ impl ResourceSetupStatus for TrackingTableSetupStatus {
154154
(None, None) => SetupChangeType::NoChange,
155155
}
156156
}
157-
158-
159157
}
160158

161159
impl TrackingTableSetupStatus {

src/execution/dumper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
2-
use futures::future::try_join_all;
32
use futures::StreamExt;
3+
use futures::future::try_join_all;
44
use indexmap::IndexMap;
55
use itertools::Itertools;
66
use serde::ser::SerializeSeq;

src/execution/live_updater.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ impl SharedAckFn {
5151
let ack_fn = {
5252
let mut v = v.lock().unwrap();
5353
v.count -= 1;
54-
if v.count > 0 {
55-
None
56-
} else {
57-
v.ack_fn.take()
58-
}
54+
if v.count > 0 { None } else { v.ack_fn.take() }
5955
};
6056
if let Some(ack_fn) = ack_fn {
6157
ack_fn().await?;
@@ -108,9 +104,7 @@ async fn update_source(
108104
} else {
109105
trace!(
110106
"{}.{}: {}",
111-
flow_ctx.flow.flow_instance.name,
112-
import_op.name,
113-
delta
107+
flow_ctx.flow.flow_instance.name, import_op.name, delta
114108
);
115109
}
116110
};
@@ -252,10 +246,16 @@ impl FlowLiveUpdater {
252246
while let Some(result) = self.tasks.join_next().await {
253247
match result {
254248
Err(e) if !e.is_cancelled() => {
255-
error!("A background task in FlowLiveUpdater failed to join: {:?}", e);
249+
error!(
250+
"A background task in FlowLiveUpdater failed to join: {:?}",
251+
e
252+
);
256253
}
257254
Ok(Err(e)) => {
258-
error!("Error reported by a source update task during live update: {:?}", e);
255+
error!(
256+
"Error reported by a source update task during live update: {:?}",
257+
e
258+
);
259259
}
260260
_ => {}
261261
}

src/execution/memoization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::{Result, bail};
22
use serde::{Deserialize, Serialize};
33
use std::{
44
borrow::Cow,

src/execution/source_indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::prelude::*;
22

33
use futures::future::Ready;
44
use sqlx::PgPool;
5-
use std::collections::{hash_map, HashMap};
5+
use std::collections::{HashMap, hash_map};
66
use tokio::{sync::Semaphore, task::JoinSet};
77

88
use super::{

src/lib_context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ impl LibContext {
110110
.ok_or_else(|| anyhow!("Database is required for this operation. Please set COCOINDEX_DATABASE_URL environment variable and call cocoindex.init() with database settings."))
111111
}
112112

113-
pub fn require_all_setup_states(&self) -> Result<&RwLock<setup::AllSetupState<setup::ExistingMode>>> {
113+
pub fn require_all_setup_states(
114+
&self,
115+
) -> Result<&RwLock<setup::AllSetupState<setup::ExistingMode>>> {
114116
self.persistence_ctx
115117
.as_ref()
116118
.map(|ctx| &ctx.all_setup_states)
@@ -149,7 +151,7 @@ pub fn create_lib_context(settings: settings::Settings) -> Result<LibContext> {
149151
// No database configured
150152
None
151153
};
152-
154+
153155
Ok(LibContext {
154156
db_pools,
155157
persistence_ctx,

src/llm/anthropic.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::llm::{
22
LlmGenerateRequest, LlmGenerateResponse, LlmGenerationClient, LlmSpec, OutputFormat,
33
ToJsonSchemaOptions,
44
};
5-
use anyhow::{bail, Context, Result};
5+
use anyhow::{Context, Result, bail};
66
use async_trait::async_trait;
77
use json5;
88
use serde_json::Value;
@@ -115,16 +115,20 @@ impl LlmGenerationClient for Client {
115115
Ok(value) => {
116116
println!("[Anthropic] Used permissive JSON5 parser for output");
117117
serde_json::to_string(&value)?
118-
},
119-
Err(e2) => return Err(anyhow::anyhow!(format!("No structured tool output or text found in response, and permissive JSON5 parsing also failed: {e}; {e2}")))
118+
}
119+
Err(e2) => {
120+
return Err(anyhow::anyhow!(format!(
121+
"No structured tool output or text found in response, and permissive JSON5 parsing also failed: {e}; {e2}"
122+
)));
123+
}
120124
}
121125
}
122126
}
123127
}
124128
_ => {
125129
return Err(anyhow::anyhow!(
126130
"No structured tool output or text found in response"
127-
))
131+
));
128132
}
129133
}
130134
};

0 commit comments

Comments
 (0)