-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unlock shebang++ #560
Unlock shebang++ #560
Conversation
@@ -52,6 +52,14 @@ func pathNormalizer(cfg *Config) (*Config, func() error, error) { | |||
} | |||
} | |||
|
|||
// default to "cat" | |||
cat, err := exec.LookPath("cat") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adambabik should this be using the new sys
abstraction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave it as is. I need to port the system
pkg usage to beta commands and runnerv2.
Also just realized that runnerv2's command packages does not seem to have any |
bool store_last_stdout = 23; | ||
// store_env_vars, if true, will store the stdout under well known name | ||
// and the last ran block in the environment variable `__`. | ||
bool store_env_vars = 23; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool store_env_vars = 23; | |
bool store_stdout_in_env = 23; |
@@ -52,6 +52,14 @@ func pathNormalizer(cfg *Config) (*Config, func() error, error) { | |||
} | |||
} | |||
|
|||
// default to "cat" | |||
cat, err := exec.LookPath("cat") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave it as is. I need to port the system
pkg usage to beta commands and runnerv2.
@@ -52,6 +52,14 @@ func pathNormalizer(cfg *Config) (*Config, func() error, error) { | |||
} | |||
} | |||
|
|||
// default to "cat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// default to "cat" | |
// Default to "cat" when no program path is found. | |
// The idea is to return the body of the cell as its output | |
// so that it can be used as input in other cells. |
internal/runner/service.go
Outdated
if knownName != "" && runnerConformsOpinionatedEnvVarNaming(knownName) { | ||
err = sess.SetEnv(knownName, string(stdoutMem)) | ||
if err != nil { | ||
logger.Sugar().Errorf("%v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.Sugar().Errorf("%v", err) | |
logger.Warn("failed to set env", zap.Error(err)) |
In order to stay consistent.
internal/runner/service.go
Outdated
@@ -609,6 +618,12 @@ func runnerWinsizeToPty(winsize *runnerv1.Winsize) *pty.Winsize { | |||
} | |||
} | |||
|
|||
func runnerConformsOpinionatedEnvVarNaming(knownName string) bool { | |||
// only allow uppercase letters, digits and underscores, min three chars | |||
re := regexp.MustCompile(`^[A-Z_][A-Z0-9_]{1}[A-Z0-9_]*[A-Z][A-Z0-9_]*$`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: you can move this line outside of the func body to compile it only once.
session *command.Session | ||
storeLastStdout bool | ||
session *command.Session | ||
storeEnvVars bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storeEnvVars bool | |
storeStdoutInEnv bool |
@@ -59,7 +61,7 @@ func newExecution( | |||
id string, | |||
cfg *command.Config, | |||
session *command.Session, | |||
storeLastStdout bool, | |||
storeEnvVars bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storeEnvVars bool, | |
storeStdoutInEnv bool, |
@@ -277,7 +283,7 @@ func (e *execution) closeIO() { | |||
} | |||
|
|||
func (e *execution) storeLastOutput(r io.Reader) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (e *execution) storeLastOutput(r io.Reader) { | |
func (e *execution) storeOutputInEnv(r io.Reader) { |
@@ -177,6 +177,12 @@ message ExecuteRequest { | |||
|
|||
// file extension associated with script | |||
string file_extension = 26; | |||
|
|||
// optional well known id for cell/block | |||
string known_id = 27; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it is not used. We can keep it for the completeness reason.
The most important for me is to provide more detailed description. What does "known" mean? What guarantees does it give? Maybe given an example how client would use this.
Finally, if you take a look at config/v1alpha1/config.proto
, we have a way to validate field values in the proto definition. This is a bit tricky and not used anywhere else, so it might be a better idea for a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add an example. The reason why I added id
(unused) was because I have near-term projects in mind where I need it. I'll be sure to make the description better. Going to skip validation in this PR for now.
This is implemented in |
I think it's ok until we figure out a better approach. I would only ask for a more detailed description in the proto files. I added a comment in the source code. |
Quality Gate passedIssues Measures |
Multiple things:
cat
to stash the input cell in the output.This will enable use cases where e.g. you have a SQL query you're live-editing in one cell and running it with
$ bq query
(BigQuery CLI) in another cell. Enables better interplay between cells than just running them back-to-back ($__
).@adambabik wondering if we should deny overwriting variables already contained in the ENV? However, any
export
statement will let you do that 🤷. Also, I don't want to overload the Runner with too much "cell/block"-level terminology so I introducedknown_id
&known_name
which are as below. The idea being that if a name or id is known, clients can specify them here. Otherwise they are "unknown" since they are not required to run programs. Open to suggestion to model this differently.PS: Also renamed
StoreLastOutput
toStoreEnvVars
only inrunnerv2
as a cleanup.