open3 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f598d530ced19be109f452253e266841b9c00d71e96687d31c2e5fa5db86957
4
- data.tar.gz: be2ec8a86eeaa8e60907e9c95268d6b65ef3b477083051054a6adb1521a0fceb
3
+ metadata.gz: b3ab5dfcb825c74af61129ee82254609322af777421f454eb90053875bdbc851
4
+ data.tar.gz: fdf3f7c0783de3763390a6e62a7ec984f262d61ca5d8906e186ad7e7deeff5d2
5
5
  SHA512:
6
- metadata.gz: c327ed7dd6b0769dd17809b7b155028ea6604364ce6a123b5f59d7f9a98ffe4e078e170f0268fb5eccdfc96a10bf9d284bdd85391052b104469906d410e010e9
7
- data.tar.gz: b641d417656c67cd4199a0592ef71dc24d852fda7084cf31b89e4172eebf91e660f585a3213ab8257cfa942fa928be5ee7fc8dd2b693a76605b0f9acd38f1033
6
+ metadata.gz: 3e3508856456efd5c0700447c9e122163ea490b32a7bd4cc09d2d4fa79639b53baac5b8f45d983e5185dd439c93cfba2b546c302569e1dccf6d4086c0a3b0858
7
+ data.tar.gz: a79fd57d1a714b793ecc3849231cf3d58fd07bcc962ffad144b98ec7443d8da1642e97ab10e6f251c720cc9d0cfe72a809fb71c0c915226fcbed0b2a1c607839
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -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
@@ -7,18 +7,15 @@ jobs:
7
7
  name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
8
  strategy:
9
9
  matrix:
10
- ruby: [ 2.7, 2.6, head ]
10
+ ruby: [ '3.0', 2.7, 2.6, head ]
11
11
  os: [ ubuntu-latest, macos-latest ]
12
12
  runs-on: ${{ matrix.os }}
13
13
  steps:
14
- - uses: actions/checkout@master
14
+ - uses: actions/checkout@v3
15
15
  - name: Set up Ruby
16
16
  uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby }}
19
- - name: Install dependencies
20
- run: |
21
- gem install bundler --no-document
22
- bundle install
19
+ bundler-cache: true # 'bundle install' and cache
23
20
  - name: Run test
24
- run: rake test
21
+ run: bundle exec rake test
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  task :sync_tool do
11
11
  require 'fileutils'
12
- FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
12
+ FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
13
13
  FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14
14
  FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15
15
  end
@@ -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
@@ -0,0 +1,3 @@
1
+ module Open3
2
+ VERSION = "0.1.2"
3
+ end
data/lib/open3.rb CHANGED
@@ -29,8 +29,9 @@
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
- VERSION = "0.1.1"
34
35
 
35
36
  # Open stdin, stdout, and stderr streams and start external executable.
36
37
  # In addition, a thread to wait for the started process is created.
@@ -758,3 +759,6 @@ module Open3
758
759
  end
759
760
 
760
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,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  name = File.basename(__FILE__, ".gemspec")
4
- version = ["lib", Array.new(name.count("-"), "..").join("/")].find do |dir|
5
- break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
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
6
  /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7
7
  end rescue nil
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-22 00:00:00.000000000 Z
11
+ date: 2022-12-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Popen, but with stderr, too
14
14
  email:
@@ -17,6 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/dependabot.yml"
21
+ - ".github/workflows/test-jruby.yml"
20
22
  - ".github/workflows/test.yml"
21
23
  - ".gitignore"
22
24
  - Gemfile
@@ -26,6 +28,8 @@ files:
26
28
  - bin/console
27
29
  - bin/setup
28
30
  - lib/open3.rb
31
+ - lib/open3/jruby_windows.rb
32
+ - lib/open3/version.rb
29
33
  - open3.gemspec
30
34
  homepage: https://github.com/ruby/open3
31
35
  licenses:
@@ -49,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
53
  - !ruby/object:Gem::Version
50
54
  version: '0'
51
55
  requirements: []
52
- rubygems_version: 3.2.2
56
+ rubygems_version: 3.4.0.dev
53
57
  signing_key:
54
58
  specification_version: 4
55
59
  summary: Popen, but with stderr, too