-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
require bug #10820
require bug #10820
Comments
I don't follow, can you explain more? A minimal example repository might help. |
There's a nice explanation of the require behaviour here. You can override the base path used, but to view the default run |
Missing require
From the link provided:
I have @jhass Project link Note: This behavior only happens when requiring "crypto-secret" from a shard. It works correctly as described in the documentation when used within the project itself. Extra requireI thought Perhaps it's harmless checking for one extra file that shouldn't exist. Another extra require
Shouldn't it only look for 2 fishy opens that aren't described and one missing open make me think requiring shards is a bit off even if it works most of the time. |
@didactic-drunk Can you please provide a clear description of the problem with a step-by-step explanation that allows anyone to recreate the problem you're talking about. I have honestly no clue what is supposedly wrong here. |
I believe @didactic-drunk did a 249511 access("lib/crypto-secret.cr", F_OK)
249511 access(".../sodium.cr/lib/crypto-secret/crypto-secret.cr", F_OK) But, @didactic-drunk , @kimburgess is correct in saying that this behavior is documented. From the URL referenced, these parts are relevant: (1) "By default the require path is the location of the standard library that comes with the compiler, and the "lib" directory relative to the current working directory" (2.1) "If a file named "filename.cr" is found in the require path, it is required." (2.2) "If a directory named "filename" is found and it contains a file named "filename.cr" directly underneath it, it is required." It is true that in standard cases these files are not found at these specific locations but somewhere else. But the behavior is documented. I'd think this is not creating real problems because it is happening at compile time rather than runtime. As for the other part of your question about a "missing subdir check" or "missing open", why would it need to pre-check the existence of dirs (making extra syscalls) when it can just count on The lookup in shards may look "a bit off" as you said, especially if you observe the least probable paths like the two you've shown, but in effect it is checking for more paths than necessary (rather than less). |
@doecelic is correct about I think my expectations are different based on reading the require documentation. The "2nd rule example" shows "you can have it like this"
And you can everywhere except when including a shard. If the require path was
If anyone has a workaround for the last point I'll take it. |
The docs are incredibly good, but I always find checking the implementation to be the most accurate way to grok any behaviour. The nice thing with Crystal is you can do that, with any part of the toolchain. In this case, it's here. For non-relative requires this is called for each with each entry in the crystal path as the The For setting up a shard that houses a set of libs that you want to require separately, I've found the pattern used here to work well too. |
I'm also experiencing this descrepency. From the docs at https://crystal-lang.org/reference/syntax_and_semantics/requiring_files.html#require-filename:
This doesn't appear to be working for shards installed under lib. For example I'd expect the following structure within installed shards to work with a simplistic require based upon the documentation:
Results in:
Placing the
Am I misudnerstanding the documentation? |
I'm glad at least one other person understands what I'm talking about. Fix that makes all these problems go away, opens up more flexible include paths and makes it ruby like: |
It seems the forth rule is incorrect, the docs should be updated. That said, you can have it structured like this:
and in turn @didactic-drunk I think the main problem everyone (including me) seems to have had with the bug report is that it wasn't clear. A bug report is best in the form:
Instead, the bug report was "This is questionable. Attached is some cryptic output." I had to parse the output to figure it was fstat or some utility that displays which files need to be checked (to this point I don't know what the correct name of the tool is) Ruby require rules aren't very good in my opinion. I think rubygems changes the load path at runtime for each gem or something like that, which seems like a total hack. The current lookup rule in Crystal tie together a project with the usual lib/shards structure. But that's just my opinion :-) |
I thought the fix was easy, just remove the incorrect lookup rule from documentation. But it might not be that simple. The rule is actually correct for paths with multiple components.
Back to the original issue here, I think |
There is also some weird behaviour. For example, |
Been 4 months, I guess I'll try this again: why does the compiler know about package layout? Shouldn't |
This works completely independent of These are not heuristics, but well-defined lookup rules. Okay, some individual ones may not be so much well-defined. Those are not that relevant, though. They just need some refinement, but the overall mechanism is pretty clear. And it's definitely not very complicated. The refactoring in #10876 hopefully makes that more visible. Not sure what your 4 months reference is supposed to mean? |
I brought it up 4 months ago on another issue and y'all got mad and closed it. I disagree completely; it looks like it was decided that shards would be stupid and just download things to a directory, and then the compiler was modified whenever someone started using a different package layout to make it work under this system. Perl, Python, Ruby, GCC.... none of them have a long list of rules for how import names are mapped to paths (Python will look for dir/__init__.py, which is why I said the foo/foo.cr rule could be useful), and none of them look in a randomly-named subdirectory of the current directory. Shards has much more information than the compiler does and places more restrictions on file layouts, so why must all of this information be passed implicitly through the filesystem instead of Not surprised you're attached to the current behavior, but it seems more optimized for the type of people that build their own compiler, not users. I mean, there's no "make install" command to put the compiler on one's PATH... |
pseudonyn: could you explain what's the issue you are facing? We can try to fix it. |
Would you be able to provide a link to the previous discussion you mentioned, please? I'd like to know what you're talking about but could not find it. |
@asterite Despite @didactic-drunk's poor explanation, I'm clearly not the only one who finds the current behavior surprising. This shouldn't be treated as purely a documentation problem, but an opportunity for the behavior to be simplified so it's easier to document. |
Oh, that discussion... I'm still a firm believer that if we make it configurable then if you download some Crystal code or package you have a chance of not knowing how things are organized. But removing the possibility of configuring things, things become simpler and more intuitive. If you used Ruby on Rails you will understand. |
Thanks for the link. I'm sorry if you had the impression everyone just completely dismissed your comments. The reason for closing this discussion was just that the original issue had been considered resolved, and when you revived the discussion, it just drew attention to it which results in closing. I tried to explain that to you and asked to open a new issue about the concerns you have. |
2 of the requires are questionable and one is missing (based on
foo.cr
may be placed underfoo/
)The text was updated successfully, but these errors were encountered: