-
Notifications
You must be signed in to change notification settings - Fork 72
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
python/go grpc interface for async uploads #408
Changes from all commits
80eeb47
043a77f
be61b09
246d4cd
65abe1c
23044fe
c922cd9
7fff96b
2261d71
281071d
405bfdb
7642371
36e71f6
b0cb87e
b79cd63
0f63da3
5af9906
7802941
f970fe4
1551fee
86f356d
6ffe401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/replicate/replicate/go/pkg/shared" | ||
"github.com/replicate/replicate/go/pkg/cli" | ||
"github.com/replicate/replicate/go/pkg/console" | ||
) | ||
|
||
func main() { | ||
shared.Serve() | ||
cmd := cli.NewDaemonCommand() | ||
if err := cmd.Execute(); err != nil { | ||
console.Fatal("%s", err) | ||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,20 +28,31 @@ func addRepositoryURLFlagVar(cmd *cobra.Command, opt *string) { | |
} | ||
|
||
// getRepositoryURLFromStringOrConfig attempts to get it from passed string from --repository, | ||
// otherwise finds replicate.yaml recursively | ||
// otherwise finds replicate.yaml recursively. | ||
// The project directory is determined by the following logic: | ||
// * If an explicit directory is passed with -D, that is used | ||
// * Else, if repository URL isn't manually passed with -R, the directory of replicate.yaml is used | ||
// * Otherwise, the current working directory is used | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it do this? I forget the nuance of this logic now, but I thought we decided it should either be determined by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually had different logic for Python and Go. In Python we threw an error if no directory was explicitly passed and replicate.yaml wasn't found. In Go it defaulted to cwd. Throwing that error would result in a bunch of extra code to support both the training use case and checking out someone else's model (without a local replicate.yaml), so I ended up relaxing the explicit directory requirement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotchya. And this method is only used in the CLI, as far as I can see? In other words, nothing weird is going to happen when I call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That case should still error since repository URL is missing. |
||
// Returns (repositoryURL, projectDir, error) | ||
func getRepositoryURLFromStringOrConfig(repositoryURL string) (string, string, error) { | ||
projectDir := global.ProjectDirectory | ||
if repositoryURL == "" { | ||
conf, projectDir, err := config.FindConfigInWorkingDir(global.ProjectDirectory) | ||
conf, confProjectDir, err := config.FindConfigInWorkingDir(global.ProjectDirectory) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
return conf.Repository, projectDir, nil | ||
if repositoryURL == "" { | ||
repositoryURL = conf.Repository | ||
} | ||
if global.ProjectDirectory == "" { | ||
projectDir = confProjectDir | ||
} else { | ||
projectDir = global.ProjectDirectory | ||
} | ||
} | ||
|
||
// if global.ProjectDirectory == "", abs of that is cwd | ||
// FIXME (bfirsh): this does not look up directories for replicate.yaml, so might be the wrong | ||
// projectDir. It should probably use return value of FindConfigInWorkingDir. | ||
projectDir, err := filepath.Abs(global.ProjectDirectory) | ||
// abs of "" if cwd | ||
projectDir, err := filepath.Abs(projectDir) | ||
if err != nil { | ||
return "", "", fmt.Errorf("Failed to determine absolute directory of '%s': %w", global.ProjectDirectory, err) | ||
} | ||
|
@@ -71,14 +82,14 @@ func getProjectDir() (string, error) { | |
// getRepository returns the project's repository, with caching if needed | ||
// This is not in repository package so we can do user interface stuff around syncing | ||
func getRepository(repositoryURL, projectDir string) (repository.Repository, error) { | ||
repo, err := repository.ForURL(repositoryURL) | ||
repo, err := repository.ForURL(repositoryURL, projectDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// projectDir might be "" if you use --repository option | ||
if repository.NeedsCaching(repo) && projectDir != "" { | ||
console.Info("Fetching new data from %q...", repo.RootURL()) | ||
repo, err = repository.NewCachedMetadataRepository(repo, projectDir) | ||
repo, err = repository.NewCachedMetadataRepository(projectDir, repo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/replicate/replicate/go/pkg/project" | ||
"github.com/replicate/replicate/go/pkg/shared" | ||
) | ||
|
||
func NewDaemonCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "replicate-daemon <socket-path>", | ||
RunE: runDaemon, | ||
} | ||
setPersistentFlags(cmd) | ||
addRepositoryURLFlag(cmd) | ||
return cmd | ||
} | ||
|
||
func runDaemon(cmd *cobra.Command, args []string) error { | ||
socketPath := args[0] | ||
|
||
projectGetter := func() (proj *project.Project, err error) { | ||
repositoryURL, projectDir, err := getRepositoryURLFromFlagOrConfig(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
repo, err := getRepository(repositoryURL, projectDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
proj = project.NewProject(repo, projectDir) | ||
return proj, err | ||
} | ||
|
||
if err := shared.Serve(projectGetter, socketPath); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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.
Thinking out loud: this is so that goimports is installed locally and versioned with go modules.