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

Prefer the README file that has the basename README #1231

Closed
mojavelinux opened this issue Mar 24, 2019 · 5 comments
Closed

Prefer the README file that has the basename README #1231

mojavelinux opened this issue Mar 24, 2019 · 5 comments

Comments

@mojavelinux
Copy link
Contributor

I'm facing a situation where the translated version of the README (e.g., README-jp.adoc) in a gem is being selected over the primary (English) one (README.adoc). (See https://www.rubydoc.info/gems/asciidoctor/2.0.0). This happens because of how the the README files are globbed.

The README files in the gem are as follows:

README.adoc
README-de.adoc
README-fr.adoc
README-jp.adoc
README-zh_CN.adoc

The glob used by YARD is README*. For some reason, that results in README-jp.adoc being selected as the default. (It appears the result of the glob isn't sorted at all).

I think the file with the basename README (e.g., README.adoc) should be preferred over files that are hyphenated. I think most people would agree that this is the master README file in all situations.

(I'm aware I can include a .yardopts file to select a specific README. However, I can't make that change for gems that have already been released).

@lsegal
Copy link
Owner

lsegal commented Mar 24, 2019

For some reason, that results in README-jp.adoc being selected as the default. (It appears the result of the glob isn't sorted at all).

I believe that the list is sorted lexically, which would make sense if README-X was chosen over README.X since:

> '-'.ord < '.'.ord
=> true
> ['.', '-'].sort
=> ["-", "."]

That said, I believe globs are system dependent, so the behavior certainly isn't guaranteed. This can be problematic in cases where you're trying to deliver consistent docs across platforms.

I think a PR to prioritize README followed by README.* could be acceptable, but note that such a PR only solves this specific case. Users who name files as README.de.adoc would have the same problem you initially have here (this is a file naming convention the Ruby repo seems to use).

Sorting the entire list could be done but could be seen as a breaking change, since it would change the behavior for systems that don't sort globs initially. I'm not sure how I feel about that, given that it (a) changes behavior but (b) is undefined behavior.

Another heuristic we could use would be to stable-sort by the frequency of '.' in the strings. That should ensure README < README.{adoc,md,txt,...} < README.{en,de,fr,...}.{adoc,md,txt,...}. You would probably need to couple it with the specific README,README.* priority rule to also solve for your case, though.

@mojavelinux
Copy link
Contributor Author

I think a PR to prioritize README followed by README.* could be acceptable

I'd be glad to.

but note that such a PR only solves this specific case.

Well, it's the most likely scenario. Any project that has a single file extension README.* probably, if not always, wants that to be used over any README-*. It's extremely clear what the single file extension README.* represents. It also happens to be the same logic GitHub uses. That's why the English README is shown at https://github.com/asciidoctor/asciidoctor and not the Japanese one (or any other transation).

Users who name files as README.de.adoc would have the same problem you initially have here

That's why I say "single file extension". That's important.

I believe globs are system dependent, so the behavior certainly isn't guaranteed.

No question, at the very least making it deterministic would be a good step forward.

Sorting the entire list could be done but could be seen as a breaking change, since it would change the behavior for systems that don't sort globs initially.

If we fix the main issue at hand, I don't think the sorting becomes all that important. Though it would still be good to stabilize it.

@mojavelinux
Copy link
Contributor Author

that results in README-jp.adoc being selected as the default

Apologies, I was mistaken. It selects the Chinese translation (zh_CN), which makes sense because it's at the end of the list. That must mean it's reversing the list at some point. I'll try to figure out what the existing rules are and report back.

@mojavelinux
Copy link
Contributor Author

Here's the order that Dir.glob returns (Ruby 2.6):

README-zh_CN.adoc
README.adoc
README-fr.adoc
README-jp.adoc
README-de.adoc

go figure

mojavelinux added a commit to mojavelinux/yard that referenced this issue Mar 30, 2019
- sort README files, first by file extension, then by basename
- prefer README basename over all other files
- prefer file without extension over file with extension
@mojavelinux
Copy link
Contributor Author

See PR #1233.

mojavelinux added a commit to mojavelinux/yard that referenced this issue Mar 31, 2019
- sort README files, first by file extension, then by basename
- prefer README basename over all other files
- prefer file without extension over file with extension
- don't glob for files if README is missing and files list is empty
mojavelinux added a commit to mojavelinux/yard that referenced this issue Mar 31, 2019
- sort README files, first by file extension, then by basename
- prefer README basename over all other files
- prefer file without extension over file with extension
- don't glob for files if README is missing and files list is empty
@lsegal lsegal closed this as completed in 88da7e6 Mar 31, 2019
lsegal added a commit that referenced this issue Mar 31, 2019
lsegal added a commit that referenced this issue Apr 2, 2019
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

2 participants