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
Allow extra runtime deps to be defined when using prune_bundler #1105
Merged
+144
−11
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fda186e
Allow extra runtime deps to be defined when using prune_bundler
daveallie 26f6a06
Check extra_runtime_dependencies is set before iterating over them
daveallie 7a6e6cb
Load additional paths for extra runtime dep gems
daveallie 7b6e0b5
Don't load extra dependencies, just add their paths to $LOAD_PATH
daveallie cd0854b
Fix typos and extraneous checks and rescues
daveallie 62d3b69
Use Gem::Specification#full_require_paths when available
daveallie c1a28a9
Prevent use of prune_bundler and extra_runtime_dependencies with earl…
daveallie 3f1eae5
Ensure LOAD_PATH is modified by extra_runtime_dependencies
daveallie 86d6ffc
Refactor prune_bundler in launcher.rb and write some unit tests
daveallie File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
prune_bundler true | ||
extra_runtime_dependencies ["rdoc"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run lambda { |env| | ||
[200, {}, [$LOAD_PATH[-1]]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require_relative "helper" | ||
|
||
require "puma/configuration" | ||
require "puma/const" | ||
require "puma/launcher" | ||
|
||
class TestLauncher < Minitest::Test | ||
def test_dependencies_and_files_to_require_after_prune_is_correctly_built_for_no_extra_deps | ||
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MSP-Greg there's no bundler on appveyor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MSP-Greg 👋 just wondering as I don’t understand why this is a thing |
||
|
||
l = Puma::Launcher.new Puma::Configuration.new | ||
deps, dirs = l.send(:dependencies_and_files_to_require_after_prune) | ||
|
||
assert_equal(1, deps.length) | ||
assert_match(%r{^nio4r:[\d.]+$}, deps.first) | ||
assert_equal(2, dirs.length) | ||
assert_match(%r{puma/lib$}, dirs[0]) # lib dir | ||
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir | ||
end | ||
|
||
def test_dependencies_and_files_to_require_after_prune_is_correctly_built_with_extra_deps | ||
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable" | ||
|
||
conf = Puma::Configuration.new do |c| | ||
c.extra_runtime_dependencies ['rdoc'] | ||
end | ||
l = Puma::Launcher.new conf | ||
deps, dirs = l.send(:dependencies_and_files_to_require_after_prune) | ||
|
||
assert_equal(1, deps.length) | ||
assert_match(%r{^nio4r:[\d.]+$}, deps.first) | ||
assert_equal(3, dirs.length) | ||
assert_match(%r{puma/lib$}, dirs[0]) # lib dir | ||
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir | ||
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dirs[2]) # rdoc dir | ||
end | ||
|
||
def test_extra_runtime_deps_directories_is_empty_for_no_config | ||
l = Puma::Launcher.new Puma::Configuration.new | ||
assert_equal([], l.send(:extra_runtime_deps_directories)) | ||
end | ||
|
||
def test_extra_runtime_deps_directories_is_correctly_built | ||
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable" | ||
conf = Puma::Configuration.new do |c| | ||
c.extra_runtime_dependencies ['rdoc'] | ||
end | ||
l = Puma::Launcher.new conf | ||
dep_dirs = l.send(:extra_runtime_deps_directories) | ||
|
||
assert_equal(1, dep_dirs.length) | ||
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dep_dirs.first) | ||
end | ||
|
||
def test_puma_wild_location_is_an_absolute_path | ||
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable" | ||
l = Puma::Launcher.new Puma::Configuration.new | ||
puma_wild_location = l.send(:puma_wild_location) | ||
assert_match(%r{bin/puma-wild$}, puma_wild_location) | ||
# assert no "/../" in path | ||
refute_match(%r{/\.\./}, puma_wild_location) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, we're actually requiring Rubygems 2.2+ to use prune_bundler at all now, is that correct?
I'm actually OK with that as well (again, rubygems 2.2+ is older than ruby 2.2) but we need to gate the code on that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, you've done a fallback instead.
I'm wondering if we should even do that. I think I sort of proved in the comments of this PR that the original implementation was bugged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just planning on straight-up raising on attempts to use the feature without rubygems 2.2+ (85c7f21#diff-d9e00ab028817951ecfdbbe7e661a141R471) instead of silently failing. The fallback codepath here is because this method is now used to find the puma lib dir. Previously it was just the fallback line, run inline. Now it's the preferred codepath for clients with rubygems 2.2+ but we still support the old codepath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that the old codepath is clearly bugged.
Try this script and you'll see what I mean:
The latter line, for me, outputs nonsense like:
...which does not exist.
There's not really a point in maintaining a 2nd codepath that doesn't actually work, so we need to either remove the path or fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puma's requiring Ruby >= 2.2.0, which shipped with RubyGems 2.4.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unfamiliar with what "shipped with" means exactly in this context. Is it possible that anyone is using Ruby 2.2 or greater with Rubygems 2.3 or less?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. It's possible, but Ruby 2.2.0 included RubyGems 2.4.5 as a std-lib.
'Shipped with' <=> 'included'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Well I'd rather provide a feature that works over one that doesn't, so our choices are to:
a) copy the entire implementation of
full_require_paths
to this file and then remove the rubygems gateb) remove the branch, and gate the entire feature of prune_bundler on Rubygems 2.2+
I am fine with either option.