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

Support XDG_* #2174

Merged
merged 37 commits into from Apr 23, 2020
Merged

Support XDG_* #2174

merged 37 commits into from Apr 23, 2020

Conversation

hsbt
Copy link
Member

@hsbt hsbt commented May 7, 2019

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

lib/rdoc.rb Outdated Show resolved Hide resolved
@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
Copy link
Member Author

hsbt commented Sep 13, 2019

@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
Contributor

Ok, I'll have a look ASAP!

Copy link
Member

@aycabta aycabta left a comment

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.

Copy link
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

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 👍.

lib/rubygems/test_case.rb Outdated Show resolved Hide resolved
test/rubygems/test_gem.rb Outdated Show resolved Hide resolved
test/rubygems/test_gem.rb Outdated Show resolved Hide resolved
lib/rubygems/defaults.rb Show resolved Hide resolved
lib/rubygems/gemcutter_utilities.rb Outdated Show resolved Hide resolved
lib/rdoc.rb Outdated Show resolved Hide resolved
lib/rubygems/test_case.rb Outdated Show resolved Hide resolved
test/rubygems/test_gem_commands_build_command.rb Outdated Show resolved Hide resolved
@eregon
Copy link
Member

eregon commented Mar 7, 2020

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
Copy link
Member

nobu commented Mar 7, 2020

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

@simi
Copy link
Contributor

simi commented Mar 7, 2020

@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
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
Copy link
Member Author

hsbt commented Mar 7, 2020

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

@simi
Copy link
Contributor

simi commented Apr 20, 2020

@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
Copy link
Member Author

hsbt commented Apr 21, 2020

@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.

lib/rdoc.rb Outdated Show resolved Hide resolved
lib/rdoc.rb Outdated Show resolved Hide resolved
lib/rdoc/ri/paths.rb Show resolved Hide resolved
test/rdoc/test_rdoc_store.rb Show resolved Hide resolved
# 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
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.

@@ -363,6 +363,14 @@ def setup
Dir.chdir @tempdir

ENV['HOME'] = @userhome
FileUtils.mkdir_p File.join(@userhome, ".gem")
Copy link
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?

FileUtils.mkdir_p File.dirname(temp_cred)
File.open temp_cred, 'w', 0600 do |fp|
fp.puts ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97'
end
Copy link
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 rubygems/rubygems that referenced this pull request Apr 24, 2020
hsbt added a commit to rubygems/rubygems that referenced this pull request Apr 28, 2020
deivid-rodriguez pushed a commit to rubygems/rubygems that referenced this pull request Apr 29, 2020
pombredanne pushed a commit to nexB/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
8 participants