Skip to content

Commit

Permalink
fix: name temporary python script for run_python with suitable name (#…
Browse files Browse the repository at this point in the history
…1616)

Earlier we would name it with a name like `tranquil-wind` etc and that
would confuse the reader on what it might contain. The ideal solution
here is to clean this up and not use a temporary files artifact at all
and not use the service network inside interpret

---------

Co-authored-by: leoporoli <[email protected]>
  • Loading branch information
h4ck3rk3y and leoporoli authored Oct 25, 2023
1 parent e98cdf6 commit 88edb39
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
temporaryPythonDirectoryPrefix = "run-python-*"

successfulPipRunExitCode = 0

scriptArtifactFormat = "%v-python-script"
)

func NewRunPythonService(serviceNetwork service_network.ServiceNetwork, runtimeValueStore *runtime_value_store.RuntimeValueStore) *kurtosis_plan_instruction.KurtosisPlanInstruction {
Expand Down Expand Up @@ -149,6 +151,9 @@ type RunPythonCapabilities struct {
}

func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())

pythonScript, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, RunArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", RunArgName)
Expand All @@ -160,10 +165,7 @@ func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_arg
return nil, scriptCompressionInterpretationErr
}
defer compressedScript.Close()
uniqueFilesArtifactName, err := builtin.serviceNetwork.GetUniqueNameForFileArtifact()
if err != nil {
return nil, startosis_errors.NewInterpretationError("an error occurred while generating unique artifact name for python script")
}
uniqueFilesArtifactName := fmt.Sprintf(scriptArtifactFormat, builtin.name)
_, err = builtin.serviceNetwork.UploadFilesArtifact(compressedScript, compressedScriptMd5, uniqueFilesArtifactName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "An error occurred while storing the python script to disk")
Expand Down Expand Up @@ -258,8 +260,6 @@ func (builtin *RunPythonCapabilities) Interpret(_ string, arguments *builtin_arg
return nil, startosis_errors.NewInterpretationError("An error occurred while generating UUID for future reference for %v instruction", RunPythonBuiltinName)
}
builtin.resultUuid = resultUuid
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())

result := createInterpretationResult(resultUuid, builtin.storeSpecList)
return result, nil
Expand Down

0 comments on commit 88edb39

Please sign in to comment.