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

Allow http 5-x #55

Merged
merged 5 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use http 4.x for ruby 2.4 and 2.3
  • Loading branch information
mgrunberg committed May 17, 2021
commit 9d2d92f7d7b593a6a0db05dee8abde80defa6455
6 changes: 5 additions & 1 deletion down.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest", "~> 5.8"
spec.add_development_dependency "mocha", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "http", "~> 5.0"
if RUBY_VERSION >= "2.5"
spec.add_development_dependency "http", "~> 5.0"
else
spec.add_development_dependency "http", "~> 4.3"
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't actually work to do what you want, I'm afraid.

Logic in a gemspec is executed at build time, so which of these gets included will depend on what version of ruby the releaser was using.

There isn't any way to do conditional logic in a gemspec like this that applies at runtime/execution time different for different apps.

However... I'm confused that this is only a development dependency not an actual runtime dependency... maybe this is ok? Is this really only about CI? But it's very confusing/misleading, and will result in a gem released to rubygems whose development_dependency for http depends on what version of ruby the releaser was running...

I am not sure what to do, but I think ideally there is a different solution than this. Or at least some very explicit comments. Because this sort of thing is an error people make in gemspecs a lot, and 99% of the time it is an error, and causes big problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't actually work to do what you want, I'm afraid.

Logic in a gemspec is executed at build time, so which of these gets included will depend on what version of ruby the releaser was using.

There isn't any way to do conditional logic in a gemspec like this that applies at runtime/execution time different for different apps.

However... I'm confused that this is only a development dependency not an actual runtime dependency... maybe this is ok? Is this really only about CI? But it's very confusing/misleading, and will result in a gem released to rubygems whose development_dependency for http depends on what version of ruby the releaser was running...

I am not sure what to do, but I think ideally there is a different solution than this. Or at least some very explicit comments. Because this sort of thing is an error people make in gemspecs a lot, and 99% of the time it is an error, and causes big problems.

I will try to do my best to explain what lead me to this solution.

down has several backends (readme). You don't always need http gem to use down. If you use the default backend, there is no point in adding http to your system. This is by, as I understand, it's not a gemspec dependency.

It's needed as a development_dependency to test Down::Http backend. But also because some specs use it to build the expected result (example) and because test_helper uses it to wait for a service.

Since http drop ruby 2.3 and 2.4 support down could do the same. That's fair. But users running old rubies (2.3 and 2.4 have reached EOL) can still use Down::Http if they use 4.x version. Drop old rubies support is not a requirement to use http 5.0, so I took the conservative alternative and let specs run with 4.x on old rubies (asserting that this works).

Why the condition logic is in the gemspec and not in another place (Gemfile for example)? Because there are already some development_dependencies handled that way.

spec.add_development_dependency "posix-spawn" unless RUBY_ENGINE == "jruby"
spec.add_development_dependency "http_parser.rb"
spec.add_development_dependency "docker-api"
Expand Down
5 changes: 5 additions & 0 deletions test/support/warnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
require "warning"

Warning.process('', /instance variable @\w+ not initialized/ => :raise)

# ruby 2.5 or higher uses http.rb 5.0 which doesn't have http-parser as a dependency
if RUBY_VERSION < "2.5"
Warning.ignore(/interpreted as argument prefix/, Gem::Specification.find_by_name("http-parser").load_paths.first)
end
end