Skip to content

chore: Python v2 migration #135

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

Merged
merged 12 commits into from
Aug 18, 2024
Merged

chore: Python v2 migration #135

merged 12 commits into from
Aug 18, 2024

Conversation

speakeasybot
Copy link
Collaborator

@speakeasybot speakeasybot commented Jul 24, 2024

After merging these changes there are steps if you're using custom hooks.

Please see:
https://www.speakeasy.com/docs/python-migration#4-adjust-imports-for-python-v2

@awalker4 awalker4 force-pushed the python-v2-migration branch from 0f96076 to 7f75744 Compare July 25, 2024 19:16
awalker4 added a commit that referenced this pull request Aug 5, 2024
PDF page splitting uses asyncio but the SDK is not async. Therefore, we
had to manage our own event loop, which can lead to issues in other
event loop contexts. Uvloop is one context that does not allow us to use
nested event loops. When we find ourselves in a uvloop.Loop, we have to
fallback to non splitting mode. #135 will make the whole SDK async so we
don't have to hack this.

Closes #133
@awalker4 awalker4 force-pushed the python-v2-migration branch from c4602c4 to 37f3628 Compare August 14, 2024 01:09
@awalker4 awalker4 force-pushed the python-v2-migration branch from 37f3628 to ea55097 Compare August 14, 2024 01:09
* Update legacy partition calls that don't use PartitionRequest
* Update error response mock to use httpx
* Change legacy calls without PartitionRequest
* Update calls that don't use PartitionRequest
* Instances of shared.Files need to use keyword args
* Update request mocks to use httpx
@awalker4 awalker4 force-pushed the python-v2-migration branch 4 times, most recently from 4d8271a to d7836d2 Compare August 14, 2024 22:22
@awalker4 awalker4 force-pushed the python-v2-migration branch from d7836d2 to 9e9fa0a Compare August 17, 2024 21:16
@awalker4 awalker4 enabled auto-merge (squash) August 18, 2024 18:46
@awalker4 awalker4 merged commit 919b6ca into main Aug 18, 2024
6 of 7 checks passed
@awalker4 awalker4 deleted the python-v2-migration branch August 18, 2024 19:15
awalker4 added a commit that referenced this pull request Aug 21, 2024
Fix all mypy errors due to incorrect typing after the SDK v2 merge
(#135).
Logic changes should be minimal, this is mostly to change type hints
where a `httpx.Response` is used instead of a `requests.Response`, etc.
I removed some `form_utils.py` functions where we no longer need to
convert a httpx request back to Requests. There's more we can cleanup in
here, but let's get the V2 migration settled first.

Add mypy to `make lint` so that we can cath these errors before merging.
The publish job runs a full linter suite, and these changes made it to
main but broke the publish job.

Also, remove the Patch Custom Code step that I added to the generate.
This broke the job. There are some minor changes to the Speakeasy code
on the main branch. In the short term, this means we'll have to run
`make patch-custom-code` whenever we regenerate.

# To verify
Make sure you can lint and run the tests locally. `make lint` and `make
test`. You can also verify that the pdf split behavior has not changed
with a call to your local server:
```
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared, operations

import json

filename = "_sample_docs/layout-parser-paper.pdf"

s = UnstructuredClient(
    server_url="http://localhost:8000",
)

with open(filename, "rb") as f:
    files=shared.Files(
        content=f,
        file_name=filename,
    )

    req = operations.PartitionRequest(
        shared.PartitionParameters(
            files=files,
            strategy="fast",
            split_pdf_page_range=[4,8],
        ),
    )

    resp = s.general.partition(req)
    print(json.dumps(resp.elements, indent=4))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants