-
Notifications
You must be signed in to change notification settings - Fork 310
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
Relative import #403
Comments
Original reply by @myitcv in cuelang/cue#403 (comment) More context from the Go side in golang/go#20883 |
Original reply by @verdverm in cuelang/cue#403 (comment) Can the fix or mod commands be used to alleviate @shykes moving pains but maintain that all imports are fully qualified? |
Original reply by @myitcv in cuelang/cue#403 (comment)
Whether it belongs in either of those commands I'm not sure, but I definitely agree that we need some tooling to support this. FWIW in the Go world there are indeed tools that fix import paths for exactly this sort of use case/reason. Two quotes stand out from the linked Go issue for me:
@shykes would better tooling solve the problems you're facing? |
Original reply by @shykes in cuelang/cue#403 (comment) A rewrite tool feels like plan B to me. Plan A is to not need the tool at all, IMO.
|
Original reply by @myitcv in cuelang/cue#403 (comment) I'm actually of the opposite opinion 😄. My thinking being that if the principal use case here is moving packages, that short-term (infrequent?) pain can be solved with tooling. Supporting relative imports would appear to harm readability in the long term. |
Original reply by @shykes in cuelang/cue#403 (comment) Why do relative imports harm readability? The concept is well understood, and it removes both characters from source files, and cognitive load from the reader’s brain. Another downside of forbidding relative imports is that it forces you to choose a module address before you can start breaking up your configuration into sub-packages. That constraint may be fine (although debatable) in the context of a Go project or other “full-blown” programming environment. But from the perspective of a configuration language, it’s highly unusual. Imagine if your Apache configuration required you to pick a URL to uniquely identify your config before allowing you to including files from ./sites-enabled/ ?
|
Original reply by @myitcv in cuelang/cue#403 (comment)
IMHO they harm readability because:
The name of the module can be anything containing a dot. It only needs to be uniquely identified if you plan to publish that module. |
Original reply by @mpvl in cuelang/cue#403 (comment) I think a notation like
where This is consistent with the fact that modules can have no name. It would allow importing packages within such module even if the name isn't there. So this is an argument in favor of usability as well, aside from the ability to refactor. A downside of this approach is that import path now no longer uniquely identify a module. To some extent this is already the case, though, as |
Original reply by @shykes in cuelang/cue#403 (comment) That’s true,
|
Original reply by @mpvl in cuelang/cue#403 (comment) Update: the main problem with using If that is the case, the import statements may be better of looking like But since we allow anonymous modules in CUE, it does seem that having some way to not have to specify a module name would be good. Anonymous packages are indicated with If this is all weird, we could consider using relative paths after all. As we are going to a closed module system, we can restrict relative paths to files within a module, eliminating most, if not all, of the security concerns. |
Originally opened by @shykes in cuelang/cue#403
Is your feature request related to a problem? Please describe.
Currently Cue does not support relative imports. The full address of the module must always be written down, even when the module is the current one. This means modules cannot be safely relocated (moved to a new address) without manually searching through all its contents, and rewriting the import address.
Describe the solution you'd like
The simplest solution, I think, is to interpret imports prefixed by
./
as meaning "relative to the current module".For example:
example.tld/foo
import ( "./bar" )
import ( "example.tld/foo/bar" )
Describe alternatives you've considered
Currently I use a bogus module name, like
127.0.0.1
when developing, and explicitly import127.0.01/subpkg
to make manual search-replace easier. Obviously that is not an elegant solution.Additional context
In live conversation, @mpvl mentioned that Cue imports are copied from Go imports, and they do not support relative imports, apparently for security reasons.
There may be security issues that I'm missing. But as long as only
./
is allowed, and more dangerous things like../
are explicitly forbidden, it seems to me that this would be safe.The text was updated successfully, but these errors were encountered: