Skip to content

Commit

Permalink
fix: httpclient doc (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurD1 committed Nov 14, 2024
1 parent 86ab5fa commit e6a77d3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions docs/apps/http_client/examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_client:
# Customize the httpx transport layer (optional)
transport:
# This is the default, only set if you want to use a custom transport. Most users don't need to set this.
"@type": "httpx:AsyncHTTPTransport"
type: httpx.AsyncHTTPTransport

# Cache configuration (optional, enabled by default)
cache:
Expand All @@ -15,7 +15,7 @@ http_client:
# Override the cache controller definition (optional)
controller:
# This is the default, only set if you want to use a custom controller.
"@type": "hishel:Controller"
type: hishel.Controller

# You can configure anything the hishel cache controller would accept as a keyword argument.
# See https://hishel.com/advanced/controllers/ for more information.
Expand All @@ -36,7 +36,7 @@ http_client:
# layer extending the base http client features with caching.
transport:
# This is the default, only set if you want to use a custom cache transport.
"@type": "hishel:AsyncCacheTransport"
type: hishel.AsyncCacheTransport

# If your hishel compatible transport class take more kwargs, you can pass more stuff here.
# See https://hishel.com/userguide/#clients-and-transports
Expand All @@ -45,7 +45,7 @@ http_client:
# Please note that we plan to allow to share other harp storages here in the future.
storage:
# This is the default, only set if you want to use a custom cache storage.
"@type": "hishel:AsyncFileStorage"
type: hishel.AsyncFileStorage

# If your hishel compatible storage class take more kwargs, you can pass more stuff here.
# See https://hishel.com/advanced/storages/
2 changes: 1 addition & 1 deletion docs/apps/http_client/examples/simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ http_client:
transport:
# You can customize the default transport implementation. The values shown are the
# defaults, and you only need to set them if you want to provide different values.
"@type": "httpx:AsyncHTTPTransport"
type: httpx.AsyncHTTPTransport
retries: 0
verify: true
http1: true
Expand Down
6 changes: 5 additions & 1 deletion harp/config/configurables/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from keyword import iskeyword
from typing import Optional

from pydantic import ConfigDict, Field, model_serializer, model_validator
Expand Down Expand Up @@ -30,7 +31,10 @@ def __validate(cls, values):
arguments = values.get("arguments", {})
for k in list(values.keys()):
if k not in cls.model_fields:
arguments[k] = values.pop(k)
if str.isidentifier(k) and not iskeyword(k):
arguments[k] = values.pop(k)
else:
raise ValueError(f"Invalid field name: {k} for {cls.__name__}")
if len(arguments):
return {**values, "arguments": arguments}
return values
Expand Down
10 changes: 4 additions & 6 deletions harp/config/tests/__snapshots__/test_all_examples.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
http_client:
cache:
controller:
'@type': hishel:Controller
allow_heuristics: true
allow_stale: true
cacheable_methods:
Expand All @@ -142,13 +141,12 @@
- 200
- 301
- 308
type: hishel.Controller
storage:
'@type': hishel:AsyncFileStorage
transport:
'@type': hishel:AsyncCacheTransport
type: hishel.AsyncFileStorage
timeout: 10.0
transport:
'@type': httpx:AsyncHTTPTransport
type: httpx.AsyncHTTPTransport
proxy: {}
storage: {}

Expand All @@ -171,10 +169,10 @@
http_client:
timeout: 10.0
transport:
'@type': httpx:AsyncHTTPTransport
http1: true
http2: false
retries: 0
type: httpx.AsyncHTTPTransport
verify: true
proxy: {}
storage: {}
Expand Down
1 change: 1 addition & 0 deletions harp/config/tests/test_all_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_load_documentation_example(configfile, snapshot):
from harp.config import ConfigurationBuilder

builder = ConfigurationBuilder()
## TODO : remove when rules enabled by default
if configfile.startswith("docs/apps/rules/"):
builder.applications.add("rules")
builder.add_file(os.path.join(harp.ROOT_DIR, configfile))
Expand Down

0 comments on commit e6a77d3

Please sign in to comment.