Repository navigation
Allow KCL source on export commands #1393
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
Open
Joe-Spencer
wants to merge
9
commits into
main
Choose a base branch
from
codex/export-kcl-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e02395
Allow optional KCL source on export commands
9f54c6c
Merge main into export KCL source
9017773
Merge main and refresh modeling API dependencies
0a57d48
Reuse KclProject for export source
5cec143
Merge main to resolve API review branch conflict
305097d
Merge remote-tracking branch 'origin/main' into codex/export-kcl-source
827f25f
Move KCL project into its own module
adamchalmers 6ed39a2
Merge remote-tracking branch 'origin/main' into codex/export-kcl-source
b3c9569
Preserve KCL project import paths and public builders
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| use crate::shared::safe_filepath::SafeFilepath; | ||
| use bon::Builder; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// A KCL project. | ||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default, Builder)] | ||
| #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] | ||
| #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] | ||
| pub struct KclProject { | ||
| /// All files in the project. | ||
| pub files: Vec<KclFile>, | ||
| /// Which file is the entrypoint? | ||
| /// This is the first KCL file to be executed, | ||
| /// the root of the KCL module tree. | ||
| pub entrypoint: SafeFilepath, | ||
| } | ||
|
|
||
| impl KclProject { | ||
| /// Create a new KCL project. | ||
| pub fn new(files: Vec<KclFile>, entrypoint: SafeFilepath) -> Self { | ||
| Self { files, entrypoint } | ||
| } | ||
| } | ||
|
|
||
| /// A file in a KCL project. | ||
| #[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default, Builder)] | ||
| #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] | ||
| #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] | ||
| #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] | ||
| #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] | ||
| pub struct KclFile { | ||
| /// Where is the file, relative to the project directory? | ||
| pub path: SafeFilepath, | ||
| /// Contents of the file, as UTF-8 encoded bytes. | ||
| #[serde( | ||
| serialize_with = "serde_bytes::serialize", | ||
| deserialize_with = "serde_bytes::deserialize" | ||
| )] | ||
| pub contents: Vec<u8>, | ||
| } | ||
|
|
||
| impl std::fmt::Debug for KclFile { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| f.debug_struct("KclFile") | ||
| .field("path", &self.path) | ||
| .field("contents.len()", &self.contents.len()) | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
| impl KclFile { | ||
| /// Create a KCL file. | ||
| pub fn new(path: SafeFilepath, contents: Vec<u8>) -> Self { | ||
| Self { path, contents } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //! Checks that moving KCL project types preserves consumers' existing import paths. | ||
|
|
||
| use kittycad_modeling_cmds::{kcl_project, shared}; | ||
|
|
||
| #[test] | ||
| fn shared_project_types_and_builders_remain_compatible() { | ||
| let file_builder: shared::KclFileBuilder = kcl_project::KclFile::builder(); | ||
| let file: shared::KclFile = file_builder | ||
| .path("main.kcl".parse().unwrap()) | ||
| .contents(b"// KCL source".to_vec()) | ||
| .build(); | ||
| let file: kcl_project::KclFile = file; | ||
|
|
||
| let project_builder: shared::KclProjectBuilder = kcl_project::KclProject::builder(); | ||
| let project: shared::KclProject = project_builder | ||
| .files(vec![file]) | ||
| .entrypoint("main.kcl".parse().unwrap()) | ||
| .build(); | ||
| let project: kcl_project::KclProject = project; | ||
|
|
||
| assert_eq!(project.entrypoint, project.files[0].path); | ||
| } | ||
|
|
||
| #[cfg(feature = "exec-kcl")] | ||
| #[test] | ||
| fn exec_kcl_project_types_and_builders_remain_compatible() { | ||
| use kittycad_modeling_cmds::exec_kcl; | ||
|
|
||
| let file_builder: exec_kcl::KclFileBuilder = kcl_project::KclFile::builder(); | ||
| let file: exec_kcl::KclFile = file_builder | ||
| .path("main.kcl".parse().unwrap()) | ||
| .contents(b"// KCL source".to_vec()) | ||
| .build(); | ||
| let file: kcl_project::KclFile = file; | ||
|
|
||
| let project_builder: exec_kcl::KclProjectBuilder = kcl_project::KclProject::builder(); | ||
| let project: exec_kcl::KclProject = project_builder | ||
| .files(vec![file]) | ||
| .entrypoint("main.kcl".parse().unwrap()) | ||
| .build(); | ||
| let project: kcl_project::KclProject = project; | ||
|
|
||
| assert_eq!(project.entrypoint, project.files[0].path); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.