Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint, build, and test commands to justfile, add fmt and clippy to CI workflow #59

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
name: CI

on:
pull_request: {}
push:
branches:
- main
workflow_dispatch: {}
pull_request: {}
push:
branches:
- main
workflow_dispatch: {}

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ matrix.rust }}
- name: Install protoc
uses: arduino/setup-protoc@v3
- name: Build SDK
run: cargo build
- name: Build documentation
run: cargo doc --no-deps
- name: Run tests
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }}
POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }}
COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }}
run: cargo test --verbose
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ matrix.rust }}
- name: Install protoc
uses: arduino/setup-protoc@v3
- name: Build SDK
run: cargo build
- name: Build documentation
run: cargo doc --no-deps
- name: Run tests
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }}
POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }}
COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }}
run: cargo test --verbose
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Enforce formatting
run: cargo fmt --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Run clippy
run: cargo clippy -- -D warnings
33 changes: 25 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
api_version := "2024-07"

# Generate version file
generate-version:
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs
# Lint files and run tests with optional specific test cases
test *tests: lint
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to add a comment for consistency.

# Runs the specified tests, or all tests if none specified
cargo test {{tests}} --verbose

# Update git submodules recursively
update:
git submodule update --init --recursive

# Run linting tools (cargo fmt and clippy)
lint:
cargo fmt && cargo clippy

# Build the OpenAPI and Protobuf definitions in `codegen/apis`
build-apis:
# Run cargo build
build:
cargo build

# Build the OpenAPI and Protobuf definitions in the `codegen/apis` submodule
gen-build-submodule-apis:
cd codegen/apis && just build

# Generate the control plane OpenAPI code based on the yaml files in `codegen/apis/_build`
build-openapi: build-apis generate-version
gen-openapi: gen-build-submodule-apis gen-version_file
./codegen/build-oas.sh {{api_version}}

# Generate the data plane protobuf code based on the yaml files in `codegen/apis/_build`
build-proto: build-apis generate-version
gen-proto: gen-build-submodule-apis gen-version_file
./codegen/build-proto.sh {{api_version}}

# Generate all OpenAPI and protobuf code
build-client: build-apis generate-version
gen-client: gen-build-submodule-apis gen-version_file
./codegen/build-oas.sh {{api_version}}
./codegen/build-proto.sh {{api_version}}

# Generate version file
gen-version_file:
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! # Pinecone Rust SDK
//!
//! > ⚠️ **Warning:** This SDK is still in an alpha state. While it is mostly built out and functional,
//! it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback,
//! but be aware that updates may introduce breaking changes.
//! > it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback,
//! > but be aware that updates may introduce breaking changes.
//!
//! `pinecone-sdk` provides an interface for working with Pinecone services such as the Database and Inference APIs.
//! See [docs.pinecone.io](https://docs.pinecone.io/) for more information.
Expand Down
4 changes: 0 additions & 4 deletions src/openapi/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Generated by: https://openapi-generator.tech
*/



#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
Expand All @@ -30,7 +28,6 @@ pub struct ApiKey {
pub key: String,
}


impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
Expand All @@ -47,7 +44,6 @@ impl Default for Configuration {
oauth_access_token: None,
bearer_access_token: None,
api_key: None,

}
}
}
25 changes: 15 additions & 10 deletions src/openapi/apis/inference_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
* Generated by: https://openapi-generator.tech
*/


use super::{configuration, Error};
use crate::openapi::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize};
use crate::openapi::{apis::ResponseContent, models};
use super::{Error, configuration};


/// struct for typed errors of method [`embed`]
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -25,18 +23,22 @@ pub enum EmbedError {
UnknownValue(serde_json::Value),
}


/// Generate embeddings for input data
pub async fn embed(configuration: &configuration::Configuration, embed_request: Option<models::EmbedRequest>) -> Result<models::EmbeddingsList, Error<EmbedError>> {
pub async fn embed(
configuration: &configuration::Configuration,
embed_request: Option<models::EmbedRequest>,
) -> Result<models::EmbeddingsList, Error<EmbedError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!("{}/embed", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
Expand All @@ -58,8 +60,11 @@ pub async fn embed(configuration: &configuration::Configuration, embed_request:
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<EmbedError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

Loading