-
Notifications
You must be signed in to change notification settings - Fork 705
Add doc string for models in sqlflow_models #1717
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ package attribute | |
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "log" | ||
| "os/exec" | ||
| "reflect" | ||
| "sort" | ||
| "strings" | ||
|
|
@@ -158,6 +160,18 @@ func NewDictionaryFromModelDefinition(estimator, prefix string) Dictionary { | |
| // PremadeModelParamsDocs stores parameters and documents of all known models | ||
| var PremadeModelParamsDocs map[string]map[string]string | ||
|
|
||
| // ExtractDocString extracts parameter documents from python doc strings | ||
| func ExtractDocString(module ...string) { | ||
| cmd := exec.Command("python", "-uc", fmt.Sprintf("__import__('extract_docstring').print_param_doc('%s')", strings.Join(module, "', '"))) | ||
| output, e := cmd.CombinedOutput() | ||
| if e != nil { | ||
| log.Println("ExtractDocString failed: ", e, string(output)) | ||
| } | ||
| if e := json.Unmarshal(output, &PremadeModelParamsDocs); e != nil { | ||
|
Collaborator
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. Maybe add a comment that unmarshal can append entries rather than overwrite it: https://golang.org/pkg/encoding/json/#Unmarshal |
||
| log.Println("ExtractDocString failed:", e, string(output)) | ||
| } | ||
| } | ||
|
|
||
| func removeUnnecessaryParams() { | ||
| // The following parameters of canned estimators are already supported in the COLUMN clause. | ||
| for _, v := range PremadeModelParamsDocs { | ||
|
|
@@ -171,5 +185,6 @@ func init() { | |
| if err := json.Unmarshal([]byte(ModelParameterJSON), &PremadeModelParamsDocs); err != nil { | ||
| panic(err) // assertion | ||
| } | ||
| ExtractDocString("sqlflow_models") | ||
| removeUnnecessaryParams() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ DATASOURCE="mysql://root:root@tcp(127.0.0.1:3306)/?maxAllowedPacket=0" | |
| export PYTHONPATH=$GOPATH/src/sqlflow.org/sqlflow/python | ||
|
|
||
| sqlflowserver & | ||
| sleep 10 | ||
|
Collaborator
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. Is it possible to change this sleep to a while loop that pings the SQLFlow server? |
||
| # e2e test for standard SQL | ||
| SQLFLOW_DATASOURCE=${DATASOURCE} SQLFLOW_SERVER=localhost:50051 ipython python/test_magic.py | ||
| # TODO(yi): Re-enable the end-to-end test of Ant XGBoost after accelerating Travis CI. | ||
|
|
||
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.
Should we make a local call here to print the docstring, other than start a process?
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.
That's somewhat hard to implement because we have to import the classes to get the docstrings. I have investigated several python bindings of golang but they are either too primitive (go-python) or not as reliable.