GithubHelp home page GithubHelp logo

Do not require_relative in gemspec about fiddle HOT 8 CLOSED

ruby avatar ruby commented on August 22, 2024
Do not require_relative in gemspec

from fiddle.

Comments (8)

kou avatar kou commented on August 22, 2024

How about this?

diff --git a/ext/fiddle/fiddle.gemspec b/ext/fiddle/fiddle.gemspec
index befa7aeff5..a3dc425245 100644
--- a/ext/fiddle/fiddle.gemspec
+++ b/ext/fiddle/fiddle.gemspec
@@ -1,18 +1,12 @@
 # frozen_string_literal: true
 
-source_version = ["", "ext/fiddle/"].find do |dir|
-  begin
-    break File.open(File.join(__dir__, "#{dir}lib/fiddle/version.rb")) {|f|
-      f.gets("\n  VERSION = ")
-      f.gets[/\s*"(.+)"/, 1]
-    }
-  rescue Errno::ENOENT
-  end
+unless defined?(Fiddle::VERSION)
+  require_relative "lib/fiddle/version"
 end
 
 Gem::Specification.new do |spec|
   spec.name          = "fiddle"
-  spec.version       = source_version
+  spec.version       = Fiddle::VERSION
   spec.authors       = ["Aaron Patterson", "SHIBATA Hiroshi"]
   spec.email         = ["[email protected]", "[email protected]"]
 

from fiddle.

kou avatar kou commented on August 22, 2024

I confirmed that this suppresses the warning reported by make test-all TESTS="../ruby/test/ruby/test_gc_compact.rb ../ruby/test/ruby/test_default_gems.rb". (../ruby is the source directory.)

from fiddle.

mame avatar mame commented on August 22, 2024

Looks good!

from fiddle.

mame avatar mame commented on August 22, 2024

Ah. You should notice that it may use a wrong version if require "fiddle" is done before loading gemspec. I guess that manual extraction of the version is dirty but more robust. I leave it up to you.

from fiddle.

kou avatar kou commented on August 22, 2024

I'm not sure that it's caused in real world...

How about this?

diff --git a/ext/fiddle/fiddle.gemspec b/ext/fiddle/fiddle.gemspec
index befa7aeff5..cd9960f3ea 100644
--- a/ext/fiddle/fiddle.gemspec
+++ b/ext/fiddle/fiddle.gemspec
@@ -1,18 +1,13 @@
 # frozen_string_literal: true
 
-source_version = ["", "ext/fiddle/"].find do |dir|
-  begin
-    break File.open(File.join(__dir__, "#{dir}lib/fiddle/version.rb")) {|f|
-      f.gets("\n  VERSION = ")
-      f.gets[/\s*"(.+)"/, 1]
-    }
-  rescue Errno::ENOENT
-  end
+if defined?(Fiddle::VERSION)
+  Fiddle.__send__(:remove_const, :VERSION)
 end
+require_relative "lib/fiddle/version"
 
 Gem::Specification.new do |spec|
   spec.name          = "fiddle"
-  spec.version       = source_version
+  spec.version       = Fiddle::VERSION
   spec.authors       = ["Aaron Patterson", "SHIBATA Hiroshi"]
   spec.email         = ["[email protected]", "[email protected]"]
 

from fiddle.

kou avatar kou commented on August 22, 2024

Or:

diff --git a/ext/fiddle/fiddle.gemspec b/ext/fiddle/fiddle.gemspec
index befa7aeff5..a6c8c9be00 100644
--- a/ext/fiddle/fiddle.gemspec
+++ b/ext/fiddle/fiddle.gemspec
@@ -1,18 +1,13 @@
 # frozen_string_literal: true
 
-source_version = ["", "ext/fiddle/"].find do |dir|
-  begin
-    break File.open(File.join(__dir__, "#{dir}lib/fiddle/version.rb")) {|f|
-      f.gets("\n  VERSION = ")
-      f.gets[/\s*"(.+)"/, 1]
-    }
-  rescue Errno::ENOENT
-  end
+version_module = Module.new do
+  version_rb = File.join(__dir__, "lib/fiddle/version.rb")
+  module_eval(File.read(version_rb), version_rb)
 end
 
 Gem::Specification.new do |spec|
   spec.name          = "fiddle"
-  spec.version       = source_version
+  spec.version       = version_module::Fiddle::VERSION
   spec.authors       = ["Aaron Patterson", "SHIBATA Hiroshi"]
   spec.email         = ["[email protected]", "[email protected]"]
 

from fiddle.

mame avatar mame commented on August 22, 2024

I'm okay for any solution including your first one! I just let you be aware of the potential risk.

from fiddle.

kou avatar kou commented on August 22, 2024

OK. I'll use the last one.

from fiddle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.