Skip to content

DRAFT - Use httpx as the transport#1046

Draft
da1910 wants to merge 24 commits into
mainfrom
feat/httpx
Draft

DRAFT - Use httpx as the transport#1046
da1910 wants to merge 24 commits into
mainfrom
feat/httpx

Conversation

@da1910

@da1910 da1910 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

In Progress

@codacy-production

codacy-production Bot commented May 8, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 344 complexity · 84 duplication

Metric Results
Complexity 344
Duplication 84

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.37349% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.28%. Comparing base (c2ec3a6) to head (392354c).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/ansys/openapi/common/_api_client.py 94.53% 10 Missing ⚠️
src/ansys/openapi/common/_oidc.py 87.14% 9 Missing ⚠️
src/ansys/openapi/common/_util.py 90.54% 7 Missing ⚠️
src/ansys/openapi/common/_session.py 89.47% 4 Missing ⚠️
src/ansys/openapi/common/_case_insensitive_dict.py 90.90% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1046      +/-   ##
==========================================
- Coverage   94.79%   94.28%   -0.51%     
==========================================
  Files           7        9       +2     
  Lines         807     1155     +348     
==========================================
+ Hits          765     1089     +324     
- Misses         42       66      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added documentation Improvements or additions to documentation enhancement New features or code improvements dependencies Related with project dependencies maintenance Package and maintenance related labels May 8, 2026

@Andy-Grigg Andy-Grigg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major concerns. Various comments, some specific, some general.

Comment thread src/ansys/openapi/common/_api_client.py Outdated
Comment thread src/ansys/openapi/common/_api_client.py Outdated
Comment thread src/ansys/openapi/common/_api_client.py Outdated
Examples
--------
>>> client = ApiClient(requests.Session(),
>>> transport = httpx.MockTransport(lambda request: httpx.Response(200))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question here about the intended audience for the example here. Although again, I suppose this is on the 'generic' ApiClient class.

But even then, would the user be expected to instantiate their own transport class, or would we expect the PyGranta package (or bindings) to do that automatically?

response_type_map,
)

@staticmethod

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of what looks like boilerplate here. Is this just httpx doing less hand-holding than requests?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, its more that requests exposes a very permissive API and handles it, it's very "python 2.x" whereas httpx has more type requirements. This just ensures that we translate the old requests style arguments into new httpx style ones (bytes for content)

Comment thread src/ansys/openapi/common/_api_client.py Outdated
def _url_with_query_string(url: str, query_params: Optional[str]) -> str:
if not query_params:
return url
return f"{url}&{query_params}" if "?" in url else f"{url}?{query_params}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of odd. What problem is being solved here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles merging the url with query parameters - if the user provides a base url that already has query parameters we need to merge them, this is actually quite a bad solution - I will do something better...

Comment thread src/ansys/openapi/common/_oidc.py Outdated
Comment thread src/ansys/openapi/common/_oidc.py Outdated
Comment thread src/ansys/openapi/common/_retry_transport.py Outdated
Comment thread src/ansys/openapi/common/_retry_transport.py
Comment thread pyproject.toml
da1910 and others added 20 commits May 19, 2026 13:11
Move the explicit doc/_build/ rule next to Sphinx-related comments so local
html/latex output stays ignored; keep _autosummary documented separately.

Co-authored-by: Cursor <cursoragent@cursor.com>
Vendor Requests-style CaseInsensitiveDict (Apache-2.0 attribution) for
session headers and exception snapshots. Export CaseInsensitiveDict from the
public package. Restrict ApiException / ApiClientBase signatures to
httpx.Response.

Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce urllib3-style retries on a custom httpx.HTTPTransport. Wire
TransportConfiguration into httpx.Client construction, WWW-Authenticate
collection via httpx.Headers.get_list, and drop the old requests session
shims from utilities.

Co-authored-by: Cursor <cursoragent@cursor.com>
Require httpx.Client for ApiClient.request paths and deserialization. Rebuild
ApiClientFactory on httpx with platform auth (NTLM, Negotiate, OIDC) and fix
probe URL handling. Port OIDCSessionFactory to httpx-auth and typed
TransportConfiguration round-trips.

Co-authored-by: Cursor <cursoragent@cursor.com>
Replace requests-mock with pytest-httpx; align dispatch and multipart tests with
httpx.Client.request. Update session, OIDC, exception, and integration tests for
httpx responses and factory behaviour. Add retry transport unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the requests stack from core dependencies; refresh the lockfile.
Add per-module mypy overrides so Windows CI passes without per-import ignores
when optional httpx auth extras are present or absent.

Co-authored-by: Cursor <cursoragent@cursor.com>
Link the engineering plan from the doc toctree; record vendoring, test
strategy, and phased rollout decisions.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ctory session headers

Updated documentation to specify that the headers in `idp_session_configuration` are not fully respected for IdP HTTP clients, particularly regarding the `Accept` and `Content-Type` headers. Added a test to ensure that the initial probe to the API uses only the factory's session headers, confirming the expected behavior of the `ApiClientFactory`.
Generated clients always used the default; the flag was wired incorrectly
to streaming for requests. call_api now always deserializes and raises
ApiException with a parsed exception model on error. request() no longer
accepts _preload_content. Add brief docstrings on context manager methods
for pydocstyle.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use a single optional outbound proxy URL and route it through one httpx
mount keyed by the API (or IdP) scheme from mount_scheme_url.
ApiClientFactory passes api_url; OIDC passes authority or resource URL.
Remove per-scheme dict handling and NotImplementedError paths from client
init kwargs. Update tests and user guide.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add .valeignore for Sphinx _build and api/_autosummary output.
- Extend ANSYS Vale accept list (httpx, certifi, conda, OpenSSL).
- Reword user guide HTTPS/session section for Google rules and spacing.
- Fix RetryingHTTPTransport docstrings (numpy style, handle_request).
- Split pydocstyle pre-commit: skip D105/D102 on vendored CaseInsensitiveDict.

Co-authored-by: Cursor <cursoragent@cursor.com>
…F401

- Remove httpx from intersphinx_mapping (no Sphinx objects.inv on MkDocs site).
- Reorder ApiClient class docstring to Parameters, Notes, Examples (GL07).
- Remove unused typing.Any import in _exceptions.py.

Co-authored-by: Cursor <cursoragent@cursor.com>
Expose AsyncApiClient from the public package, wire async request paths
through the existing client stack, and align retry transport and session
utilities with async-capable httpx usage. Add unit tests for the async
client surface and updated retry behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>
Factor Uvicorn apps into fixture_apps with shared /models routes, add
server_utils and async_integration helpers, and extend basic, anonymous,
and negotiate suites with parametrized GET/POST/PUT/DELETE/HEAD/OPTIONS
checks alongside existing PATCH coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Added tests to ensure AsyncApiClient correctly rejects sync clients and handles async client closure.
- Implemented tests for OIDCSessionFactory to verify audience header handling in API and IDP configurations.
- Included checks for proper error handling when invalid HTTP clients are used.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Related with project dependencies documentation Improvements or additions to documentation enhancement New features or code improvements maintenance Package and maintenance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants