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

Restructure repository #35

Merged
merged 10 commits into from
Jul 29, 2024
Merged

Restructure repository #35

merged 10 commits into from
Jul 29, 2024

Conversation

emily-emily
Copy link
Contributor

@emily-emily emily-emily commented Jul 22, 2024

Problem

OpenAPI generates Rust code in the form of a crate. To publish our SDK without separately publishing the OpenAPI code as its own crate, we want to include it as a module in our SDK instead of as an external dependency.

Solution

  • Remove workspace and make pinecone_sdk the root project.
  • OpenAPI code generates to temporary folder .openapi-crate.
  • OpenAPI dependencies are added to Cargo.toml for pinecone_sdk.
  • Bash script copies source files from the generated crate into src/openapi and also updates imports in these files to reflect the new project structure.
  • Protobuf code is also moved into src/protos and turned into a module.
  • Disables warnings for generated code (openapi and proto).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Infrastructure change (CI configs, etc)
  • Non-code change (docs, etc)
  • None of the above: (explain here)

Test Plan

All existing test cases pass.

@emily-emily emily-emily self-assigned this Jul 22, 2024
@emily-emily emily-emily marked this pull request as ready for review July 23, 2024 13:35
@spacejam
Copy link
Member

spacejam commented Jul 23, 2024

the bash script may be better done as a build.rs file, similar to the build.rs file in our main pinecone-io/pinecone-db/outer-protos/build.rs script. We use tonic-build there for protobufs, but there are a few options depending on what kind of codegen you want to do, and probably the openapi stuff can be done in a similar way.

https://docs.rs/tonic-build/latest/tonic_build/

@austin-denoble
Copy link
Contributor

the bash script may be better done as a build.rs file, similar to the build.rs file in our main pinecone-io/pinecone-db/outer-protos/build.rs script. We use tonic-build there for protobufs, but there are a few options depending on what kind of codegen you want to do, and probably the openapi stuff can be done in a similar way.

https://docs.rs/tonic-build/latest/tonic_build/

They've used tonic-build in /codegen/proto_build/src/main.rs - https://github.com/pinecone-io/pinecone-rust-client/blob/main/codegen/proto_build/src/main.rs#L27-L30, which is called from the build-proto.sh file. I'm assuming they've opted to leverage bash scripts inside the /codegen/ folder here which aligns with how we do code generation in the other SDKs.

This seems fine to me, but let us know if there are any additional ways this could be improved, @spacejam.

Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

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

Overall, I feel like this makes a lot of sense. Having the openapi and protos as modules inside of pinecone_sdk feels a bit easier to reason about, but I suppose we have to do some manual manipulation of the generated code to get it working.

I've left some feedback around some improvements to the actual generation scripts / steps. I think having a variable for the api_version is important, and I've linked to some examples of getting that set up in other repos, but let me know if you have any questions. I had to implement something similar in the Go SDK recently, and can talk through some of the considerations there.

It might be good to get eyes from @haruska, @ssmith-pc, and @jhamon on this if possible, just to make sure the code generation and project-level / Rust-focused aspects make sense here.

Really nice work on this!

justfile Outdated Show resolved Hide resolved
justfile Outdated Show resolved Hide resolved
codegen/build-oas.sh Show resolved Hide resolved
codegen/build-proto.sh Outdated Show resolved Hide resolved
Comment on lines +19 to +22
# copy source files from the crate to the module (outdir)
echo "Copying source files from $tempdir to $outdir"
mod_header=$'\n#![allow(missing_docs)]\n'
pushd $PROJECT_DIR
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do this manually because the openapi-generator-cli outputs to a crate rather than a module by default?

I was going to ask why we couldn't put the generated files directly into outdir, but I'm probably missing something about how this actually works. It also seems like this piece of code is slightly altering each generated file to match where they've been moved to. 🤔

I'm not sure if I have strong opinions on modifying the generated code like this, to me it seems fine and a bit analogous to what we do with templates in Python, and if this is consistently done each time we generate the client it should be fine.

I'd be curious if @jhamon had thoughts on this specifically, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, there could be better way to do it, but openapi-generator-cli outputs a crate and there are some small modifications that need to be made for the source files to be included as if they were defined as a module (eg. relative import paths). I didn't copy them directly to outdir to map out where I wanted files to go, and it seemed easier to pick out files I wanted rather than figure out all the files to remove. We could clean it up at the end of the script.

Not sure how robust this is moving forward but it seems to work fine right now.

Copy link
Contributor

@ssmith-pc ssmith-pc left a comment

Choose a reason for hiding this comment

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

Looks great! Could definitely use a pass-through on the README, either in this PR or a fast-follow.

I'm not sure the pinecone_sdk folder is still needed?

src/lib.rs Show resolved Hide resolved
@emily-emily emily-emily merged commit c0c109f into main Jul 29, 2024
1 check passed
@emily-emily emily-emily deleted the emily/restructure branch July 29, 2024 15:42
emily-emily added a commit that referenced this pull request Jul 29, 2024
OpenAPI generates Rust code in the form of a crate. To publish our SDK
without separately publishing the OpenAPI code as its own crate, we want
to include it as a module in our SDK instead of as an external
dependency.

- Remove workspace and make `pinecone_sdk` the root project.
- OpenAPI code generates to temporary folder `.openapi-crate`.
- OpenAPI dependencies are added to `Cargo.toml` for `pinecone_sdk`.
- Bash script copies source files from the generated crate into
`src/openapi` and also updates imports in these files to reflect the new
project structure.
- Protobuf code is also moved into `src/protos` and turned into a
module.
- Disables warnings for generated code (openapi and proto).

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [x] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

All existing test cases pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants