lino 3.2.0.pre.6 → 3.2.0.pre.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1dd66849dd6c056a887e3db11f3b7e4ce81fe79977803e756295b432782990d
4
- data.tar.gz: dd084ea5d3d3e2399e17e3bf560fd5452094623218c0b3124e4ed2749e9abfc7
3
+ metadata.gz: da0833b0822fedee12bfa81350d5e87a69ef51bb9b4abc7f9f4537d5b851d3fe
4
+ data.tar.gz: f3bc82e3a0f6af9b1ae512a8db77b01626b39b089616371a35bb523a625a3551
5
5
  SHA512:
6
- metadata.gz: efbe7f4fea738bceb5ae5e148de4591e0a635a0c67923e30eb69f9503723d2bb70eb28911fd1addde172218d217de1cb27a9d3237293759b323a341c964ba3af
7
- data.tar.gz: 38833fa7c9b6c9c91e1056099fa4f3d0fe35117c624cb20bc7e265ad234a27613fa5f8f13176a148b0690bf60368d4919a0263d455e1faebdb1922801548995c
6
+ metadata.gz: e901b165f5fa1da7678057e04217b90558f7ef19f788b575e1dd3e1a5af825615e46040c33c24135899af5fa1ca1d8b150b83f225aeff568facc3498a2092f95
7
+ data.tar.gz: 9bd2103be29ad1026863b39df46a33d2a9618343d06ce517a01558087d6f18a85501c9a3a12fb04ab526ac6a22b56a9d8f29f0ee4269cf5b4ba013da3c5a1b58
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (3.2.0.pre.6)
4
+ lino (3.2.0.pre.8)
5
5
  childprocess (~> 5.0.0)
6
6
  hamster (~> 3.0)
7
7
  open4 (~> 1.3)
@@ -5,8 +5,8 @@ module Lino
5
5
  module Mixins
6
6
  module Executor
7
7
  def initialize(state)
8
- @executor = state[:executor] || Executors::Childprocess.new
9
8
  super
9
+ @executor = state[:executor] || Lino.configuration.executor
10
10
  end
11
11
 
12
12
  def with_executor(executor)
@@ -17,7 +17,7 @@ module Lino
17
17
 
18
18
  exit_code = process.wait
19
19
 
20
- return unless exit_code != 0
20
+ return if exit_code.zero?
21
21
 
22
22
  raise Lino::Errors::ExecutionError.new(
23
23
  command_line.string, exit_code
@@ -39,7 +39,8 @@ module Lino
39
39
  def start_process(process, opts)
40
40
  process.duplex = true if opts[:stdin]
41
41
  process.start
42
- process.io.stdin.write(opts[:stdin]) if opts[:stdin]
42
+ process.io.stdin.write(opts[:stdin].read) if opts[:stdin]
43
+ process.io.stdin.close if opts[:stdin]
43
44
  end
44
45
 
45
46
  def set_output_streams(process, opts)
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lino
4
+ module Executors
5
+ class Mock
6
+ attr_reader :executions, :stdout_contents, :stderr_contents
7
+ attr_accessor :exit_code
8
+
9
+ def initialize
10
+ reset
11
+ end
12
+
13
+ def execute(command_line, opts = {})
14
+ execution = { command_line:, opts:, exit_code: @exit_code }
15
+ execution = process_streams(execution, opts)
16
+
17
+ @executions << execution
18
+
19
+ return if @exit_code.zero?
20
+
21
+ raise Lino::Errors::ExecutionError.new(
22
+ command_line.string, @exit_code
23
+ )
24
+ end
25
+
26
+ def fail_all_executions
27
+ self.exit_code = 1
28
+ end
29
+
30
+ def write_to_stdout(contents)
31
+ @stdout_contents = contents
32
+ end
33
+
34
+ def write_to_stderr(contents)
35
+ @stderr_contents = contents
36
+ end
37
+
38
+ def reset
39
+ @executions = []
40
+ @exit_code = 0
41
+ @stdout_contents = nil
42
+ @stderr_contents = nil
43
+ end
44
+
45
+ private
46
+
47
+ def process_streams(execution, opts)
48
+ execution = process_stdout(execution, opts[:stdout])
49
+ execution = process_stderr(execution, opts[:stderr])
50
+ process_stdin(execution, opts[:stdin])
51
+ end
52
+
53
+ def process_stdout(execution, stdout)
54
+ if stdout && stdout_contents
55
+ stdout.write(stdout_contents)
56
+ return execution.merge(stdout_contents:)
57
+ end
58
+
59
+ execution
60
+ end
61
+
62
+ def process_stderr(execution, stderr)
63
+ if stderr && stderr_contents
64
+ stderr.write(stderr_contents)
65
+ return execution.merge(stderr_contents:)
66
+ end
67
+
68
+ execution
69
+ end
70
+
71
+ def process_stdin(execution, stdin)
72
+ return execution.merge(stdin_contents: stdin.read) if stdin
73
+
74
+ execution
75
+ end
76
+ end
77
+ end
78
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'executors/open4'
4
4
  require_relative 'executors/childprocess'
5
+ require_relative 'executors/mock'
5
6
 
6
7
  module Lino
7
8
  module Executors
@@ -85,7 +85,7 @@ module Lino
85
85
  options: opts.fetch(:options, []),
86
86
  arguments: opts.fetch(:arguments, []),
87
87
  environment_variables: opts.fetch(:environment_variables, []),
88
- executor: opts.fetch(:executor, Executors::Childprocess.new),
88
+ executor: opts.fetch(:executor, Lino.configuration.executor),
89
89
  working_directory: opts.fetch(:working_directory, nil)
90
90
  }
91
91
  end
data/lib/lino/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lino
4
- VERSION = '3.2.0.pre.6'
4
+ VERSION = '3.2.0.pre.8'
5
5
  end
data/lib/lino.rb CHANGED
@@ -7,6 +7,30 @@ require 'lino/executors'
7
7
  require 'lino/errors'
8
8
 
9
9
  module Lino
10
+ class << self
11
+ attr_writer :configuration
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+
21
+ def reset!
22
+ @configuration = nil
23
+ end
24
+ end
25
+
26
+ class Configuration
27
+ attr_accessor :executor
28
+
29
+ def initialize
30
+ @executor = Executors::Childprocess.new
31
+ end
32
+ end
33
+
10
34
  class CommandLineBuilder
11
35
  class << self
12
36
  def for_command(command)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lino
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0.pre.6
4
+ version: 3.2.0.pre.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-07 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess
@@ -310,6 +310,7 @@ files:
310
310
  - lib/lino/errors/execution_error.rb
311
311
  - lib/lino/executors.rb
312
312
  - lib/lino/executors/childprocess.rb
313
+ - lib/lino/executors/mock.rb
313
314
  - lib/lino/executors/open4.rb
314
315
  - lib/lino/model.rb
315
316
  - lib/lino/model/argument.rb