Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .codegen/__init__.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def _make_dbutils(config: client.Config):


class WorkspaceClient:
"""
The WorkspaceClient is a client for the workspace-level Databricks REST API.
"""
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
debug_truncate_bytes: int = None,
debug_headers: bool = None,
Expand All @@ -52,10 +55,17 @@ class WorkspaceClient:
self.config = config.copy()
self.dbutils = _make_dbutils(self.config)
self.api_client = client.ApiClient(self.config)

{{- range .Services}}{{if not .IsAccounts}}
self.{{.SnakeName}} = {{template "api" .}}(self.api_client){{end -}}{{end}}
self.{{.SnakeName}}: {{template "api" .}} = {{template "api" .}}(self.api_client){{if .Description}}
"""{{.Comment " " 100}}"""{{end}}
{{end -}}{{end}}

class AccountClient:
"""
The AccountClient is a client for the account-level Databricks REST API.
"""

def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
debug_truncate_bytes: int = None,
debug_headers: bool = None,
Expand All @@ -72,5 +82,8 @@ class AccountClient:
product_version=product_version)
self.config = config.copy()
self.api_client = client.ApiClient(self.config)

{{- range .Services}}{{if .IsAccounts}}
self.{{(.TrimPrefix "account").SnakeName}} = {{template "api" .}}(self.api_client){{end -}}{{end}}
self.{{.SnakeName}}: {{template "api" .}} = {{template "api" .}}(self.api_client){{if .Description}}
"""{{.Comment " " 100}}"""{{end}}
{{end -}}{{end}}
24 changes: 16 additions & 8 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import random
import logging
from ..errors import OperationTimeout, OperationFailed
from ._internal import _enum, _from_dict, _repeated_dict, _repeated_enum, Wait
from __future__ import annotations

_LOG = logging.getLogger('databricks.sdk')

Expand All @@ -21,17 +22,24 @@ from databricks.sdk.service import {{.Package.Name}}{{end}}
class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Description}}
"""{{.Comment " " 100}}"""
{{end}}{{- range .RequiredFields | alphanumOnly}}
{{template "safe-snake-name" .}}: {{template "type" .Entity}}{{end}}{{- range .NonRequiredFields | alphanumOnly}}
{{template "safe-snake-name" .}}: Optional[{{template "type" .Entity}}] = None{{end}}
{{template "safe-snake-name" .}}: {{template "type" .Entity}}{{if .Description}}
"""{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
{{end}}
{{- range .NonRequiredFields | alphanumOnly}}
{{template "safe-snake-name" .}}: Optional[{{template "type" .Entity}}] = None{{if .Description}}
"""{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
{{end}}
{{if .HasJsonField -}}
def as_dict(self) -> dict:
"""Serializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} into a dictionary suitable for use as a JSON request body."""
body = {}
{{range .Fields | alphanumOnly}}if self.{{template "safe-snake-name" .}}{{with .Entity.IsPrimitive}} is not None{{end}}: body['{{.Name}}'] = {{template "as_request_type" .}}
{{end -}}
return body

@classmethod
def from_dict(cls, d: Dict[str, any]) -> '{{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}':
def from_dict(cls, d: Dict[str, any]) -> {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:
"""Deserializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} from a dictionary."""
return cls({{range $i, $f := .Fields | alphanumOnly}}{{if $i}}, {{end}}{{template "safe-snake-name" $f}}={{template "from_dict_type" $f}}{{end}})
{{end}}
{{end}}
Expand Down Expand Up @@ -62,11 +70,11 @@ class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Descriptio
{{- end -}}
{{- define "type" -}}
{{- if not . }}any # ERROR: No Type
{{- else if .ArrayValue }}'List[{{template "type-nq" .ArrayValue}}]'
{{- else if .MapValue }}'Dict[str,{{template "type-nq" .MapValue}}]'
{{- else if .IsExternal }}'{{.Package.Name}}.{{.PascalName}}'
{{- else if .IsObject }}'{{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}'
{{- else if .Enum }}'{{.PascalName}}'
{{- else if .ArrayValue }}List[{{template "type-nq" .ArrayValue}}]
{{- else if .MapValue }}Dict[str,{{template "type-nq" .MapValue}}]
{{- else if .IsExternal }}{{.Package.Name}}.{{.PascalName}}
{{- else if .IsObject }}{{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}
{{- else if .Enum }}{{.PascalName}}
{{- else}}{{template "type-nq" .}}{{- end -}}
{{- end -}}
{{- define "type-nq" -}}
Expand Down
Loading