Skip to content

Support XDG_* - #2174

Merged
hsbt merged 37 commits into
ruby:masterfrom
hsbt:support-xdg
Apr 23, 2020
Merged

Support XDG_*#2174
hsbt merged 37 commits into
ruby:masterfrom
hsbt:support-xdg

Conversation

@hsbt

@hsbt hsbt commented May 7, 2019

Copy link
Copy Markdown
Member

We should support XDG Base Directory Specification on the Ruby language.

I try to support the following environmental variables:

  • XDG_CONFIG_HOME
  • XDG_CACHE_HOME
  • XDG_DATA_HOME

Comment thread lib/rdoc.rb Outdated
Comment thread lib/rubygems/gemcutter_utilities.rb Outdated
Comment thread lib/rubygems/config_file.rb Outdated
@k0kubun
k0kubun changed the base branch from trunk to master August 15, 2019 17:15
@hsbt
hsbt marked this pull request as ready for review September 13, 2019 01:13
@hsbt

hsbt commented Sep 13, 2019

Copy link
Copy Markdown
Member Author

@deivid-rodriguez @aycabta Can you review this branch?

I changed rubygems, bundler, rdoc, irb for XDG. I'm going to separate them for the upstream repositories after merging this.

@deivid-rodriguez

Copy link
Copy Markdown
Contributor

Ok, I'll have a look ASAP!

@aycabta aycabta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good patch to merge to RDoc and IRB. I'll make another patch to Reline later.

@deivid-rodriguez deivid-rodriguez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR in general looks great to me. I only added a few minor comments. I think the backwards compatibility mechanism you used (optin if no prior config is there) should be fine 👍.

Comment thread lib/rubygems/test_case.rb Outdated
Comment thread test/rubygems/test_gem.rb Outdated
Comment thread test/rubygems/test_gem.rb Outdated
Comment thread lib/rubygems/defaults.rb
Comment thread lib/rubygems/gemcutter_utilities.rb Outdated
Comment thread lib/rdoc.rb Outdated
Comment thread lib/rubygems/test_case.rb Outdated
Comment thread test/rubygems/test_gem_commands_build_command.rb Outdated
@eregon

eregon commented Mar 7, 2020

Copy link
Copy Markdown
Member

What's the motivation to use these XDG_* variables? Is there a request for it?
I'm not sure I know anyone using them.

@nobu

nobu commented Mar 7, 2020

Copy link
Copy Markdown
Member

XDG would be used in Freedesktop.org (and compatible environments probably).

@simi

simi commented Mar 7, 2020

Copy link
Copy Markdown

@eregon from my experience it is not common to set those manually, but those are set in your environment (Linux/GNOME on my system) on its own to unify config,cache,data application files location.

[retro@retro  ruby (master $%=)]❤ env | grep XDG
XDG_MENU_PREFIX=gnome-
XDG_SESSION_DESKTOP=gnome
XDG_SESSION_TYPE=wayland
XDG_CURRENT_DESKTOP=GNOME
XDG_SESSION_CLASS=user
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/home/retro/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/

Comment on lines +264 to +269
credentials = File.join Gem.user_home, '.gem', 'credentials'
if File.exist? credentials
credentials
else
File.join Gem.data_home, "gem", "credentials"
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern of checking file existence appears to occur several times. Would it be helpful to encapsulate it in a utility method?

def find_home_file(filename)
  path = File.join Gem.user_home, ".gem", filename
  if File.exist? path
    path
  else
    File.join Gem.data_home, "gem", filename
  end
end

@hsbt

hsbt commented Mar 7, 2020

Copy link
Copy Markdown
Member Author

@eregon The modern toolchains supported XDG Base Directory. See https://wiki.archlinux.org/index.php/XDG_Base_Directory

@simi

simi commented Apr 20, 2020

Copy link
Copy Markdown

@hsbt hello, are there any news on this? Is there any plan to move this forward? If needed I can help (for exmaple move rubygems part to rubygems repo as a PR). Ping me if that would be helpful.

@hsbt

hsbt commented Apr 21, 2020

Copy link
Copy Markdown
Member Author

@simi Thanks for your comments. I'm going to merge about RubyGems, RDoc and IRB supports in this branch in few days.

After that, I will backport to the upstream of them. Can you try it and improve them? Thanks.

Comment thread lib/rdoc.rb Outdated
Comment thread lib/rdoc.rb Outdated
Comment thread lib/rdoc/ri/paths.rb
Comment thread test/rdoc/test_rdoc_store.rb
Comment thread lib/rubygems/defaults.rb
# I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
# to be depending on HOME in those code samples. I propose that
# it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
# least on Win32).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is much outdated, for 1.8 era.

Comment thread lib/rubygems/test_case.rb
Dir.chdir @tempdir

ENV['HOME'] = @userhome
FileUtils.mkdir_p File.join(@userhome, ".gem")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this path reused bellow?

Comment thread lib/rubygems/test_case.rb Outdated
FileUtils.mkdir_p File.dirname(temp_cred)
File.open temp_cred, 'w', 0600 do |fp|
fp.puts ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97'
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File.write.

@hsbt
hsbt merged commit 5c6269c into ruby:master Apr 23, 2020
@hsbt
hsbt deleted the support-xdg branch April 23, 2020 10:16
hsbt added a commit to ruby/rubygems that referenced this pull request Apr 24, 2020
@hsbt hsbt mentioned this pull request Apr 24, 2020
4 tasks
hsbt added a commit to ruby/rubygems that referenced this pull request Apr 28, 2020
deivid-rodriguez pushed a commit to ruby/rubygems that referenced this pull request Apr 29, 2020
pombredanne pushed a commit to aboutcode-org/univers that referenced this pull request Dec 7, 2021
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

Successfully merging this pull request may close these issues.

8 participants