Skip to content

Use Bundler.load.specs instead of reading Gemfile.lock #2363

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KaanOzkan
Copy link
Contributor

@KaanOzkan KaanOzkan commented Jul 23, 2025

Motivation

Resolves #2355

Implementation

annotations command parses the lockfile to get a list of gem names, we can get it from Bundler.definition instead.

Tests

@samuel-williams-shopify

This looks good but maybe some minor issue:

async-rbs (rbs)> bundle exec tapioca init
/Users/samuel/.gem/ruby/ruby-head/gems/rbs-4.0.0.dev.4/lib/rbs.rb:11: warning: tsort was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.6.0
You can add tsort to your Gemfile or gemspec to silence this warning.
   identical  sorbet/config
   identical  sorbet/tapioca/config.yml
   identical  sorbet/tapioca/require.rb
       force  bin/tapioca
Retrieving index from central repository... Done
Listing gems from bundle... bundler: failed to load command: tapioca (/Users/samuel/.gem/ruby/ruby-head/bin/tapioca)
/Users/samuel/.gem/ruby/ruby-head/bundler/gems/tapioca-a3dd3c0fa023/lib/tapioca/gem_info.rb:12:in 'block in singleton class': uninitialized constant Tapioca::Gem::Specification (NameError)
	from /Users/samuel/.gem/ruby/ruby-head/gems/sorbet-runtime-0.5.12356/lib/types/private/methods/_methods.rb:360:in 'BasicObject#instance_exec'
	from /Users/samuel/.gem/ruby/ruby-head/gems/sorbet-runtime-0.5.12356/lib/types/private/methods/_methods.rb:360:in 'T::Private::Methods.run_builder'
	from /Users/samuel/.gem/ruby/ruby-head/gems/sorbet-runtime-0.5.12356/lib/types/private/methods/_methods.rb:338:in 'T::Private::Methods.run_sig'

@samuel-williams-shopify

(Feel free to edit/remove my change - I just wanted to see if this fixed CI).

@KaanOzkan KaanOzkan force-pushed the ko/annotations-bundler branch 3 times, most recently from 12ad8ec to 1a81625 Compare July 25, 2025 14:41
@KaanOzkan KaanOzkan marked this pull request as ready for review July 25, 2025 15:29
@KaanOzkan KaanOzkan requested a review from a team as a code owner July 25, 2025 15:29
@amomchilov amomchilov changed the title Use Bundler.load.specs instead of reading Gemfile.lock Use Bundler.load.specs instead of reading Gemfile.lock Jul 25, 2025
gemfile = Bundler.read_file("Gemfile.lock")
parser = Bundler::LockfileParser.new(gemfile)
gem_info = parser.specs.map { |spec| GemInfo.from_spec(spec) }
say("Listing gems from bundle... ", [:blue, :bold])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
say("Listing gems from bundle... ", [:blue, :bold])
lockfile_path = Bundler.definition.lockfile.basename
say("Listing gems from #{lockfile_path}... ", [:blue, :bold])

@@ -22,7 +22,7 @@ class AnnotationsTest < SpecWithProject

assert_stdout_equals(<<~OUT, result)
Retrieving index from central repository... Done
Listing gems from Gemfile.lock... Done
Listing gems from bundle... Done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Listing gems from bundle... Done
Listing gems from Gemfile.lock... Done

Can we add a test for Gems.rb, and comment that it's the old name of the file, supported for backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test.

@KaanOzkan KaanOzkan force-pushed the ko/annotations-bundler branch from 1a81625 to 1661a46 Compare July 28, 2025 15:34
@KaanOzkan KaanOzkan force-pushed the ko/annotations-bundler branch from 1661a46 to 4ec0561 Compare July 28, 2025 15:55
@KaanOzkan KaanOzkan requested a review from amomchilov July 28, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bundle exec tapioca init fails with No such file or directory @ rb_sysopen - Gemfile.lock when using gems.rb
3 participants