Part of #1285.
Background
We want to minimize pyvespa's runtime dependency surface (see #1285). vespa/models.py is one of the last places in vespa/ still importing requests directly.
Scope
Replace requests usage in vespa/models.py:_validate_single_url so this file no longer needs requests.
Current usage
vespa/models.py:8 — import requests
vespa/models.py:276 — requests.head(url, timeout=10, allow_redirects=True)
vespa/models.py:279 — requests.get(url, timeout=10, stream=True, allow_redirects=True) (fallback when HEAD doesn't return 200)
vespa/models.py:287 — except requests.RequestException
Used to validate user-supplied model_url / tokenizer_url values.
Approach
Recommended: use stdlib urllib.request (one-shot validation, no pooling needed — one fewer thing depending on httpr surface area).
Alternative: use httpr.head / httpr.get (sync API) — fine if httpr is already a runtime dep.
Update the exception handler from requests.RequestException to the new equivalent.
Tasks
Out of scope
Risk
Very low. Pure refactor of a validation helper, no public API change.
Part of #1285.
Background
We want to minimize pyvespa's runtime dependency surface (see #1285).
vespa/models.pyis one of the last places invespa/still importingrequestsdirectly.Scope
Replace
requestsusage invespa/models.py:_validate_single_urlso this file no longer needsrequests.Current usage
vespa/models.py:8—import requestsvespa/models.py:276—requests.head(url, timeout=10, allow_redirects=True)vespa/models.py:279—requests.get(url, timeout=10, stream=True, allow_redirects=True)(fallback when HEAD doesn't return 200)vespa/models.py:287—except requests.RequestExceptionUsed to validate user-supplied
model_url/tokenizer_urlvalues.Approach
Recommended: use stdlib
urllib.request(one-shot validation, no pooling needed — one fewer thing depending on httpr surface area).Alternative: use
httpr.head/httpr.get(sync API) — fine if httpr is already a runtime dep.Update the exception handler from
requests.RequestExceptionto the new equivalent.Tasks
requests.head/requests.getcallsimport requestsfromvespa/models.pypytest-httpserveror a local socket — don't mock the HTTP library directly@retry(stop=stop_after_attempt(3), ...))Out of scope
requestsfrompyproject.toml— that's PR 4 (Deps cleanup PR 4: Remove requests/requests_toolbelt/httpx from pyproject.toml #1289)Risk
Very low. Pure refactor of a validation helper, no public API change.