janlelis/unicode-display_width

This gem breaks the babosa gem

agross opened this issue ยท 8 comments

I use rubocop together with babosa in a project. Rubocop added this gem as a dependency in 0.37.0.

When requiring babosa, the library checks whether Unicode is defined. If this is the case, it then goes on to require 'unicode' which fails my Travis CI builds and also build on the local machine.

$ gem install babosa
$ gem install unicode-display_width
$ irb
>> require 'unicode/display_width'
true
>> defined? Unicode
"constant"
>> require 'babosa'
LoadError: cannot load such file -- unicode
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/gems/2.2.0/gems/babosa-1.0.2/lib/babosa/utf8/unicode_proxy.rb:1:in `<top (required)>'
        from C:/Ruby/lib/ruby/gems/2.2.0/gems/babosa-1.0.2/lib/babosa/identifier.rb:41:in `<class:Identifier>'
        ...

Hi @agross,

I've investigated a little and it seems to be an issue with babosa not loading a required low-level unicode library. The unicode gem is not a hard ("runtime") dependency of babosa https://rubygems.org/gems/babosa. The reason stated in the README is that they allow different low-level unicode implementations (e.g. unicode gem, JRuby, ActiveSupport, etc).

I have not researched why your workaround works (can you point to the point where there is a test for the Unicode constant?), but I suggest just adding the unicode gem to your setup and trying again.

Hi @janlelis,

To work around the issue I just undefine Unicode before loading babosa: https://github.com/dnugleipzig/web/commit/9990d9ce7b82e7abffb3dae0ca0e2671e5475c46

I don't know if that might break something, at least for now it doesn't. Rubocop is run before nanoc (and nanoc uses babosa for slugs).

Babosa autoloads its Unicode proxy and then checks whether Unicode is defined to require the matching proxy for the available unicode implementation. That is where the clash between the unicode gem and yours surfaces.

Thank you for this extra info. I've created a pull request in babosa.

๐Ÿ‘

I've merged the PR in Babosa ๐Ÿ˜„

Yay, thank you very much!

@parndt Thanks!

๐Ÿ™‡๐Ÿผ