piotrmurach/tty-reader

io/console required but gem not included in gemspec

mmrwoods opened this issue · 2 comments

Describe the problem

TTY::Reader requires io/console, but the io-console gem is not included as a dependency in gemspec.

This results in a LoadError on systems where the io-console gem is not included with the Ruby package/installation.

I ran into this problem on Amazon Linux 2, which does not include io-console in the main Ruby rpm packages, it must be installed separately (via a rubygem-io-console rpm package).

Steps to reproduce the problem

Install a ruby package on Amazon Linux 2, then gem install tty-reader and try loading tty-reader, e.g.

# amazon-linux-extras enable ruby2.6
....
....
# yum install ruby ruby-irb
....
....
# gem install tty-reader
Fetching tty-screen-0.8.1.gem
Successfully installed tty-screen-0.8.1
Fetching tty-cursor-0.7.1.gem
Successfully installed tty-cursor-0.7.1
Fetching wisper-2.0.1.gem
Successfully installed wisper-2.0.1
Fetching tty-reader-0.8.0.gem
Successfully installed tty-reader-0.8.0
4 gems installed
# irb
irb(main):001:0> require 'tty-reader'
Traceback (most recent call last):
       16: from /bin/irb:23:in `<main>'
       15: from /bin/irb:23:in `load'
       14: from /usr/share/gems/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
       13: from (irb):1
       12: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:34:in `require'
       11: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
       10: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:130:in `require'
        9: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty-reader.rb:1:in `<top (required)>'
        8: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty-reader.rb:1:in `require_relative'
        7: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty/reader.rb:10:in `<top (required)>'
        6: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty/reader.rb:10:in `require_relative'
        5: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty/reader/console.rb:6:in `<top (required)>'
        4: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty/reader/console.rb:6:in `require_relative'
        3: from /usr/local/share/gems/gems/tty-reader-0.8.0/lib/tty/reader/mode.rb:3:in `<top (required)>'
        2: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
        1: from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'
LoadError (cannot load such file -- io/console)
irb(main):002:0>

Actual behaviour

"LoadError (cannot load such file -- io/console)" when requiring tty-reader

Expected behaviour

I guess io-console gem to be installed as dependency of tty-reader and no LoadError when io/console is required by tty-reader.

Describe your environment

  • OS version: Amazon Linux 2
  • Ruby version: 2.6 (installed from Amazon Linux Extras repos)
  • TTY version: TTY Reader version 0.8.0 (but master has same issue)

Hi Mark 👋

Thanks for using tty-reader in your project.

As you already noted the Ruby shipped with Linux 2 is a stripped-down version. The io-console is part of standard Ruby distribution hence why it's not part of the gemspec dependencies. Here is a full list of all packages distributed in standard Ruby 2.6 standard gems. Other packages this gem uses are forwardable and fiddle and I tend to use many more in my other projects. Is your suggestion that I should be including all Ruby standard gems in gemspec dependencies? This may lead to some future conflicts with bundler/rubygems resolution algorithm which may on a system with default io-console prefer it over the newer version. I think if you choose to use restricted/non-standard Ruby version that the onus is on you to also patch up all the missing bits. You will hit exactly the same problems with any other gem that uses gems from the standard set.

Hi Piotr,

Thanks for responding so quickly. Sorry, I didn't realise io-console was part of the standard library, and was considered a default gem that should be included as part of a Ruby distribution.

I was just reporting an issue I'd run into, rather than just ignore it, but it seems I did not investigate thoroughly before pressing send and wasted your time. Sorry about that. You're right, the onus is on me here to patch up the missing bits as I'm stuck with the stripped down Ruby shipped with Amazon Linux 2.

Thanks very much for responding all the same, really appreciate the quick reply explaining how this is not an issue with tty-reader, I've learnt something new today :-)

Regards

Mark