Skip to content

Commit

Permalink
Merge pull request #2 from Astera-org/garymm/codecov
Browse files Browse the repository at this point in the history
improve doc comments
  • Loading branch information
garymm authored Oct 3, 2023
2 parents 6c51748 + 0d04c58 commit 309133b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mlflow-go

Go MLFlow client.
Go [MLFlow](https://mlflow.org) client.

Supports the Tracking API, with local files and HTTP.

Expand Down
19 changes: 10 additions & 9 deletions dbfs_artifact_repo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mlflow

// When modifying please run the manual test for this file with:
// go test -v -tags manual ./mlflow/go
// go test -v -tags manual ./...
// or
// bazel test --test_output=all //mlflow/go:dbfs_artifact_repo_test
package mlflow
// bazel test --test_output=all //:dbfs_artifact_repo_test

import (
"bytes"
Expand All @@ -23,9 +24,11 @@ const (
dbfsMaxUploadFileSize = 64 * 1024 * 1024
)

// Based on
// https://github.com/mlflow/mlflow/blob/e7ff52d724e3218704fde225493e52c5acd41bb6/mlflow/store/artifact/databricks_artifact_repo.py
// DBFSArtifactRepo uploads to DBFS (Databricks File System).
// Generally it is used indirectly via [Run.LogArtifact].
type DBFSArtifactRepo struct {
// Based on
// https://github.com/mlflow/mlflow/blob/e7ff52d724e3218704fde225493e52c5acd41bb6/mlflow/store/artifact/databricks_artifact_repo.py
rest *RESTStore
rootPath string
runID string
Expand All @@ -44,9 +47,7 @@ func NewDBFSArtifactRepo(restStore *RESTStore, uri string) (ArtifactRepo, error)
return &DBFSArtifactRepo{restStore, parsed.Path, path.Base(path.Dir(parsed.Path))}, nil
}

// localPath is the path to the file on the local filesystem.
// artifactPath is the directory in the artifact repo to upload the file to.
// Kinda weird, but this is how the python client does it.
// Implements [ArtifactRepo.LogArtifact].
func (repo *DBFSArtifactRepo) LogArtifact(localPath, artifactPath string) error {
destPath := path.Join(artifactPath, path.Base(localPath))
getCredsReq := protos.GetCredentialsForWrite{
Expand Down Expand Up @@ -107,7 +108,7 @@ func (repo *DBFSArtifactRepo) LogArtifact(localPath, artifactPath string) error
return nil
}

// localPath is the path to the directory on the local filesystem.
// Implements [ArtifactRepo.LogArtifacts].
func (repo *DBFSArtifactRepo) LogArtifacts(localPath, artifactPath string) error {
// We want to keep only the last directory in the path.
// This is because the python client does this.
Expand Down
2 changes: 2 additions & 0 deletions file_artifact_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
)

// FileArtifactRepo writes to a local file system.
// Generally it is used indirectly via [Run.LogArtifact].
type FileArtifactRepo struct {
rootDir string
}
Expand Down
13 changes: 12 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Follow the [personal acess token instructions] to get one.
//
// The API is organized into a hierarchy of interfaces:
// - [Tracking]: represents a connection to an MLFlow tracking server.
// - [Tracking]: represents an MLFlow tracking server.
// - [Experiment]: represents an MLFlow experiment.
// - [Run]: represents an MLFlow run.
//
Expand Down Expand Up @@ -54,6 +54,9 @@ var (
ErrUnsupported = errors.New("this operation not supported by this tracking client")
)

// Tracking is an interface for an MLFlow tracking server.
// It is generally used indirectly via [ActiveRunFromEnv], or you can create one with
// [NewTracking].
type Tracking interface {
ExperimentsByName() (map[string]Experiment, error)
CreateExperiment(name string) (Experiment, error)
Expand Down Expand Up @@ -105,8 +108,16 @@ type Run interface {
ExperimentID() string
}

// ArtifactRepo is an interface for logging artifacts.
// It is generally used indirectly via [Run.LogArtifact].
type ArtifactRepo interface {
// localPath is the path to the file on the local filesystem.
// artifactPath is the directory in the artifact repo to upload the file to.
// Kinda weird, but this is how the python client does it.
LogArtifact(localPath, artifactPath string) error
// LogArtifacts logs all of the files in a directory tree as artifacts.
// localPath is the path to the directory on the local filesystem.
// artifactPath is the directory in the artifact repo to upload to.
LogArtifacts(localDir, artifactPath string) error
}

Expand Down

0 comments on commit 309133b

Please sign in to comment.