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

Requiring nokogiri/version does not fully define Nokogiri::VERSION #1896

Closed
headius opened this issue Apr 20, 2019 · 4 comments
Closed

Requiring nokogiri/version does not fully define Nokogiri::VERSION #1896

headius opened this issue Apr 20, 2019 · 4 comments

Comments

@headius
Copy link
Contributor

headius commented Apr 20, 2019

When requiring just 'nokogiri/version', the Nokogiri::VERSION errors, likely because the JRuby extension does not load.

$ jruby -e 'require "nokogiri/version"; Nokogiri::VERSION'
NameError: uninitialized constant Nokogiri::XERCES_VERSION
      const_missing at org/jruby/RubyModule.java:3742
            to_hash at /Users/headius/projects/jruby/lib/ruby/gems/shared/gems/nokogiri-1.10.2-java/lib/nokogiri/version.rb:74
  <module:Nokogiri> at /Users/headius/projects/jruby/lib/ruby/gems/shared/gems/nokogiri-1.10.2-java/lib/nokogiri/version.rb:100
             <main> at /Users/headius/projects/jruby/lib/ruby/gems/shared/gems/nokogiri-1.10.2-java/lib/nokogiri/version.rb:1
            require at org/jruby/RubyKernel.java:987
             (root) at /Users/headius/projects/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
             <main> at /Users/headius/projects/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:130

The constant should get defined within version.rb or it should require in what it needs for this constant.

@flavorjones
Copy link
Member

Hi @headius,

I think you're assuming a contract where one doesn't exist. The file nokogiri/version.rb has never been intended to be required by itself, because (as you point out in #1899) the underlying libraries aren't guaranteed to have been loaded.

Can you help me understand why you want to load this file individually? Specifics about your use case would really help. I imagine it's because many gems have an implicit contract that you can more-cheaply get version info if only that file is loaded, and you'd like that here -- but I'd like to validate that assumption.

The change you've made in #1899 does introduce that contract; but only for JRuby. It may be worth pointing out that currently this contract does not exist for CRuby, either:

ruby -ryaml -rnokogiri/version -e 'puts Nokogiri::VERSION_INFO.to_yaml'
---
warnings: []
nokogiri: 1.10.3
ruby:
  version: 2.6.2
  platform: x86_64-linux
  description: ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
  engine: ruby

modulo that in CRuby, no errors are raised, the constants populated by version.rb do not include the underlying libraries.

@flavorjones
Copy link
Member

All of which is to say, I think I'm OK with introducing this contract, but I'd like it to be consistently enforced across both backends.

@flavorjones
Copy link
Member

Oh! Ignore my above comment, I see your change in #1899 does indeed introduce that contract for CRuby as well. I'll fix the PR (which went red because the new file isn't in the Manifest (thanks, Hoe)) and merge it once it's green.

Thanks, @headius!

flavorjones added a commit to headius/nokogiri that referenced this issue Apr 27, 2019
flavorjones added a commit to headius/nokogiri that referenced this issue Apr 27, 2019
This ensures "version.rb" can be required by itself for CRuby as well
as JRuby.

Part of fixing sparklemotion#1896.
@flavorjones flavorjones added this to the v1.11.0 milestone Apr 27, 2019
flavorjones added a commit to headius/nokogiri that referenced this issue Apr 28, 2019
flavorjones added a commit that referenced this issue Apr 28, 2019
flavorjones added a commit that referenced this issue Apr 28, 2019
This ensures "version.rb" can be required by itself for CRuby as well
as JRuby.

Part of fixing #1896.
flavorjones added a commit that referenced this issue Apr 28, 2019
@flavorjones
Copy link
Member

This will be fixed in v1.11.0. Please watch the milestone for status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants