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

Fix Bootsnap to work with Ruby 3.0 #264

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

Conversation

RicardoTrindade
Copy link

Due to the changes in keyword arguments for Ruby 3.0 I believe the bootsnap integration stopped working.
This PR updates the Bootsnap.setup method call to use ** operator and get around the initialization issue.
Since dry-system requires ruby 3.0 or higher I've updated the condition to check if bootsnap was available.
Also uncommented a test for bootsnap. I've added an empty file to get the test working but I'm open to other suggestions

Stacktrace from an example repo I created to show the issue
https://github.com/RicardoTrindade/Bootsnap-example

Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.15.0/lib/bootsnap.rb:38:in `setup': wrong number of arguments (given 1, expected 0; required keyword: cache_dir) (ArgumentError)
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/plugins/bootsnap.rb:35:in `setup_bootsnap'
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/container.rb:129:in `instance_eval'
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/container.rb:129:in `block in configured!'
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/container.rb:129:in `each'
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/container.rb:129:in `configured!'
	from /Users/ricardot/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/dry-system-1.0.1/lib/dry/system/container.rb:108:in `configure'
	from /Users/ricardot/Documents/github/forks/Bootsnap-example/lib/app.rb:10:in `<class:App>'
	from /Users/ricardot/Documents/github/forks/Bootsnap-example/lib/app.rb:5:in `<top (required)>'
	from /Users/ricardot/Documents/github/forks/Bootsnap-example/config.ru:6:in `require_relative'
	from /Users/ricardot/Documents/github/forks/Bootsnap-example/config.ru:6:in `block in <main>'

end

# @api private
def bootsnap_available?
RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.3.0" && RUBY_VERSION < "3.1.0"
RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0.0" && RUBY_VERSION < "3.1.0"
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the upper bound be removed? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Oh sure, removed the < 3.1.0 condition

@flash-gordon
Copy link
Member

@RicardoTrindade something's broken in CI? Mind to take a look?

lib/dry/system/plugins/bootsnap.rb Show resolved Hide resolved
@@ -5,11 +5,9 @@ module System
module Plugins
module Bootsnap
DEFAULT_OPTIONS = {
load_path_cache: true,
disable_trace: true,
load_path_cache: false,
Copy link
Author

Choose a reason for hiding this comment

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

had to change this from true to false to get CI passing once again. with the option as true, some specs would fail with the error below that I haven't been able to figure out what is causing it

  11) Container / Imports / Exports exports configured as a list of keys importing container is lazy loading does not finalize either container
      Failure/Error: raise ComponentNotLoadableError.new(component, e)
      
      Dry::System::ComponentNotLoadableError:
        Component 'exportable_component_a' is not loadable.
        Looking for Test::ExportableComponentA.
      
        Did you mean?  ExternalComponents
      
                    raise ComponentNotLoadableError.new(component, e)
                    ^^^^^
      # ./lib/dry/system/loader.rb:71:in `rescue in constant'
      # ./lib/dry/system/loader.rb:64:in `constant'
      # ./lib/dry/system/loader.rb:49:in `call'
      # ./lib/dry/system/component.rb:64:in `instance'
      # ./lib/dry/system/container.rb:639:in `block in load_local_component'
      # ./lib/dry/system/container.rb:493:in `resolve'
      # ./lib/dry/system/container.rb:516:in `key?'
      # ./lib/dry/system/importer.rb:109:in `block in build_merge_container'
      # ./lib/dry/system/importer.rb:108:in `each'
      # ./lib/dry/system/importer.rb:108:in `each_with_object'
      # ./lib/dry/system/importer.rb:108:in `build_merge_container'
      # ./lib/dry/system/importer.rb:86:in `import_keys'
      # ./lib/dry/system/importer.rb:69:in `import'
      # ./lib/dry/system/container.rb:648:in `load_imported_component'
      # ./lib/dry/system/container.rb:626:in `load_component'
      # ./lib/dry/system/container.rb:491:in `resolve'
      # ./spec/integration/container/importing/exports_spec.rb:76:in `block (4 levels) in <top (required)>'
      # ------------------
      # --- Caused by: ---
      # NameError:
      #   uninitialized constant Test::ExportableComponentA
      #   
      #         Object.const_get(input, false)
      #               ^^^^^^^^^^
      #   Did you mean?  ExternalComponents
      #   ./lib/dry/system/loader.rb:67:in `constant'


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

Successfully merging this pull request may close these issues.

None yet

2 participants