Skip to content

Commit a8ba8eb

Browse files
Launching another Enso process via Process_Builder (#14753)
- make it easy to launch another Enso process via `Process_Builder` - just say the command to execute is `"enso"` - we'll make sure we find it for you! - internally we use the new method in `Enso_Bin_Utils` instead of home made `test/Base_Tests` solution # Important Notes - original version was proposing alternative method to `new_builder` - however just recognizing `"enso"` command seems simpler - and it is kind of natural - just like making sure that `PATH` environment variable include the Enso bin directory - something I have done recently for NetBeans: apache/netbeans#8756
1 parent 2d7bb5c commit a8ba8eb

17 files changed

Lines changed: 199 additions & 282 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Add Amazon SES email provider][14597]
2121
- [Support for reading Alteryx YXDB files][14602].
2222
- [Salesforce OAuth support.][14550]
23+
- [Launching another Enso process via `Process_Builder`][14753]
2324
- [Redshift schema support.][14735]
2425

2526
[14522]: https://github.com/enso-org/enso/pull/14522
@@ -31,6 +32,7 @@
3132
[14597]: https://github.com/enso-org/enso/pull/14597
3233
[14602]: https://github.com/enso-org/enso/pull/14602
3334
[14550]: https://github.com/enso-org/enso/pull/14550
35+
[14753]: https://github.com/enso-org/enso/pull/14753
3436
[14735]: https://github.com/enso-org/enso/pull/14735
3537

3638
#### Enso Language & Runtime
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## Enso Signatures 1.0
22
## module Standard.Base.System.Process
3-
- new_builder command:Standard.Base.Any.Any arguments:Standard.Base.Any.Any= stdin:Standard.Base.Any.Any= -> Standard.Base.Any.Any
3+
- new_builder command:Standard.Base.Data.Text.Text arguments:Standard.Base.Any.Any= stdin:Standard.Base.Any.Any= -> Standard.Base.System.Process.Process_Builder.Process_Builder
44
- run command:Standard.Base.Data.Text.Text arguments:Standard.Base.Any.Any= stdin:Standard.Base.Data.Text.Text= redirect_out_err:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Any.Any
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## Enso Signatures 1.0
22
## module Standard.Base.System.Process.Process_Builder
33
- type Process_Builder
4-
- Value command:Standard.Base.Any.Any arguments:Standard.Base.Any.Any stdin:Standard.Base.Any.Any
5-
- create self redirect_out_err:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Any.Any
6-
- set_arguments self arguments:Standard.Base.Any.Any -> Standard.Base.Any.Any
7-
- set_stdin self stdin:Standard.Base.Any.Any -> Standard.Base.Any.Any
4+
- create self redirect_out_err:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.System.Process.Process_Builder.Process_Result
5+
- set_arguments self arguments:(Standard.Base.Data.Vector.Vector Standard.Base.Data.Text.Text) -> Standard.Base.System.Process.Process_Builder.Process_Builder
6+
- set_directory self path:Standard.Base.System.File.File -> Standard.Base.System.Process.Process_Builder.Process_Builder
7+
- set_stdin self stdin:Standard.Base.Data.Text.Text -> Standard.Base.System.Process.Process_Builder.Process_Builder
8+
- to_js_object self -> Standard.Base.Data.Json.JS_Object
89
- type Process_Result
910
- Value exit_code:Standard.Base.System.Process.Exit_Code.Exit_Code stdout:Standard.Base.Data.Text.Text stderr:Standard.Base.Data.Text.Text
10-
- to_display_text self -> Standard.Base.Any.Any
11+
- to_display_text self -> Standard.Base.Data.Text.Text

distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Runtime_Helpers.enso

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ state_uninitialized key =
4848
ref_new ~value = @Builtin_Method "Ref.alloc"
4949
ref_get ref = @Builtin_Method "Ref.get"
5050
ref_put ref new_value = @Builtin_Method "Ref.put"
51+
52+
create_process command arguments input redirect_in redirect_out redirect_err cwd = @Builtin_Method "System.create_process"

distribution/lib/Standard/Base/0.0.0-dev/src/System.enso

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import project.Data.Boolean.Boolean
55
import project.Data.Numbers.Integer
66
import project.Data.Text.Text
77
import project.Nothing.Nothing
8+
import project.Internal.Runtime_Helpers
89

910
polyglot java import java.lang.System as Java_System
1011

@@ -25,7 +26,8 @@ polyglot java import java.lang.System as Java_System
2526
- `redirect_err`: Specifies if the standard error output of the started
2627
process should be redirected to the program's standard error output.
2728
create_process : Text -> Array -> Text -> Boolean -> Boolean -> Boolean -> System_Process_Result
28-
create_process command arguments input redirect_in redirect_out redirect_err = @Builtin_Method "System.create_process"
29+
create_process command arguments input redirect_in redirect_out redirect_err =
30+
Runtime_Helpers.create_process command arguments input redirect_in redirect_out redirect_err Nothing
2931

3032
## ---
3133
private: true

distribution/lib/Standard/Base/0.0.0-dev/src/System/Process.enso

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import project.Data.Text.Text
22
import project.Data.Vector.Vector
3+
import project.Nothing.Nothing
34
import project.System.Process.Process_Builder.Process_Builder
45
import project.System.Process.Process_Builder.Process_Result
56
from project.Data.Boolean import Boolean, False
67
from project.Metadata.Widget import Text_Input, Vector_Editor
78

9+
polyglot java import org.enso.base.file_system.File_Utils
10+
811
## ---
912
aliases: [run a command]
1013
group: System
@@ -44,7 +47,6 @@ run command:Text arguments=[] stdin:Text="" redirect_out_err:Boolean=False =
4447
- `command`: The command to execute on the system.
4548
- `arguments`: The arguments to pass to `command`. These must be text.
4649
- `stdin`: Any content to pass to the standard input for `command`.
47-
- `redirect_out_err`: Redirect stdout/stderr to `Process_Result`.
4850

4951
## Examples
5052
### Create a new builder for a command "echo".
@@ -54,5 +56,10 @@ run command:Text arguments=[] stdin:Text="" redirect_out_err:Boolean=False =
5456

5557
example_new_builder = Process.new_builder "echo"
5658
```
57-
new_builder : Text -> Vector Text -> Text -> Process_Builder
58-
new_builder command arguments=[] stdin="" = Process_Builder.Value command arguments stdin
59+
new_builder command:Text arguments=[]:(Vector Text) stdin="":Text -> Process_Builder =
60+
cmd =
61+
if command == "enso" then
62+
File_Utils.getExecutableLocation
63+
else
64+
command
65+
Process_Builder.Value cmd arguments stdin Nothing

distribution/lib/Standard/Base/0.0.0-dev/src/System/Process/Process_Builder.enso

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import project.Data.Json.JS_Object
12
import project.Data.Text.Text
23
import project.Data.Vector.Vector
3-
import project.System
4+
import project.Nothing.Nothing
5+
import project.Internal.Runtime_Helpers
6+
import project.System.File.File
47
import project.System.Process.Exit_Code.Exit_Code
58
from project.Data.Boolean import Boolean, False
69

@@ -26,7 +29,7 @@ type Process_Builder
2629
We recommend that you use this type with its builder interface. Start by
2730
creating a `Builder "command"` and then call functions on it to set
2831
arguments and standard output. It results in much clearer code.
29-
Value command arguments stdin
32+
private Value command:Text (arguments:(Vector Text)) stdin:Text (cwd:Nothing|File)
3033

3134
## ---
3235
icon: edit
@@ -46,8 +49,8 @@ type Process_Builder
4649
builder = Process.new_builder "echo"
4750
builder.set_arguments ["hello, world!"]
4851
```
49-
set_arguments : Vector Text -> Process_Builder
50-
set_arguments self arguments = Process_Builder.Value self.command arguments self.stdin
52+
set_arguments self (arguments:Vector Text) -> Process_Builder =
53+
Process_Builder.Value self.command arguments self.stdin self.cwd
5154

5255
## ---
5356
icon: edit
@@ -68,8 +71,18 @@ type Process_Builder
6871
builder = Process.new_builder "echo"
6972
builder.set_stdin "hello, world!"
7073
```
71-
set_stdin : Text -> Process_Builder
72-
set_stdin self stdin = Process_Builder.Value self.command self.arguments stdin
74+
set_stdin self stdin:Text -> Process_Builder = Process_Builder.Value self.command self.arguments stdin self.cwd
75+
76+
## ---
77+
icon: edit
78+
---
79+
Sets the directory to execute the process at
80+
81+
## Arguments
82+
- `path`: the directory to execute the process at
83+
84+
set_directory self path:File -> Process_Builder =
85+
Process_Builder.Value self.command self.arguments self.stdin path
7386

7487
## ---
7588
icon: system
@@ -90,12 +103,18 @@ type Process_Builder
90103
with_args = builder.set_arguments ["hello, world!"]
91104
with_args.create
92105
```
93-
create : Boolean -> Process_Result
94-
create self redirect_out_err:Boolean=False =
95-
result = System.create_process self.command self.arguments self.stdin redirect_in=(self.stdin == False) redirect_out=redirect_out_err redirect_err=redirect_out_err
106+
create self redirect_out_err:Boolean=False -> Process_Result =
107+
cwd = if self.cwd != Nothing then
108+
self.cwd.to_text
109+
result = Runtime_Helpers.create_process self.command self.arguments self.stdin redirect_in=(self.stdin == False) redirect_out=redirect_out_err redirect_err=redirect_out_err cwd
96110
exit_code = Exit_Code.from_number result.exit_code
97111
Process_Result.Value exit_code result.stdout result.stderr
98112

113+
## ---
114+
private: true
115+
---
116+
to_js_object self -> JS_Object = JS_Object.from_pairs [["type", "Process_Builder"]]
117+
99118
type Process_Result
100119
## ---
101120
private: true
@@ -106,7 +125,6 @@ type Process_Result
106125
private: true
107126
---
108127
Convert to a display representation of this Process_Result.
109-
to_display_text : Text
110-
to_display_text self = case self.exit_code of
128+
to_display_text self -> Text = case self.exit_code of
111129
Exit_Code.Success -> "Success(" + self.stdout.to_display_text + ")"
112130
_ -> self.exit_code.to_display_text + "(" + self.stderr.to_display_text + ")"

0 commit comments

Comments
 (0)