|
| 1 | +# polywrap-client-config-builder |
1 | 2 |
|
2 | | -# Polywrap Python Client |
3 | | -## This object allows you to build proper Polywrapt ClientConfig objects |
| 3 | +A utility class for building the PolywrapClient config. |
4 | 4 |
|
5 | | -These objects are needed to configure your python client's wrappers, pluggins, env variables, resolvers and interfaces. |
| 5 | +Supports building configs using method chaining or imperatively. |
6 | 6 |
|
7 | | -Look at [this file](./polywrap_client_config_builder/client_config_builder.py) to detail all of its functionality |
8 | | -And at [tests](./tests/test_client_config_builder.py) |
| 7 | +## Quickstart |
9 | 8 |
|
10 | | ---- |
| 9 | +### Initialize |
11 | 10 |
|
12 | | -The current implementation uses the `ClientConfig` as a dataclass to later create an Abstract Base Class of a `BaseClientConfigBuilder` which defines more clearly the functions of the module, like add_envs, set_resolvers, remove_wrappers, and so on. |
| 11 | +Initialize a ClientConfigBuilder using the constructor |
13 | 12 |
|
14 | | -This `BaseClientConfigBuilder` is later used in the class `ClientConfigBuilder` which only implements the build method, for now, and inherits all the abstract methods of the `BaseClientConfigBuilder`. |
| 13 | +```python |
| 14 | +# start with a blank slate (typical usage) |
| 15 | +builder = ClientConfigBuilder() |
| 16 | +``` |
| 17 | + |
| 18 | +### Configure |
| 19 | + |
| 20 | +Add client configuration with add, or flexibly mix and match builder configuration methods to add and remove configuration items. |
| 21 | + |
| 22 | +```python |
| 23 | +# add multiple items to the configuration using the catch-all `add` method |
| 24 | +builder.add( |
| 25 | + BuilderConfig( |
| 26 | + envs={}, |
| 27 | + interfaces={}, |
| 28 | + redirects={}, |
| 29 | + wrappers={}, |
| 30 | + packages={}, |
| 31 | + resolvers=[] |
| 32 | + ) |
| 33 | +) |
| 34 | + |
| 35 | +// add or remove items by chaining method calls |
| 36 | +builder |
| 37 | + .add_package("wrap://plugin/package", test_plugin({})) |
| 38 | + .remove_package("wrap://plugin/package") |
| 39 | + .add_packages( |
| 40 | + { |
| 41 | + "wrap://plugin/http": http_plugin({}), |
| 42 | + "wrap://plugin/filesystem": file_system_plugin({}), |
| 43 | + } |
| 44 | + ) |
| 45 | +``` |
| 46 | + |
| 47 | +### Build |
| 48 | + |
| 49 | +Finally, build a ClientConfig to pass to the PolywrapClient constructor. |
| 50 | + |
| 51 | +```python |
| 52 | +# accepted by the PolywrapClient |
| 53 | +config = builder.build() |
| 54 | + |
| 55 | +# build with a custom cache |
| 56 | +config = builder.build({ |
| 57 | + wrapperCache: WrapperCache(), |
| 58 | +}) |
| 59 | + |
| 60 | +# or build with a custom resolver |
| 61 | +coreClientConfig = builder.build({ |
| 62 | + resolver: RecursiveResolver(...), |
| 63 | +}) |
| 64 | +``` |
0 commit comments