Skip to content

Commit

Permalink
fix, Linting problems
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Oct 3, 2024
1 parent c1e29e3 commit 832369f
Show file tree
Hide file tree
Showing 32 changed files with 262 additions and 200 deletions.
22 changes: 15 additions & 7 deletions cmd/eval-dev-quality/cmd/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ func (command *Evaluate) Initialize(args []string) (evaluationContext *evaluate.
if err != nil {
command.logger.Panicf("ERROR: %s", err)
}
configurationFile.Close()
if err := configurationFile.Close(); err != nil {
panic(err)
}

command.Models = configuration.Models.Selected
command.Repositories = configuration.Repositories.Selected
Expand Down Expand Up @@ -360,9 +362,7 @@ func (command *Evaluate) Initialize(args []string) (evaluationContext *evaluate.
sort.Strings(command.Repositories)
}
evaluationContext.RepositoryPaths = command.Repositories
for _, r := range command.Repositories {
evaluationConfiguration.Repositories.Selected = append(evaluationConfiguration.Repositories.Selected, r)
}
evaluationConfiguration.Repositories.Selected = append(evaluationConfiguration.Repositories.Selected, command.Repositories...)
}

// Make the resolved selected languages available in the command.
Expand Down Expand Up @@ -494,7 +494,11 @@ func (command *Evaluate) Execute(args []string) (err error) {
if err != nil {
command.logger.Panicf("ERROR: cannot create configuration file: %s", err)
}
defer configurationFile.Close()
defer func() {
if err := configurationFile.Close(); err != nil {
panic(err)
}
}()
if err := evaluationConfiguration.Write(configurationFile); err != nil {
command.logger.Panicf("ERROR: %s", err)
}
Expand Down Expand Up @@ -773,7 +777,9 @@ func (command *Evaluate) evaluateKubernetes(ctx *evaluate.Context) (err error) {

parallel.Execute(func() {
var tmplData bytes.Buffer
jobTmpl.Execute(&tmplData, data)
if err := jobTmpl.Execute(&tmplData, data); err != nil {
panic(err)
}

commandOutput, err := util.CommandWithResult(context.Background(), command.logger, &util.Command{
Command: kubeCommand,
Expand Down Expand Up @@ -836,7 +842,9 @@ func (command *Evaluate) evaluateKubernetes(ctx *evaluate.Context) (err error) {
}

var tmplData bytes.Buffer
storageTmpl.Execute(&tmplData, data)
if err := storageTmpl.Execute(&tmplData, data); err != nil {
panic(err)
}

// Create the storage access pod.
output, err := util.CommandWithResult(context.Background(), command.logger, &util.Command{
Expand Down
13 changes: 10 additions & 3 deletions cmd/eval-dev-quality/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (command *Report) Execute(args []string) (err error) {
if evaluationCSVFile, err = os.OpenFile(filepath.Join(command.ResultPath, "evaluation.csv"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0755); err != nil {
command.logger.Panicf("ERROR: %s", err)
}
defer evaluationCSVFile.Close()
defer func() {
if err := evaluationCSVFile.Close(); err != nil {
panic(err)
}
}()

// Collect all evaluation CSV file paths.
allEvaluationPaths := map[string]bool{}
Expand Down Expand Up @@ -86,7 +90,11 @@ func (command *Report) Execute(args []string) (err error) {
if err != nil {
command.logger.Panicf("ERROR: %s", err)
}
defer modelsMetaInformationCSVFile.Close()
defer func() {
if err := modelsMetaInformationCSVFile.Close(); err != nil {
panic(err)
}
}()

// Fetch all openrouter models since it is the only provider that currently supports querying meta information.
provider := openrouter.NewProvider().(*openrouter.Provider)
Expand Down Expand Up @@ -139,7 +147,6 @@ func collectAllEvaluationLogFiles(evaluationCSVFilePaths []string) (evaluationLo
if err != nil {
continue
}
filepath.Base(evaluationDirectory)
evaluationLogFilePaths = append(evaluationLogFilePaths, filepath.Join(filepath.Base(evaluationDirectory), "evaluation.log"))
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/eval-dev-quality/cmd/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestPathsFromGlobPattern(t *testing.T) {
Before: func(workingDirectory string) {
file, err := os.Create(filepath.Join(workingDirectory, "not-an-evaluation.csv"))
require.NoError(t, err)
file.Close()
require.NoError(t, file.Close())
},

EvaluationGlobPattern: "not-an-evaluation.csv",
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestCollectAllEvaluationLogFiles(t *testing.T) {

file, err := os.Create(filepath.Join(workingDirectory, "someModel", "evaluation.csv"))
require.NoError(t, err)
file.Close()
require.NoError(t, file.Close())
},

EvaluationCSVFilePaths: []string{
Expand Down Expand Up @@ -442,9 +442,9 @@ func createEvaluationDirectoryWithLogFiles(t *testing.T, workingDirectory string

file, err := os.Create(filepath.Join(workingDirectory, "evaluation.csv"))
require.NoError(t, err)
file.Close()
require.NoError(t, file.Close())

file, err = os.Create(filepath.Join(workingDirectory, "evaluation.log"))
require.NoError(t, err)
file.Close()
require.NoError(t, file.Close())
}
21 changes: 14 additions & 7 deletions evaluate/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/symflower/eval-dev-quality/evaluate/report"
evaluatetask "github.com/symflower/eval-dev-quality/evaluate/task"
"github.com/symflower/eval-dev-quality/language"
evallanguage "github.com/symflower/eval-dev-quality/language"
"github.com/symflower/eval-dev-quality/log"
evalmodel "github.com/symflower/eval-dev-quality/model"
Expand Down Expand Up @@ -79,7 +78,11 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
if err != nil {
ctx.Log.Panicf("ERROR: unable to create evaluation CSV file: %+v", err)
}
defer evaluationCSVFile.Close()
defer func() {
if err := evaluationCSVFile.Close(); err != nil {
panic(err)
}
}()
evaluationFile, err := report.NewEvaluationFile(evaluationCSVFile)
if err != nil {
ctx.Log.Panicf("ERROR: %+v", err)
Expand Down Expand Up @@ -131,7 +134,7 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
}

for _, taskIdentifier := range temporaryRepository.SupportedTasks() {
task, err := evaluatetask.TaskForIdentifier(taskIdentifier)
task, err := evaluatetask.ForIdentifier(taskIdentifier)
if err != nil {
logger.Fatal(err)
}
Expand Down Expand Up @@ -172,7 +175,9 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
}
assessments.AddAssessmentPerTask(model, language, repositoryPath, assessment)
// Write the task assessment to the evaluation CSV file.
evaluationFile.WriteEvaluationRecord(model, language, temporaryRepository.Name(), runCount, assessment)
if err := evaluationFile.WriteEvaluationRecord(model, language, temporaryRepository.Name(), runCount, assessment); err != nil {
panic(err)
}
}
})
}
Expand All @@ -191,7 +196,7 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
// Create temporary repositories for each language so the repository is copied only once per language.
temporaryRepositories := map[string]*evaluatetask.Repository{}
for _, l := range ctx.Languages {
relativeRepositoryPaths, err := language.RepositoriesForLanguage(l, ctx.TestdataPath)
relativeRepositoryPaths, err := evallanguage.RepositoriesForLanguage(l, ctx.TestdataPath)
if err != nil {
ctx.Log.Panicf("ERROR: %s", err)
}
Expand Down Expand Up @@ -256,7 +261,7 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
continue
}
for _, taskIdentifier := range temporaryRepository.Tasks {
task, err := evaluatetask.TaskForIdentifier(taskIdentifier)
task, err := evaluatetask.ForIdentifier(taskIdentifier)
if err != nil {
logger.Fatal(err)
}
Expand Down Expand Up @@ -291,7 +296,9 @@ func Evaluate(ctx *Context) (assessments *report.AssessmentStore, totalScore uin
}
assessments.AddAssessmentPerTask(model, language, repositoryPath, assessment)
// Write the task assessment to the evaluation CSV file.
evaluationFile.WriteEvaluationRecord(model, language, temporaryRepository.Name(), runCount, assessment)
if err := evaluationFile.WriteEvaluationRecord(model, language, temporaryRepository.Name(), runCount, assessment); err != nil {
panic(err)
}
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions evaluate/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/symflower/eval-dev-quality/language"
"github.com/symflower/eval-dev-quality/language/golang"
"github.com/symflower/eval-dev-quality/log"
"github.com/symflower/eval-dev-quality/model"
evalmodel "github.com/symflower/eval-dev-quality/model"
"github.com/symflower/eval-dev-quality/model/llm"
modeltesting "github.com/symflower/eval-dev-quality/model/testing"
Expand Down Expand Up @@ -863,7 +862,7 @@ func TestEvaluate(t *testing.T) {
mockedModelID := "testing-provider/testing-model"
mockedModel := modeltesting.NewMockCapabilityWriteTestsNamed(t, mockedModelID)
mockedProviderID := "testing-provider"
mockedProvider := providertesting.NewMockProviderNamedWithModels(t, mockedProviderID, []model.Model{mockedModel})
mockedProvider := providertesting.NewMockProviderNamedWithModels(t, mockedProviderID, []evalmodel.Model{mockedModel})
mockedLoader := providertesting.NewMockLoader(t)
embeddedProvider := &struct {
provider.Provider
Expand Down Expand Up @@ -947,7 +946,7 @@ func TestEvaluate(t *testing.T) {
mockedModelID := "testing-provider/testing-model"
mockedModel := modeltesting.NewMockCapabilityWriteTestsNamed(t, mockedModelID)
mockedProviderID := "testing-provider"
mockedProvider := providertesting.NewMockProviderNamedWithModels(t, mockedProviderID, []model.Model{mockedModel})
mockedProvider := providertesting.NewMockProviderNamedWithModels(t, mockedProviderID, []evalmodel.Model{mockedModel})
mockedLoader := providertesting.NewMockLoader(t)
embeddedProvider := &struct {
provider.Provider
Expand Down
26 changes: 14 additions & 12 deletions evaluate/metrics/testing/assessments.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ import (

// Clean deletes all empty and nondeterministic keys from the assessment.
func Clean(assessment metrics.Assessments) metrics.Assessments {
copy := metrics.Assessments{}
maps.Copy(copy, assessment)
c := metrics.Assessments{}
maps.Copy(c, assessment)

delete(copy, metrics.AssessmentKeyProcessingTime)
delete(c, metrics.AssessmentKeyProcessingTime)

for _, key := range metrics.AllAssessmentKeysStrings {
if copy[metrics.AssessmentKey(key)] == 0 {
delete(copy, metrics.AssessmentKey(key))
if c[metrics.AssessmentKey(key)] == 0 {
delete(c, metrics.AssessmentKey(key))
}
}

return copy
return c
}

// CleanSlice deletes all empty and nondeterministic keys from the assessments.
func CleanSlice(assessments []metrics.Assessments) []metrics.Assessments {
copy := make([]metrics.Assessments, len(assessments))
c := make([]metrics.Assessments, len(assessments))

for i, assessment := range assessments {
copy[i] = Clean(assessment)
c[i] = Clean(assessment)
}

return copy
return c
}

// CleanMap deletes all empty and nondeterministic keys from the assessments.
func CleanMap[E comparable](assessments map[E]metrics.Assessments) map[E]metrics.Assessments {
copy := map[E]metrics.Assessments{}
c := map[E]metrics.Assessments{}

for key, assessment := range assessments {
copy[key] = Clean(assessment)
c[key] = Clean(assessment)
}

return copy
return c
}

// AssessmentsWithProcessingTime is an empty assessment collection with positive processing time.
Expand All @@ -61,8 +61,10 @@ type AssessmentTuple struct {
Assessment metrics.Assessments
}

// AssessmentTuples holds a list of all parameters uniquely defining to which run an assessment belongs to.
type AssessmentTuples []*AssessmentTuple

// ToMap converts a list of assessment tuples to a mapping.
func (at AssessmentTuples) ToMap() (lookup map[model.Model]map[language.Language]map[string]map[task.Identifier]metrics.Assessments) {
lookup = map[model.Model]map[language.Language]map[string]map[task.Identifier]metrics.Assessments{}
for _, t := range at {
Expand Down
12 changes: 9 additions & 3 deletions evaluate/report/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e *EvaluationFile) WriteLines(records [][]string) (err error) {
return nil
}

// evaluationHeader returns the CSV header for the evaluation CSV.
// EvaluationHeader returns the CSV header for the evaluation CSV.
func EvaluationHeader() (header []string) {
return append([]string{"model-id", "language", "repository", "task", "run", "score"}, metrics.AllAssessmentKeysStrings...)
}
Expand All @@ -84,12 +84,18 @@ func RecordsFromEvaluationCSVFiles(evaluationCSVFilePaths []string) (records [][
if err != nil {
return nil, pkgerrors.WithStack(err)
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
panic(err)
}
}()

csv := csv.NewReader(file)

// Ignore the CSV header.
csv.Read()
if _, err := csv.Read(); err != nil {
panic(err)
}

evaluationRecords, err := csv.ReadAll()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ import (
evaltask "github.com/symflower/eval-dev-quality/task"
)

// TaskCodeRepair holds the code repair task.
type TaskCodeRepair struct {
// CodeRepair holds the code repair task.
type CodeRepair struct {
}

// TaskArgumentsCodeRepair holds extra arguments to be used in a query prompt.
type TaskArgumentsCodeRepair struct {
// ArgumentsCodeRepair holds extra arguments to be used in a query prompt.
type ArgumentsCodeRepair struct {
// Mistakes holds the list of compilation errors for a package.
Mistakes []string
}

var _ evaltask.Task = (*TaskCodeRepair)(nil)
var _ evaltask.Task = (*CodeRepair)(nil)

// Identifier returns the code repair task identifier.
func (t *TaskCodeRepair) Identifier() evaltask.Identifier {
func (t *CodeRepair) Identifier() evaltask.Identifier {
return IdentifierCodeRepair
}

// Run performs source code repairing in a repository with compilation errors.
// This task requires the repository to consist of multiple packages, with each containing one faulty implementation file and a corresponding test file.
func (t *TaskCodeRepair) Run(ctx evaltask.Context) (repositoryAssessment map[evaltask.Identifier]metrics.Assessments, problems []error, err error) {
func (t *CodeRepair) Run(ctx evaltask.Context) (repositoryAssessment map[evaltask.Identifier]metrics.Assessments, problems []error, err error) {
modelCapability, ok := ctx.Model.(model.CapabilityRepairCode)
if !ok {
return nil, nil, pkgerrors.Wrap(evaltask.ErrTaskUnsupportedByModel, fmt.Sprintf("%q does not support %q", ctx.Model.ID(), string(t.Identifier())))
Expand Down Expand Up @@ -76,7 +76,7 @@ func (t *TaskCodeRepair) Run(ctx evaltask.Context) (repositoryAssessment map[eva
RepositoryPath: packagePath,
FilePath: sourceFile,

Arguments: &TaskArgumentsCodeRepair{
Arguments: &ArgumentsCodeRepair{
Mistakes: mistakes,
},

Expand Down Expand Up @@ -115,7 +115,7 @@ func (t *TaskCodeRepair) Run(ctx evaltask.Context) (repositoryAssessment map[eva
}

// unpackCodeRepairPackage validates a package under test and returns the source file path and the list of compilation errors found.
func (t *TaskCodeRepair) unpackCodeRepairPackage(ctx evaltask.Context, fileLogger *log.Logger, packagePath string) (sourceFilePath string, mistakes []string, err error) {
func (t *CodeRepair) unpackCodeRepairPackage(ctx evaltask.Context, fileLogger *log.Logger, packagePath string) (sourceFilePath string, mistakes []string, err error) {
mistakes, err = ctx.Language.Mistakes(ctx.Logger, packagePath)
if err != nil {
return "", nil, pkgerrors.WithStack(err)
Expand Down
Loading

0 comments on commit 832369f

Please sign in to comment.