open3 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test-jruby.yml +21 -0
- data/.github/workflows/test.yml +21 -0
- data/Rakefile +7 -0
- data/lib/open3/jruby_windows.rb +127 -0
- data/lib/open3/version.rb +1 -1
- data/lib/open3.rb +12 -0
- data/open3.gemspec +15 -9
- metadata +14 -10
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3ab5dfcb825c74af61129ee82254609322af777421f454eb90053875bdbc851
|
4
|
+
data.tar.gz: fdf3f7c0783de3763390a6e62a7ec984f262d61ca5d8906e186ad7e7deeff5d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e3508856456efd5c0700447c9e122163ea490b32a7bd4cc09d2d4fa79639b53baac5b8f45d983e5185dd439c93cfba2b546c302569e1dccf6d4086c0a3b0858
|
7
|
+
data.tar.gz: a79fd57d1a714b793ecc3849231cf3d58fd07bcc962ffad144b98ec7443d8da1642e97ab10e6f251c720cc9d0cfe72a809fb71c0c915226fcbed0b2a1c607839
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ 2.7, 2.6, head, jruby-9.3 ]
|
11
|
+
os: [ ubuntu-latest, macos-latest ]
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
bundler-cache: true # 'bundle install' and cache
|
20
|
+
- name: Run test
|
21
|
+
run: bundle exec rake test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ '3.0', 2.7, 2.6, head ]
|
11
|
+
os: [ ubuntu-latest, macos-latest ]
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
bundler-cache: true # 'bundle install' and cache
|
20
|
+
- name: Run test
|
21
|
+
run: bundle exec rake test
|
data/Rakefile
CHANGED
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
|
|
7
7
|
t.test_files = FileList["test/**/test_*.rb"]
|
8
8
|
end
|
9
9
|
|
10
|
+
task :sync_tool do
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
|
+
end
|
16
|
+
|
10
17
|
task :default => :test
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#
|
2
|
+
# Custom implementation of Open3.popen{3,2,2e} that uses java.lang.ProcessBuilder rather than pipes and spawns.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'jruby' # need access to runtime for RubyStatus construction
|
6
|
+
|
7
|
+
module Open3
|
8
|
+
|
9
|
+
java_import java.lang.ProcessBuilder
|
10
|
+
java_import org.jruby.RubyProcess
|
11
|
+
java_import org.jruby.util.ShellLauncher
|
12
|
+
|
13
|
+
def popen3(*cmd, &block)
|
14
|
+
if cmd.size > 0 && Hash === cmd[-1]
|
15
|
+
opts = cmd.pop
|
16
|
+
else
|
17
|
+
opts = {}
|
18
|
+
end
|
19
|
+
processbuilder_run(cmd, opts, io: IO_3, &block)
|
20
|
+
end
|
21
|
+
module_function :popen3
|
22
|
+
|
23
|
+
IO_3 = proc do |process|
|
24
|
+
[process.getOutputStream.to_io, process.getInputStream.to_io, process.getErrorStream.to_io]
|
25
|
+
end
|
26
|
+
|
27
|
+
BUILD_2 = proc do |builder|
|
28
|
+
builder.redirectError(ProcessBuilder::Redirect::INHERIT)
|
29
|
+
end
|
30
|
+
|
31
|
+
IO_2 = proc do |process|
|
32
|
+
[process.getOutputStream.to_io, process.getInputStream.to_io]
|
33
|
+
end
|
34
|
+
|
35
|
+
def popen2(*cmd, &block)
|
36
|
+
if cmd.size > 0 && Hash === cmd[-1]
|
37
|
+
opts = cmd.pop
|
38
|
+
else
|
39
|
+
opts = {}
|
40
|
+
end
|
41
|
+
processbuilder_run(cmd, opts, build: BUILD_2, io: IO_2, &block)
|
42
|
+
end
|
43
|
+
module_function :popen2
|
44
|
+
|
45
|
+
BUILD_2E = proc do |builder|
|
46
|
+
builder.redirectErrorStream(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
def popen2e(*cmd, &block)
|
50
|
+
if cmd.size > 0 && Hash === cmd[-1]
|
51
|
+
opts = cmd.pop
|
52
|
+
else
|
53
|
+
opts = {}
|
54
|
+
end
|
55
|
+
processbuilder_run(cmd, opts, build: BUILD_2E, io: IO_2, &block)
|
56
|
+
end
|
57
|
+
module_function :popen2e
|
58
|
+
|
59
|
+
def processbuilder_run(cmd, opts, build: nil, io:)
|
60
|
+
opts.each do |k, v|
|
61
|
+
if Integer === k
|
62
|
+
if IO == v || !(String === v || v.respond_to?(:to_path))
|
63
|
+
# target is an open IO or a non-pathable object, bail out
|
64
|
+
raise NotImplementedError.new("redirect to an open IO is not implemented on this platform")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if Hash === cmd[0]
|
70
|
+
env = cmd.shift;
|
71
|
+
else
|
72
|
+
env = {}
|
73
|
+
end
|
74
|
+
|
75
|
+
if cmd.size == 1 && (cmd[0] =~ / / || ShellLauncher.shouldUseShell(cmd[0]))
|
76
|
+
cmd = [RbConfig::CONFIG['SHELL'], JRuby::Util::ON_WINDOWS ? '/c' : '-c', cmd[0]]
|
77
|
+
end
|
78
|
+
|
79
|
+
builder = ProcessBuilder.new(cmd.to_java(:string))
|
80
|
+
|
81
|
+
builder.directory(java.io.File.new(opts[:chdir] || Dir.pwd))
|
82
|
+
|
83
|
+
environment = builder.environment
|
84
|
+
env.each { |k, v| v.nil? ? environment.remove(k) : environment.put(k, v) }
|
85
|
+
|
86
|
+
build.call(builder) if build
|
87
|
+
|
88
|
+
process = builder.start
|
89
|
+
|
90
|
+
pid = org.jruby.util.ShellLauncher.getPidFromProcess(process)
|
91
|
+
|
92
|
+
parent_io = io.call(process)
|
93
|
+
|
94
|
+
parent_io.each {|i| i.sync = true}
|
95
|
+
|
96
|
+
wait_thr = DetachThread.new(pid) { RubyProcess::RubyStatus.newProcessStatus(JRuby.runtime, process.waitFor << 8, pid) }
|
97
|
+
|
98
|
+
result = [*parent_io, wait_thr]
|
99
|
+
|
100
|
+
if defined? yield
|
101
|
+
begin
|
102
|
+
return yield(*result)
|
103
|
+
ensure
|
104
|
+
parent_io.each(&:close)
|
105
|
+
wait_thr.join
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
result
|
110
|
+
end
|
111
|
+
module_function :processbuilder_run
|
112
|
+
class << self
|
113
|
+
private :processbuilder_run
|
114
|
+
end
|
115
|
+
|
116
|
+
class DetachThread < Thread
|
117
|
+
attr_reader :pid
|
118
|
+
|
119
|
+
def initialize(pid)
|
120
|
+
super
|
121
|
+
|
122
|
+
@pid = pid
|
123
|
+
self[:pid] = pid
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
data/lib/open3/version.rb
CHANGED
data/lib/open3.rb
CHANGED
@@ -29,6 +29,8 @@
|
|
29
29
|
# - Open3.pipeline : run a pipeline and wait for its completion
|
30
30
|
#
|
31
31
|
|
32
|
+
require 'open3/version'
|
33
|
+
|
32
34
|
module Open3
|
33
35
|
|
34
36
|
# Open stdin, stdout, and stderr streams and start external executable.
|
@@ -206,6 +208,13 @@ module Open3
|
|
206
208
|
opts[[:out, :err]] = out_w
|
207
209
|
|
208
210
|
popen_run(cmd, opts, [in_r, out_w], [in_w, out_r], &block)
|
211
|
+
ensure
|
212
|
+
if block
|
213
|
+
in_r.close
|
214
|
+
in_w.close
|
215
|
+
out_r.close
|
216
|
+
out_w.close
|
217
|
+
end
|
209
218
|
end
|
210
219
|
module_function :popen2e
|
211
220
|
|
@@ -750,3 +759,6 @@ module Open3
|
|
750
759
|
end
|
751
760
|
|
752
761
|
end
|
762
|
+
|
763
|
+
# JRuby uses different popen logic on Windows, require it here to reuse wrapper methods above.
|
764
|
+
require 'open3/jruby_windows' if RUBY_ENGINE == 'jruby' && JRuby::Util::ON_WINDOWS
|
data/open3.gemspec
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
name = File.basename(__FILE__, ".gemspec")
|
4
|
+
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
|
5
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}/version.rb")) do |line|
|
6
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
7
|
+
end rescue nil
|
8
|
+
end
|
4
9
|
|
5
10
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
7
|
-
spec.version =
|
8
|
-
spec.authors = ["
|
9
|
-
spec.email = ["
|
11
|
+
spec.name = name
|
12
|
+
spec.version = version
|
13
|
+
spec.authors = ["Yukihiro Matsumoto"]
|
14
|
+
spec.email = ["matz@ruby-lang.org"]
|
10
15
|
|
11
16
|
spec.summary = %q{Popen, but with stderr, too}
|
12
17
|
spec.description = spec.summary
|
13
18
|
spec.homepage = "https://github.com/ruby/open3"
|
14
|
-
spec.
|
19
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
20
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
21
|
|
16
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
23
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -19,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
19
25
|
# Specify which files should be added to the gem when it is released.
|
20
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
27
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
29
|
end
|
24
30
|
spec.bindir = "exe"
|
25
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Yukihiro Matsumoto
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Popen, but with stderr, too
|
14
14
|
email:
|
15
|
-
-
|
15
|
+
- matz@ruby-lang.org
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/dependabot.yml"
|
21
|
+
- ".github/workflows/test-jruby.yml"
|
22
|
+
- ".github/workflows/test.yml"
|
20
23
|
- ".gitignore"
|
21
|
-
- ".travis.yml"
|
22
24
|
- Gemfile
|
23
25
|
- LICENSE.txt
|
24
26
|
- README.md
|
@@ -26,15 +28,17 @@ files:
|
|
26
28
|
- bin/console
|
27
29
|
- bin/setup
|
28
30
|
- lib/open3.rb
|
31
|
+
- lib/open3/jruby_windows.rb
|
29
32
|
- lib/open3/version.rb
|
30
33
|
- open3.gemspec
|
31
34
|
homepage: https://github.com/ruby/open3
|
32
35
|
licenses:
|
36
|
+
- Ruby
|
33
37
|
- BSD-2-Clause
|
34
38
|
metadata:
|
35
39
|
homepage_uri: https://github.com/ruby/open3
|
36
40
|
source_code_uri: https://github.com/ruby/open3
|
37
|
-
post_install_message:
|
41
|
+
post_install_message:
|
38
42
|
rdoc_options: []
|
39
43
|
require_paths:
|
40
44
|
- lib
|
@@ -42,15 +46,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
46
|
requirements:
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
49
|
+
version: 2.6.0
|
46
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
51
|
requirements:
|
48
52
|
- - ">="
|
49
53
|
- !ruby/object:Gem::Version
|
50
54
|
version: '0'
|
51
55
|
requirements: []
|
52
|
-
rubygems_version: 3.0.
|
53
|
-
signing_key:
|
56
|
+
rubygems_version: 3.4.0.dev
|
57
|
+
signing_key:
|
54
58
|
specification_version: 4
|
55
59
|
summary: Popen, but with stderr, too
|
56
60
|
test_files: []
|