Skip to content

Commit

Permalink
Make code working with new OpenAPI packaging (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx authored Apr 20, 2023
1 parent 006bbef commit f05ccd2
Show file tree
Hide file tree
Showing 36 changed files with 7,392 additions and 6,907 deletions.
19 changes: 13 additions & 6 deletions .codegen/__init__.py.tmpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{{range .Packages}}
import databricks.sdk.service.{{.Name}} as {{.Name}}{{end}}
import databricks.sdk.core as client
import databricks.sdk.dbutils as dbutils
import databricks.sdk.mixins.dbfs as dbfs_mixin
import databricks.sdk.mixins.compute as compute_mixin

from databricks.sdk.mixins.dbfs import DbfsExt
from databricks.sdk.mixins.compute import ClustersExt
{{- range .Services}}
from databricks.sdk.service.{{.Package.Name}} import {{.PascalName}}API{{end}}

{{$args := list "host" "account_id" "username" "password" "client_id" "client_secret"
"token" "profile" "config_file" "azure_workspace_resource_id" "azure_client_secret"
"azure_client_id" "azure_tenant_id" "azure_environment" "auth_type" "cluster_id"}}

{{- define "api" -}}
{{- $mixins := dict "ClustersAPI" "ClustersExt" "DbfsAPI" "DbfsExt" -}}
{{- $genApi := concat .PascalName "API" -}}
{{- getOrDefault $mixins $genApi $genApi -}}
{{- end -}}

class WorkspaceClient:
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
debug_truncate_bytes: int = None,
Expand All @@ -28,7 +35,7 @@ class WorkspaceClient:
self.dbutils = dbutils.RemoteDbUtils(self.config)
self.api_client = client.ApiClient(self.config)
{{- range .Services}}{{if not .IsAccounts}}
self.{{.SnakeName}} = {{if eq .SnakeName "dbfs"}}dbfs_mixin.DbfsExt{{else if eq .SnakeName "clusters"}}compute_mixin.ClustersExt{{else}}{{.Package.Name}}.{{.Name}}API{{end}}(self.api_client){{end -}}{{end}}
self.{{.SnakeName}} = {{template "api" .}}(self.api_client){{end -}}{{end}}

class AccountClient:
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
Expand All @@ -48,4 +55,4 @@ class AccountClient:
self.config = config
self.api_client = client.ApiClient(self.config)
{{- range .Services}}{{if .IsAccounts}}
self.{{.SnakeName}} = {{.Package.Name}}.{{.Name}}API(self.api_client){{end -}}{{end}}
self.{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self.api_client){{end -}}{{end}}
29 changes: 9 additions & 20 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
databricks/sdk/__init__.py linguist-generated=true
databricks/sdk/service/billing.py linguist-generated=true
databricks/sdk/service/clusterpolicies.py linguist-generated=true
databricks/sdk/service/clusters.py linguist-generated=true
databricks/sdk/service/commands.py linguist-generated=true
databricks/sdk/service/dbfs.py linguist-generated=true
databricks/sdk/service/deployment.py linguist-generated=true
databricks/sdk/service/endpoints.py linguist-generated=true
databricks/sdk/service/gitcredentials.py linguist-generated=true
databricks/sdk/service/globalinitscripts.py linguist-generated=true
databricks/sdk/service/instancepools.py linguist-generated=true
databricks/sdk/service/ipaccesslists.py linguist-generated=true
databricks/sdk/service/catalog.py linguist-generated=true
databricks/sdk/service/compute.py linguist-generated=true
databricks/sdk/service/files.py linguist-generated=true
databricks/sdk/service/iam.py linguist-generated=true
databricks/sdk/service/jobs.py linguist-generated=true
databricks/sdk/service/libraries.py linguist-generated=true
databricks/sdk/service/mlflow.py linguist-generated=true
databricks/sdk/service/ml.py linguist-generated=true
databricks/sdk/service/oauth2.py linguist-generated=true
databricks/sdk/service/permissions.py linguist-generated=true
databricks/sdk/service/pipelines.py linguist-generated=true
databricks/sdk/service/repos.py linguist-generated=true
databricks/sdk/service/scim.py linguist-generated=true
databricks/sdk/service/secrets.py linguist-generated=true
databricks/sdk/service/provisioning.py linguist-generated=true
databricks/sdk/service/serving.py linguist-generated=true
databricks/sdk/service/settings.py linguist-generated=true
databricks/sdk/service/sharing.py linguist-generated=true
databricks/sdk/service/sql.py linguist-generated=true
databricks/sdk/service/tokenmanagement.py linguist-generated=true
databricks/sdk/service/tokens.py linguist-generated=true
databricks/sdk/service/unitycatalog.py linguist-generated=true
databricks/sdk/service/workspace.py linguist-generated=true
databricks/sdk/service/workspaceconf.py linguist-generated=true
225 changes: 121 additions & 104 deletions databricks/sdk/__init__.py
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f05ccd2

Please sign in to comment.