Skip to content

Commit

Permalink
Add Execution Context control to Text.write (#6459)
Browse files Browse the repository at this point in the history
- Adjusted `Context.is_enabled` to support default argument (moved built in so can have defaults).
- Made `environment` case-insensitive.
- Bug fix for play button.
- Short hand to execute within an enabled context.
- Forbid file writing if the Output context is disabled with a `Forbidden_Operation` error.
- Add temporary file support via `File.create_temporary_file` which is deleted on exit of JVM.
- Execution Context first pass in `Text.write`.
- Added dry run warning.
- Writes to a temporary file if disabled.
- Created a `DryRunFileManager` which will create and manage the temporary files.
- Added `format` dropdown to `File.read` and `Data.read`.
- Renamed `JSON_File` to `JSON_Format` to be consistent.

(still to unit test).
  • Loading branch information
jdunkerley authored Apr 29, 2023
1 parent cdd0065 commit 6b0c682
Show file tree
Hide file tree
Showing 30 changed files with 295 additions and 109 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@
`Time_Of_Day`, `Time_Zone`, and `URI` to `Text`.][6404]
- [Implemented `create_database_table` allowing upload of in-memory
tables.][6429]
- [Added execution context control to writing files and dry run capabilities to
`Text.write`.][6459]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -602,6 +604,7 @@
[6404]: https://github.com/enso-org/enso/pull/6404
[6347]: https://github.com/enso-org/enso/pull/6347
[6429]: https://github.com/enso-org/enso/pull/6429
[6459]: https://github.com/enso-org/enso/pull/6459

#### Enso Compiler

Expand Down
2 changes: 1 addition & 1 deletion app/gui/controller/engine-protocol/src/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ trait API {

/// Restart the program execution.
#[MethodInput=RecomputeInput, rpc_name="executionContext/recompute"]
fn recompute(&self, context_id: ContextId, invalidated_expressions: InvalidatedExpressions, mode: Option<ExecutionEnvironment>) -> ();
fn recompute(&self, context_id: ContextId, invalidated_expressions: InvalidatedExpressions, execution_environment: Option<ExecutionEnvironment>) -> ();

/// Obtain the full suggestions database.
#[MethodInput=GetSuggestionsDatabaseInput, rpc_name="search/getSuggestionsDatabase"]
Expand Down
5 changes: 3 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data.enso
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import project.Network.HTTP.Request.Request
import project.Network.HTTP.Request_Error
import project.Nothing.Nothing
import project.System.File.File
import project.System.File_Format.Auto_Detect
import project.System.File_Format.File_Format

from project.Data.Boolean import Boolean, True, False
from project.System.File_Format import Auto_Detect, File_Format, format_widget

## ALIAS Load, Open
Reads a file into Enso.
Expand Down Expand Up @@ -56,6 +55,7 @@ from project.Data.Boolean import Boolean, True, False
import Standard.Examples

example_xls_to_table = Data.read Examples.xls (Excel (Worksheet 'Dates'))
@format format_widget
read : Text | File -> File_Format -> Problem_Behavior -> Any ! File_Error
read path format=Auto_Detect (on_problems=Problem_Behavior.Report_Warning) =
File.new path . read format on_problems
Expand All @@ -81,6 +81,7 @@ read path format=Auto_Detect (on_problems=Problem_Behavior.Report_Warning) =
import Standard.Examples

example_read = Data.read_text Examples.csv_path
@encoding Encoding.default_widget
read_text : (Text | File) -> Encoding -> Problem_Behavior -> Text
read_text path (encoding=Encoding.utf_8) (on_problems=Problem_Behavior.Report_Warning) =
File.new path . read_text encoding on_problems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ polyglot java import java.nio.charset.Charset
polyglot java import java.nio.charset.UnsupportedCharsetException
polyglot java import org.enso.base.Text_Utils

from project.Metadata.Widget import Single_Choice
from project.Metadata.Choice import Option
import project.Metadata.Display

## Represents a character encoding.
type Encoding
## PRIVATE
Gets the default drop down option for this encoding.
default_widget : Single_Choice
default_widget =
values = [Option "UTF-8" "Encoding.utf_8", Option "ASCII" "Encoding.ascii", Option "UTF-16LE" "Encoding.utf_16_le", Option "UTF-16BE" "Encoding.utf_16_be", Option "UTF-32LE" "Encoding.utf_32_le", Option "UTF-32BE" "Encoding.utf_32_be", Option "Windows-1250" "Encoding.windows_1250", Option "Windows-1251" "Encoding.windows_1251", Option "Windows-1252" "Encoding.windows_1252", Option "Windows-1253" "Encoding.windows_1253", Option "Windows-1254" "Encoding.windows_1254", Option "Windows-1255" "Encoding.windows_1255", Option "Windows-1256" "Encoding.windows_1256", Option "Windows-1257" "Encoding.windows_1257", Option "Windows-1258" "Encoding.windows_1258"]
Single_Choice values=values display=Display.When_Modified

## PRIVATE
ADVANCED
Get all available character sets from Java as Encodings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ Text.is_whitespace self =
Get the ASCII bytes of the text "Hello".

"Hello".bytes (Encoding.ascii)
@encoding Encoding.default_widget
Text.bytes : Encoding -> Problem_Behavior -> Vector Integer
Text.bytes self encoding on_problems=Problem_Behavior.Report_Warning =
result = Encoding_Utils.get_bytes self (encoding . to_java_charset)
Expand All @@ -664,6 +665,7 @@ Text.bytes self encoding on_problems=Problem_Behavior.Report_Warning =
Get the ASCII bytes of the text "Hello".

"Hello".bytes (Encoding.ascii)
@encoding Encoding.default_widget
Text.from_bytes : Vector Integer -> Encoding -> Problem_Behavior -> Text
Text.from_bytes bytes encoding on_problems=Problem_Behavior.Report_Error =
result = Encoding_Utils.from_bytes bytes.to_array (encoding . to_java_charset)
Expand Down
13 changes: 13 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,16 @@ type Forbidden_Operation
Convert the Forbidden_Operation error to a human-readable format.
to_display_text : Text
to_display_text self = "Forbidden operation: "+self.operation+"."

type Dry_Run_Operation
## PRIVATE
A warning that the operation has only been performed in a test mode.

Arguments:
- message: The message to be displayed.
Warning message

## PRIVATE
Convert the Dry_Run_Operation to a human-readable format.
to_display_text : Text
to_display_text self = self.message
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export project.Warning.Warning
from project.Data.Boolean export Boolean, True, False
from project.Function export all
from project.Data.Numbers export Number, Integer, Decimal
from project.System.File_Format export File_Format, Plain_Text_Format, Plain_Text, Bytes, Infer, Auto_Detect, JSON_File
from project.System.File_Format export File_Format, Plain_Text_Format, Plain_Text, Bytes, Infer, Auto_Detect, JSON_Format

import project.Data
import project.Data.Filter_Condition.Filter_Condition
Expand Down
21 changes: 18 additions & 3 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Runtime.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import project.Any.Any
import project.Data.Array.Array
import project.Data.Boolean.Boolean
import project.Data.Text.Case.Case
import project.Data.Text.Extensions
import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Errors.Common.Forbidden_Operation
Expand Down Expand Up @@ -159,7 +161,18 @@ type Context
- environment: Name of the execution environment.
- context: The context to enable.
is_enabled : Text -> Boolean
is_enabled self environment=Runtime.current_execution_environment = @Builtin_Method "Context.is_enabled"
is_enabled self environment=Runtime.current_execution_environment =
self.is_enabled_builtin (environment.to_case Case.Lower)

## PRIVATE
is_enabled_builtin : Text -> Boolean
is_enabled_builtin self environment = @Builtin_Method "Context.is_enabled_builtin"

## PRIVATE
Run an action with the Context enabled.
with_enabled : Function -> Any
with_enabled self ~action =
with_enabled_context self Runtime.current_execution_environment action


## PRIVATE
Expand All @@ -179,7 +192,8 @@ current_execution_environment = @Builtin_Method "Runtime.current_execution_envir
- context: The context to enable.
- action: Action to be performed with the context enabled.
with_enabled_context : Context -> Text -> Function -> Any
with_enabled_context context environment=Runtime.current_execution_environment ~action = with_enabled_context_builtin context environment action
with_enabled_context context environment=Runtime.current_execution_environment ~action =
with_enabled_context_builtin context (environment.to_case Case.Lower) action

## PRIVATE
ADVANCED
Expand All @@ -205,7 +219,8 @@ with_enabled_context_builtin context environment ~action = @Builtin_Method "Runt
- context: The context to disable.
- action: Action to be performed with the context disabled.
with_disabled_context : Context -> Text -> Function -> Any
with_disabled_context context environment=Runtime.current_execution_environment ~action = with_disabled_context_builtin context environment action
with_disabled_context context environment=Runtime.current_execution_environment ~action =
with_disabled_context_builtin context (environment.to_case Case.Lower) action

## PRIVATE
ADVANCED
Expand Down
Loading

0 comments on commit 6b0c682

Please sign in to comment.