lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.95k stars 398 forks source link

Expand path non-absolute home #1539

Closed SenZmaKi closed 8 months ago

SenZmaKi commented 8 months ago

There's no mention anywhere that yard is Unix only, on Windows yard doesn't even start

yard --version
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard/config.rb:95:in `expand_path': non-absolute home (ArgumentError)
    CONFIG_DIR = File.expand_path('~/.yard')
                                  ^^^^^^^^^
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard/config.rb:95:in `<class:Config>'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard/config.rb:86:in `<module:YARD>'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard/config.rb:2:in `<top (required)>'
        from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require'
        from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard.rb:13:in `<module:YARD>'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/lib/yard.rb:2:in `<top (required)>'
        from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require'
        from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:127:in `require'
        from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/yard-0.9.36/bin/yard:11:in `<top (required)>'
        from C:/Ruby33-x64/bin/yard:32:in `load'
        from C:/Ruby33-x64/bin/yard:32:in `<main>'

I have the HOME environment variable set, maybe getting HOME directly from ENV then joining to .yard would fix it, something like

    CONFIG_DIR = File.join(ENV["HOME"], '.yard')
MSP-Greg commented 8 months ago

That's a Ruby error, not a YARD error. I don't have HOME set.

Have you tried this in stand-alone Ruby?

ruby -e "puts File.join(ENV['HOME'], '.yard')"
-- or --
ruby -e "puts File.expand_path('~/.yard')"
SenZmaKi commented 8 months ago

Here are my outputs

ruby -e "puts File.expand_path('~/.yard')"

-e:1:in `expand_path': non-absolute home (ArgumentError)

puts File.expand_path('~/.yard')
                      ^^^^^^^^^
        from -e:1:in `<main>'

ruby -e "puts File.join(ENV['HOME'], '.yard')"

\Users\PC/.yard
lsegal commented 8 months ago

Windows relies on USERPROFILE (or HOMEDRIVE / HOMEPATH) to derive your home directory from ~, not HOME. You should print your full ENV to see if those are missing. This definitely sounds like a general environment issue with your Ruby installation and not specific to yard

SenZmaKi commented 8 months ago

These are all the environment variables you mentioned

> echo %HOMEPATH%
\Users\PC

> echo %USERPROFILE%
C:\Users\PC

> echo %HOMEDRIVE%
C:

> echo %HOMEPATH%
\Users\PC

> echo %HOME%
\Users\PC

I'll leave it up to you to close it since you might wanna come back to it

MSP-Greg commented 8 months ago

@SenZmaKi

From the Ruby error, ENV['HOME'] needs to be an absolute path, so something like C:/Users/PC.

I haven't looked thru the code, but I set something similar to the following for running tests on Windows BUNDLE_PATH: "/usr/vendor", which exists as C:/usr/vendor, and it works. Not sure how Bundler resolves the path.

SenZmaKi commented 8 months ago

@MSP-Greg

When I set use File.join(ENV['HOME'], '.yard') it works just fine the problem comes with File.expand_path('~/.yard')

lsegal commented 8 months ago

This is definitely an issue with Ruby, not yard, and as such, is an upstream issue with Ruby and should be reported there. This works in our CI testing, on my Windows machine, etc. I remember seeing path expansion issues before, but only when Ruby was not configured correctly.

SenZmaKi commented 8 months ago

I've fixed it finally, the problem was with the HOME environment variable. I had set it personally for convenience and its value was HOMEPATH which is \Users\PC, I assumed most tools on windows would use HOMEPATH cause HOME isn't typically available on windows, even then since it's value is still set to HOMEPATH there'd be no issue.

Ruby for whatever reason still chose to check in HOME and expanded it to \Users\PC which then caused the non-absolute home error. When I deleted HOME or set it to C:\Users\PC yard worked. This probably means ruby isn't using HOMEPATH when expanding home or maybe doing some extra work after expanding HOMEPATH to make it absolute which wasn't the case with HOME.

Thanks for the help and sorry for the inconvenience.