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

Remove posix runner and unsupported posix-spawn gem #19

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
source 'https://rubygems.org'

gemspec

platforms :ruby do
gem "posix-spawn"
end
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,22 @@ second argument of `new`. Terrapin assumes that you will not be manually
passing user-generated data to that argument and will be using it as a template
for your command line's structure.

## POSIX Spawn
## Runners

You can potentially increase performance by installing [the posix-spawn
gem](https://rubygems.org/gems/posix-spawn). This gem can keep your
application's heap from being copied when forking command line
processes. For applications with large heaps the gain can be
significant. To include `posix-spawn`, simply add it to your `Gemfile` or,
if you don't use bundler, install the gem.
Terrapin will choose from among a couple different ways of running commands.
The simplest is `Process.spawn`, which is also the default. Terrapin can also just use [backticks], so if for some reason you'd prefer that, you can ask Terrapin to use that:

## Runners
```ruby
Terrapin::CommandLine.runner = Terrapin::CommandLine::BackticksRunner.new
```

Terrapin will attempt to choose from among 3 different ways of running commands.
The simplest is using backticks, and is the default in 1.8. In Ruby 1.9, it
will attempt to use `Process.spawn`. And, as mentioned above, if the
`posix-spawn` gem is installed, it will attempt to use that. If for some reason
one of the `.spawn` runners don't work for you, you can override them manually
by setting a new runner, like so:
And if you really want to, you can define your own Runner, though I can't imagine why you would.

[backticks]: https://ruby-doc.org/3.2.1/Kernel.html#method-i-60

Terrapin::CommandLine.runner = Terrapin::CommandLine::BackticksRunner.new
And if you really want to, you can define your own Runner, though I can't
imagine why you would.

```ruby
Terrapin::CommandLine.runner = Terrapin::CommandLine::BackticksRunner.new
Expand Down
2 changes: 1 addition & 1 deletion lib/terrapin/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def unfake!
private

def best_runner
[PosixRunner, ProcessRunner, BackticksRunner].detect do |runner|
[ProcessRunner, BackticksRunner].detect do |runner|
runner.supported?
end.new
end
Expand Down
1 change: 0 additions & 1 deletion lib/terrapin/command_line/runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

require 'terrapin/command_line/runners/backticks_runner'
require 'terrapin/command_line/runners/process_runner'
require 'terrapin/command_line/runners/posix_runner'
require 'terrapin/command_line/runners/popen_runner'
require 'terrapin/command_line/runners/fake_runner'
49 changes: 0 additions & 49 deletions lib/terrapin/command_line/runners/posix_runner.rb

This file was deleted.

40 changes: 0 additions & 40 deletions spec/terrapin/command_line/runners/posix_runner_spec.rb

This file was deleted.

25 changes: 0 additions & 25 deletions spec/terrapin/runners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe "When picking a Runner" do
it "uses the BackticksRunner by default" do
Terrapin::CommandLine::ProcessRunner.stubs(:supported?).returns(false)
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(false)

cmd = Terrapin::CommandLine.new("echo", "hello")

Expand All @@ -12,34 +11,11 @@

it "uses the ProcessRunner on 1.9 and it's available" do
Terrapin::CommandLine::ProcessRunner.stubs(:supported?).returns(true)
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(false)

cmd = Terrapin::CommandLine.new("echo", "hello")
expect(cmd.runner.class).to eq(Terrapin::CommandLine::ProcessRunner)
end

it "uses the PosixRunner if the PosixRunner is available" do
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)

cmd = Terrapin::CommandLine.new("echo", "hello")
expect(cmd.runner.class).to eq(Terrapin::CommandLine::PosixRunner)
end

it "uses the BackticksRunner if the PosixRunner is available, but we told it to use Backticks all the time" do
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)
Terrapin::CommandLine.runner = Terrapin::CommandLine::BackticksRunner.new

cmd = Terrapin::CommandLine.new("echo", "hello")
expect(cmd.runner.class).to eq(Terrapin::CommandLine::BackticksRunner)
end

it "uses the BackticksRunner if the PosixRunner is available, but we told it to use Backticks" do
Terrapin::CommandLine::PosixRunner.stubs(:supported?).returns(true)

cmd = Terrapin::CommandLine.new("echo", "hello", :runner => Terrapin::CommandLine::BackticksRunner.new)
expect(cmd.runner.class).to eq(Terrapin::CommandLine::BackticksRunner)
end

it "can go into 'Fake' mode" do
Terrapin::CommandLine.fake!

Expand Down Expand Up @@ -78,7 +54,6 @@
[
Terrapin::CommandLine::BackticksRunner,
Terrapin::CommandLine::PopenRunner,
Terrapin::CommandLine::PosixRunner,
Terrapin::CommandLine::ProcessRunner
].each do |runner_class|
if runner_class.supported?
Expand Down