Skip to content

Commit

Permalink
Regenerate Python SDK using recent OpenAPI Specification (#229)
Browse files Browse the repository at this point in the history
## Changes
Spec commit sha: 17a3f7fe6 (7 July 2023)

Breaking Changes:
* Use CONSTANT_CASE for Enum constants. Many enums already use constant
case in their definition, but some constants (like the SCIM Patch schema
name) includes symbols `:` and numbers, so the SDK cannot use the enum
value as the name.
* Replace Query type with AlertQuery in sql.Alert class.
* Removal of User.is_db_admin and User.profile_image_url.

Changes:
* Introduce CleanRooms API
* Introduce TablesAPI.update()
* Introduce Group.meta property
* Fix SCIM Patch implementation
* Introduce BaseRun.job_parameters and BaseRun.trigger_info
* Introduce CreateJob.parameters
* Fix spelling in file arrival trigger configuration
* Introduce GitSource.job_source
* Introduce RepairRun.rerun_dependent_tasks
* Introduce Resolved*Values classes, RunIf, and RunJobTask
* Introduce TaskNotificationSettings

Later follow-up:
* Names should split on Pascal-case word boundaries (see
CloudProviderNodeStatus). This is an OpenAPI code gen change that needs
to be made.
  • Loading branch information
mgyucht authored Jul 12, 2023
1 parent 734cb2f commit c9f7c41
Show file tree
Hide file tree
Showing 20 changed files with 1,254 additions and 204 deletions.
4 changes: 2 additions & 2 deletions .codegen/example.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import time, base64, os
{{- else if eq .Type "lookup" -}}
{{template "expr" .X}}.{{.Field.SnakeName}}
{{- else if eq .Type "enum" -}}
{{.Package}}.{{.Entity.PascalName}}.{{.Content}}{{if eq .Content "None"}}_{{end}}
{{.Package}}.{{.Entity.PascalName}}.{{.ConstantName}}
{{- else if eq .Type "variable" -}}
{{if eq .SnakeName "true"}}True
{{- else if eq .SnakeName "false"}}False
Expand Down Expand Up @@ -109,4 +109,4 @@ f'/Users/{w.current_user.me().user_name}/sdk-{time.time_ns()}'
{{- else -}}
{{.SnakeName}}({{range $i, $x := .Args}}{{if $i}}, {{end}}{{template "expr" .}}{{end}})
{{- end -}}
{{- end}}
{{- end}}
8 changes: 4 additions & 4 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Descriptio
{{else if .Enum}}class {{.PascalName}}(Enum):
{{if .Description}}"""{{.Comment " " 100 | trimSuffix "\"" }}"""{{end}}
{{range .Enum }}
{{.Content}}{{if eq .Content "None"}}_{{end}} = '{{.Content}}'{{end}}{{end}}
{{.ConstantName}} = '{{.Content}}'{{end}}{{end}}
{{end}}
{{- define "from_dict_type" -}}
{{- if not .Entity }}None
Expand Down Expand Up @@ -218,7 +218,7 @@ class {{.Name}}API:{{if .Description}}

{{define "method-call-paginated" -}}
{{if .Pagination.MultiRequest}}
{{if .Pagination.NeedsOffsetDedupe -}}
{{if .NeedsOffsetDedupe -}}
# deduplicate items that may have been added during iteration
seen = set()
{{- end}}{{if and .Pagination.Offset (not (eq .Path "/api/2.0/clusters/events")) }}
Expand All @@ -228,8 +228,8 @@ class {{.Name}}API:{{if .Description}}
if '{{.Pagination.Results.Name}}' not in json or not json['{{.Pagination.Results.Name}}']:
return
for v in json['{{.Pagination.Results.Name}}']:
{{if .Pagination.NeedsOffsetDedupe -}}
i = v['{{.Pagination.Entity.IdentifierField.Name}}']
{{if .NeedsOffsetDedupe -}}
i = v['{{.IdentifierField.Name}}']
if i in seen:
continue
seen.add(i)
Expand Down
3 changes: 2 additions & 1 deletion databricks/sdk/__init__.py

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

10 changes: 5 additions & 5 deletions databricks/sdk/dbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _running_command_context(self) -> compute.ContextStatusResponse:
return self._ctx
self._clusters.ensure_cluster_is_running(self._cluster_id)
self._ctx = self._commands.create(cluster_id=self._cluster_id,
language=compute.Language.python).result()
language=compute.Language.PYTHON).result()
return self._ctx

def __getattr__(self, util) -> '_ProxyUtil':
Expand Down Expand Up @@ -258,10 +258,10 @@ def __init__(self, *, command_execution: compute.CommandExecutionAPI,
_ascii_escape_re = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')

def _is_failed(self, results: compute.Results) -> bool:
return results.result_type == compute.ResultType.error
return results.result_type == compute.ResultType.ERROR

def _text(self, results: compute.Results) -> str:
if results.result_type != compute.ResultType.text:
if results.result_type != compute.ResultType.TEXT:
return ''
return self._out_re.sub("", str(results.data))

Expand Down Expand Up @@ -305,10 +305,10 @@ def __call__(self, *args, **kwargs):
'''
ctx = self._context_factory()
result = self._commands.execute(cluster_id=self._cluster_id,
language=compute.Language.python,
language=compute.Language.PYTHON,
context_id=ctx.id,
command=code).result()
if result.status == compute.CommandStatus.Finished:
if result.status == compute.CommandStatus.FINISHED:
self._raise_if_failed(result.results)
raw = result.results.data
return json.loads(raw)
Expand Down
77 changes: 58 additions & 19 deletions databricks/sdk/service/catalog.py

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

81 changes: 50 additions & 31 deletions databricks/sdk/service/compute.py

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

Loading

0 comments on commit c9f7c41

Please sign in to comment.