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

Module system extensions and assemblies #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Module system extensions and assemblies #12

wants to merge 1 commit into from

Conversation

nrc
Copy link

@nrc nrc commented Oct 18, 2024

This doc describes possible extensions to the current import/export syntax for modules. This includes support for assemblies.


### Foreign formats

`import` can be used to import objects defined in other CAD formats, replacing the `import` function in the standard library. E.g., `model = import("tests/inputs/cube.obj")` is replaced by `import "tests/inputs/cube.obj" as model`. Such objects are treated in the same way as other assemblies, but they are always opaque (no AST, etc.) and read-only.
Copy link

Choose a reason for hiding this comment

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

I was wondering about this. I like the idea of combining these cases.

Copy link

@jtran jtran left a comment

Choose a reason for hiding this comment

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

Sounds good to me.


This is mostly postponed for future work. We would use the same syntax and semantics as the rest of the system, however the string in the import would include some indicator that the target is outside the project and how to locate it.

Example with very, very strawman syntax: `import a from "cargo://some-library/foo.kcl"` would import `a` from the file `foo.kcl` in the project `some-library` located in the `cargo` (lol) repository. `import a from "local://../some-library/foo.kcl` would import `a` from the file `foo.kcl` from a sibling directory of the current project called `some-library`. The point of these examples is not the syntax for identifying other projects or the places where an external project might live, just to show how the `import` statement might be extended to support other projects.
Copy link

Choose a reason for hiding this comment

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

Interesting. I hadn't seen anything like this before.

Copy link
Author

Choose a reason for hiding this comment

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

We should properly design the syntax inside the quotes here, I literally just made it up, but I'm sure we can figure something out which does everything we need it to, whether that's url-like or more structured or whatever


This is mostly postponed for future work. We would use the same syntax and semantics as the rest of the system, however the string in the import would include some indicator that the target is outside the project and how to locate it.

Example with very, very strawman syntax: `import a from "cargo://some-library/foo.kcl"` would import `a` from the file `foo.kcl` in the project `some-library` located in the `cargo` (lol) repository. `import a from "local://../some-library/foo.kcl` would import `a` from the file `foo.kcl` from a sibling directory of the current project called `some-library`. The point of these examples is not the syntax for identifying other projects or the places where an external project might live, just to show how the `import` statement might be extended to support other projects.

Choose a reason for hiding this comment

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

I would love to do the golang dep thing and just allow github.com/kittycad/kcl-samples/my-wheel.kcl as an import. cc @paultag and @Irev-Dev who we've talked about this before, this allows people to use urls and saves us having to create some package manager for a while, PLUS promotes git usage

Copy link

@paultag paultag Oct 24, 2024

Choose a reason for hiding this comment

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

strong concur; it also lets us avoid the incredible complexity of a package manager (and associated tooling which we'd have to handle), as well as it adds a lot of clarity in the modules (no namespace squatting; food-fight adjudication over copyrights and shit.

It also gives a level of "official" status to our repos and other trusted orgs -- it's hard to tell if https://pypi.org/project/cryptography/ is official pyca or some rano without looking closely; or like tokio_xyz -- is that tokio or some rando? Hard to tell unless you find the repo (which may or may not get linked).

Love having everything be a git url, or even some intermediate like go's module url protocol if we wanted to get wicked fancy with it (for sub-folder imports this would be required so we know where the module root is; likely with special-casing for github as go-get has until they support ?kcl-import=1)

@yeroca
Copy link

yeroca commented Oct 27, 2024

Being able to import from the internet would be very nice for open source projects so that not everything needs to be downloaded locally by the user somehow. Referencing the imported code via by a git commit or tag (e.g. v1.1) can be specified in the URL to ensure getting the intended and stable / locked-down version of the code.

Signed-off-by: Nick Cameron <nrc@ncameron.org>
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.

6 participants