Skip to content

Import path should be opaque #190

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

Closed
petr-k opened this issue Feb 17, 2018 · 6 comments
Closed

Import path should be opaque #190

petr-k opened this issue Feb 17, 2018 · 6 comments

Comments

@petr-k
Copy link
Contributor

petr-k commented Feb 17, 2018

When importing jsonnet documents using the import statement, the current implementation assumes that the resource returned from importer's FoundHere is a filesystem path. On subsequent imports, the base dir of that path is derived via a call to path.Dir() (see e.g. https://github.com/google/go-jsonnet/blob/master/interpreter.go#L415). This function always performs a path cleanup.

This is a problem when implementing custom importers that do not use filesystem paths, but for example URLs. E.g. when an importer returns https://github.com/raw/ksonnet/ksonnet-lib/master/ksonnet.beta.2/k.libsonnet in FoundHere, upon resolving relative imports based on that URL, the importDir comes back to the importer cleaned up as https:/raw.githubusercontent.com/ksonnet/ksonnet-lib/master/ksonnet.beta.2 (notice the single forward slash in https:/).

go-jsonnet should not assume filesystem paths, in fact the resource "path" should be opaque.

@petr-k petr-k changed the title Import dir should be opaque Import path should be opaque Feb 17, 2018
@sbarzowski
Copy link
Collaborator

sbarzowski commented Feb 17, 2018

You're right. Thanks for pointing this out.

This was done for compatibility with C++ jsonnet.

IMO the right way to do it would be to have canonicalizePath(codePath, importedPath string) function in Importer interface. This way interpreter would assume nothing about the structure of the path. That would also help with caching (caching once per code directory is not ideal). Having a way to canonicalize paths would let us cache every file exactly once.

@sparkprime What do you think?

@sparkprime
Copy link
Collaborator

Yes I was thinking the same. I also think that was proposed in google/jsonnet#239

@sparkprime sparkprime reopened this Feb 17, 2018
@sparkprime
Copy link
Collaborator

In other words, if the importer is responsible for deriving the new path from the current file and the possibly relative import string, then there is no need for it to expose a splitting function.

@petr-k
Copy link
Contributor Author

petr-k commented Feb 17, 2018

Just to provide some context, I stumbled upon this when implementing an importer that would support URLs in import statements and search paths for the [kubecfg] tool: (https://github.com/ksonnet/kubecfg) vmware-archive/kubecfg#182

@sparkprime
Copy link
Collaborator

C++ implementation did not canonicalize paths: https://github.com/google/jsonnet/blob/master/core/vm.cpp#L37

sbarzowski added a commit to sbarzowski/go-jsonnet that referenced this issue Feb 18, 2018
sbarzowski added a commit to sbarzowski/go-jsonnet that referenced this issue Mar 15, 2018
sbarzowski added a commit to sbarzowski/go-jsonnet that referenced this issue Apr 21, 2018
sbarzowski added a commit to sbarzowski/go-jsonnet that referenced this issue Apr 21, 2018
sparkprime pushed a commit that referenced this issue Apr 28, 2018
@sbarzowski
Copy link
Collaborator

This has been solved a while back.

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

No branches or pull requests

3 participants