diff --git a/.release-please-manifest.json b/.release-please-manifest.json index cce92405..dbe5ddf4 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.3.1" + ".": "0.3.2" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b9e6239..9a9608c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.3.2 (2023-10-27) + +Full Changelog: [v0.3.1...v0.3.2](https://github.com/Finch-API/finch-api-python/compare/v0.3.1...v0.3.2) + +### Chores + +* **internal:** minor restructuring of base client ([#158](https://github.com/Finch-API/finch-api-python/issues/158)) ([4aee7a7](https://github.com/Finch-API/finch-api-python/commit/4aee7a757122de18ee54ccecc5a5698e19511aaf)) + ## 0.3.1 (2023-10-27) Full Changelog: [v0.3.0...v0.3.1](https://github.com/Finch-API/finch-api-python/compare/v0.3.0...v0.3.1) diff --git a/pyproject.toml b/pyproject.toml index ce9c3b94..85213d1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "finch-api" -version = "0.3.1" +version = "0.3.2" description = "Client library for the Finch API" readme = "README.md" license = "Apache-2.0" @@ -13,7 +13,7 @@ dependencies = [ "typing-extensions>=4.5, <5", "anyio>=3.5.0, <4", "distro>=1.7.0, <2", - + ] requires-python = ">= 3.7" @@ -39,7 +39,7 @@ dev-dependencies = [ "time-machine==2.9.0", "nox==2023.4.22", "dirty-equals>=0.6.0", - + ] [tool.rye.scripts] diff --git a/src/finch/_base_client.py b/src/finch/_base_client.py index 6e4be17a..5ed9f54d 100644 --- a/src/finch/_base_client.py +++ b/src/finch/_base_client.py @@ -399,18 +399,6 @@ def _build_headers(self, options: FinalRequestOptions) -> httpx.Headers: return headers - def _prepare_request( - self, - request: httpx.Request, # noqa: ARG002 - ) -> None: - """This method is used as a callback for mutating the `Request` object - after it has been constructed. - - This is useful for cases where you want to add certain headers based off of - the request properties, e.g. `url`, `method` etc. - """ - return None - def _prepare_url(self, url: str) -> URL: """ Merge a URL argument together with any 'base_url' on the client, @@ -463,7 +451,7 @@ def _build_request( kwargs["data"] = self._serialize_multipartform(json_data) # TODO: report this error to httpx - request = self._client.build_request( # pyright: ignore[reportUnknownMemberType] + return self._client.build_request( # pyright: ignore[reportUnknownMemberType] headers=headers, timeout=self.timeout if isinstance(options.timeout, NotGiven) else options.timeout, method=options.method, @@ -477,8 +465,6 @@ def _build_request( files=options.files, **kwargs, ) - self._prepare_request(request) - return request def _serialize_multipartform(self, data: Mapping[object, object]) -> dict[str, object]: items = self.qs.stringify_items( @@ -781,6 +767,24 @@ def __exit__( ) -> None: self.close() + def _prepare_options( + self, + options: FinalRequestOptions, # noqa: ARG002 + ) -> None: + """Hook for mutating the given options""" + return None + + def _prepare_request( + self, + request: httpx.Request, # noqa: ARG002 + ) -> None: + """This method is used as a callback for mutating the `Request` object + after it has been constructed. + This is useful for cases where you want to add certain headers based off of + the request properties, e.g. `url`, `method` etc. + """ + return None + @overload def request( self, @@ -842,8 +846,11 @@ def _request( stream: bool, stream_cls: type[_StreamT] | None, ) -> ResponseT | _StreamT: + self._prepare_options(options) + retries = self._remaining_retries(remaining_retries, options) request = self._build_request(options) + self._prepare_request(request) try: response = self._client.send(request, auth=self.custom_auth, stream=stream) @@ -1201,6 +1208,24 @@ async def __aexit__( ) -> None: await self.close() + async def _prepare_options( + self, + options: FinalRequestOptions, # noqa: ARG002 + ) -> None: + """Hook for mutating the given options""" + return None + + async def _prepare_request( + self, + request: httpx.Request, # noqa: ARG002 + ) -> None: + """This method is used as a callback for mutating the `Request` object + after it has been constructed. + This is useful for cases where you want to add certain headers based off of + the request properties, e.g. `url`, `method` etc. + """ + return None + @overload async def request( self, @@ -1262,8 +1287,11 @@ async def _request( stream_cls: type[_AsyncStreamT] | None, remaining_retries: int | None, ) -> ResponseT | _AsyncStreamT: + await self._prepare_options(options) + retries = self._remaining_retries(remaining_retries, options) request = self._build_request(options) + await self._prepare_request(request) try: response = await self._client.send(request, auth=self.custom_auth, stream=stream) diff --git a/src/finch/_version.py b/src/finch/_version.py index 59e35a47..8ed7b4ed 100644 --- a/src/finch/_version.py +++ b/src/finch/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. __title__ = "finch" -__version__ = "0.3.1" # x-release-please-version +__version__ = "0.3.2" # x-release-please-version