Skip to content

Commit 643ed88

Browse files
authored
chore: revert custom changes to autogenerated code (#181)
# The issue The v2 python client has some minor breaking changes for our users, both related to keyword parameters: * The PartitionRequest class is now a pydantic model which does not support positional arguments in the constructor. Therefore we always have to name the `partition_parameters` field. ``` req = operations.PartitionRequest( shared.PartitionParameters( .... .... ) ) ``` becomes ``` req = operations.PartitionRequest( partition_parameters=shared.PartitionParameters( .... .... ) ) ``` * Likewise, the function signature for `general.partition` no longer allows for positional args. Instead of ``` response = client.general.partition(req) ``` we have to do ``` response = client.general.partition(request=req) ``` # The first approach These are minimal changes, but they will disrupt a number of users who have copied our sample snippets in the past. My workaround for this was to manually patch the autogenerated code to bring back positional params. However, this will be messy in the long term, as we now have to apply our changes after every regenerate. Instead, let's embrace the version bump to 0.16.0 and just document the breaking change. Update: The python snippet in the serverless dashboard uses keyword args, so users who copied this out are unaffected. # Changes - Revert my manual edits to: - Allow `request` as a positional arg in `general.partition` (`general.py`) - Add a constructor to `PartitionRequest` so we don't have to use a keyword arg - Remove the patch file containing these changes - Update some makefile commands to reuse in other repos
1 parent 5954e72 commit 643ed88

File tree

6 files changed

+12
-42
lines changed

6 files changed

+12
-42
lines changed

Diff for: Makefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ install:
1414
python scripts/prepare-readme.py
1515
poetry install
1616

17+
## install-speakeasy-cli: download the speakeasy cli tool
18+
.PHONY: install-speakeasy-cli
19+
install-speakeasy-cli:
20+
curl -fsSL https://raw.githubusercontent.com/speakeasy-api/speakeasy/main/install.sh | sh
21+
1722
#################
1823
# Test and Lint #
1924
#################
@@ -48,24 +53,21 @@ lint:
4853
# Speakeasy #
4954
#############
5055

56+
## client-generate: Pull the openapi spec from the free hosted API and generate the SDK
5157
.PHONY: client-generate
5258
client-generate:
5359
wget -nv -q -O openapi.json https://api.unstructured.io/general/openapi.json
5460
speakeasy overlay validate -o ./overlay_client.yaml
5561
speakeasy overlay apply -s ./openapi.json -o ./overlay_client.yaml > ./openapi_client.json
5662
speakeasy generate sdk -s ./openapi_client.json -o ./ -l python
5763

64+
## client-generate-local: Generate the SDK using a local copy of openapi.json
5865
.PHONY: client-generate-local
5966
client-generate-local:
60-
wget -nv -q -O openapi.json http://localhost:5000/general/openapi.json
6167
speakeasy overlay validate -o ./overlay_client.yaml
6268
speakeasy overlay apply -s ./openapi.json -o ./overlay_client.yaml > ./openapi_client.json
6369
speakeasy generate sdk -s ./openapi_client.json -o ./ -l python
6470

65-
.PHONY: patch-custom-code
66-
patch-custom-code:
67-
git apply _custom_code.patch
68-
6971
.PHONY: publish
7072
publish:
7173
./scripts/publish.sh

Diff for: _custom_code.patch

-29
This file was deleted.

Diff for: _test_unstructured_client/integration/test_decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ async def mock_send(_, request: httpx.Request, **kwargs):
356356
)
357357

358358
req = operations.PartitionRequest(
359-
shared.PartitionParameters(
359+
partition_parameters=shared.PartitionParameters(
360360
files=files,
361361
split_pdf_page=True,
362362
split_pdf_allow_failed=False,

Diff for: _test_unstructured_client/unit/test_custom_hooks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ def mock_post(request):
122122
files = shared.Files(content=f.read(), file_name=filename)
123123

124124
req = operations.PartitionRequest(
125-
shared.PartitionParameters(files=files)
125+
partition_parameters=shared.PartitionParameters(files=files)
126126
)
127127

128128
with pytest.raises(Exception, match=f"Status {status_code}"):
129-
session.general.partition(req, retries=retries)
129+
session.general.partition(request=req, retries=retries)
130130

131131
if expect_retry:
132132
assert number_of_requests[0] > 1

Diff for: src/unstructured_client/general.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
class General(BaseSDK):
1212
def partition(
1313
self,
14+
*,
1415
request: Union[
1516
operations.PartitionRequest, operations.PartitionRequestTypedDict
1617
],
17-
*,
1818
retries: OptionalNullable[utils.RetryConfig] = UNSET,
1919
server_url: Optional[str] = None,
2020
timeout_ms: Optional[int] = None,
@@ -116,10 +116,10 @@ def partition(
116116

117117
async def partition_async(
118118
self,
119+
*,
119120
request: Union[
120121
operations.PartitionRequest, operations.PartitionRequestTypedDict
121122
],
122-
*,
123123
retries: OptionalNullable[utils.RetryConfig] = UNSET,
124124
server_url: Optional[str] = None,
125125
timeout_ms: Optional[int] = None,

Diff for: src/unstructured_client/models/operations/partition.py

-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class PartitionRequestTypedDict(TypedDict):
2525

2626

2727
class PartitionRequest(BaseModel):
28-
def __init__(self, partition_parameters, **kwargs):
29-
BaseModel.__init__(self, partition_parameters=partition_parameters, **kwargs)
30-
3128
partition_parameters: Annotated[
3229
shared_partition_parameters.PartitionParameters,
3330
FieldMetadata(request=RequestMetadata(media_type="multipart/form-data")),

0 commit comments

Comments
 (0)