-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Print bundle install
output in rails new
as soon as it's available
#19429
Print bundle install
output in rails new
as soon as it's available
#19429
Conversation
output = `"#{Gem.ruby}" "#{_bundle_command}" #{command}` | ||
print output unless options[:quiet] | ||
full_command = "\"#{Gem.ruby}\" \"#{_bundle_command}\" #{command}" | ||
Open3.popen2e(full_command) do |_in, out_and_err, _thread| |
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.
Does it works on windows machine?
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.
@rafaelfranca Yes. I tested it on a Windows 7 VM.
6c25512
to
d50a207
Compare
I added a fix for the failing test and squashed my commit. The build is now passing for this branch. The test was relying on |
That deadlock only happens if you try to read to EOF on one of the streams, doesn't it? So can't we just Not Do That? Actually, looking at the "why we use backticks instead of |
@matthewd honestly this whole deadlock thing was news to me so I may have misunderstood the problem and you might be right. Here's what I found after looking into this some more. I originally thought
But then I caught the bit of the documentation that mentions deadlocks:
You can get a deadlock to happen using my above implementation if you send enough to fill the pipe buffer on standard error before you send anything on standard out:
Now, you could say that bundler is pretty unlikely to output enough to standard error to fill the buffer on a single line, which is a good point, but I don't think We can solve this problem while still using
This works in Windows too. I initially picked To summarize, I think our options are:
@matthewd, @rafaelfranca what do you think? sorry for spending your time on something that is pretty minor! |
How about just adding a "This step might take some time. Please be patient" line ? |
None of those options seem to be my proposed "use If we're going to use popen3, I'd expect to use |
Ahh no you're not missing anything obvious. I was, sorry! So you're saying something like:
Yeah that looks much better and solves all the problems. This might make the intent more clear but I don't think would work on Windows:
I'll see if I can get something like that working on Windows and update the PR. Thanks @matthewd. sorry for my confusion. |
d50a207
to
219a033
Compare
Ok I updated and squashed. The build is passing. |
Looks good 👍 I'm open to being convinced otherwise, but I think we should generally let stderr through, even in "quiet" mode. If something's gone wrong, the user probably wants to know what it was. (See, e.g., Meanwhile, I'll refrain from asking (the universe in general, not you in particular) why we have to make this sort of decision at all, instead of just passing |
219a033
to
0d3dd7f
Compare
Ok I updated it to not redirect stderr to null in quiet mode. Yeah I thought about just passing |
@@ -326,8 +322,12 @@ def bundle_command(command) | |||
|
|||
require 'bundler' | |||
Bundler.with_clean_env do | |||
output = `"#{Gem.ruby}" "#{_bundle_command}" #{command}` | |||
print output unless options[:quiet] | |||
full_command = "\"#{Gem.ruby}\" \"#{_bundle_command}\" #{command}" |
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.
It might be better to use %Q[]
or something like that to build the string, to avoid escaping quotes.
It probably does not affect our tests, maybe it will add extra noise to some that check the output in case they fail, that might be ok. @matthewd do you have any other concern about this one? |
Previously, running `rails new` would not print any of the output from `bundle install` until all the gems had finished installing. This made it look like the generator was hanging at the `bundle install` step. This commit switches to using `system` so that the bundle command can output as it needs to. This has the added benefit of including output bundler produces on standard error, which the previous code ignored since backticks only capture standard out. This is not a big deal right now since bundler does not currently print errors to standard error, but that may change in the future (see: rubygems/bundler/issues/3353).
0d3dd7f
to
2a5bb9d
Compare
I updated it to use |
Sorry, I did have one other thought: can we test this? ("this" == the fact we don't buffer the output, I guess) Nothing simple comes to mind, but I figure I might as well raise the question, in case you have any ideas. |
Hmm that is a good idea but I can't really think of a good way to test this either. We could test that |
…e_by_line Print `bundle install` output in `rails new` as soon as it's available
Previously, running
rails new
would not print any of the output frombundle install
until all the gems had finished installing. This madeit look like the generator was hanging at the
bundle install
step.This is arguably a minor issue, but it can be confusing for new people.
This PR changes how we call the bundle command from using backticks
to using
Open3.popen2e
, allowing us to read each line of the output asbundler produces it.
This has the added benefit of including output bundler produces on
standard error, which the previous code ignored since backticks only
capture standard out. This is not a big deal right now since bundler
does not currently print errors to standard error, but that may change
in the future (see: rubygems/bundler/issues/3353).
The one downside here is that since we're using
Open3.popen2e
, we aremerging standard error and standard out, and outputting them both to
standard out. This is not ideal, but it removes the possibility for a
deadlock that could occur if we used
Open3.popen3
instead.