-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Tidy up after multiple changes
- Loading branch information
1 parent
c715730
commit 83b2c3d
Showing
3 changed files
with
188 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,73 @@ | ||
# Reference | ||
|
||
## ArgInit | ||
## ClassArgInit | ||
|
||
```python | ||
ArgInit(env_prefix="", priority=ARG_PRIORITY, use_kwargs=False, func_is_bound=False, set_attrs=True, args=None) | ||
ClassArgInit(env_prefix=None, priority=ENV_PRIORITY, use_kwargs=False, set_attrs=True, protect_atts=True, defaults=None) | ||
``` | ||
|
||
Initialise arguments using the function that calls ArgInit as the reference. Process each argument, setting the value of the class dictionary, args, with either the value provided by the argument, an associated environment variable or a default value. If the value of the arg or env is None then try the next item in the selected priority system | ||
Resolve argument values using the bound function that calls ClassArgInit as the reference. Process each argument (skipping the first argument as this is a class reference) from the calling function, resolving and storing the value in a dictionary, where the argument name is the key. | ||
|
||
### Arguments | ||
|
||
+ **env_prefix**: env_prefix is used to avoid namespace clashes with environment variables. If set, all environment variables must have include this prefix followed by an "_" character and the name of the argument. | ||
+ **env_prefix**: env_prefix is used to avoid namespace clashes with environment variables. If set, all environment variables must include this prefix followed by an "_" character and the name of the argument. | ||
|
||
+ **priority**: By default arguments will be set based on the prioty env, arg, default. An alternate priority of arg, env, default is available by setting priority=ARG_PRIORITY. | ||
+ **priority**: By default arguments will be set based on the priority env, arg, default. An alternate priority of arg, env, default is available by setting priority=ARG_PRIORITY. | ||
|
||
+ **use_kwargs**: When initialising arguments, only named arguments will be initialised by default. If use_kwargs=True, then any keyword arguments will also be initialised | ||
|
||
+ **is_class**: Set to True if the function being processed is a class method i.e. the first argument is "self" | ||
+ **set_attrs**: Set the arguments as class attributes. Default is true. | ||
|
||
+ **set_attrs**: If the function being processed is a class method (a bound function), set the arguments as class attributes. Default is true. Set to false to disable. This attribute has no effect if is_class=False. | ||
+ **protect_attrs**: Add a leading "_" character to all assigned attribute names. Default is True. | ||
|
||
+ **args**: A list of Arg objects that allow overriding the processing behaviour of individual arguments. | ||
+ **defaults**: A list of ArgDefault objects. | ||
|
||
### Attributes | ||
|
||
#### args | ||
|
||
An object representing the processed arguments. Arguments are exposed as attributes or key/value pairs. | ||
An object representing the resolved arguments. Arguments are exposed as attributes or key/value pairs. | ||
|
||
Note: The returned object is a [python-box](https://github.com/cdgriffith/Box) Box class. | ||
|
||
## Arg | ||
## FunctionArgInit | ||
|
||
```python | ||
Arg(name, env=None, default=None, attr=None, force_arg=False, force_env=True, disable_env=False) | ||
FunctionArgInit(env_prefix=None, priority=ENV_PRIORITY, use_kwargs=False, defaults=None) | ||
``` | ||
|
||
A dataclass that is used to customise the processing of arguments. | ||
Resolve argument values using the function that calls FunctionArgInit as the reference. Process each argument from the calling function, resolving and storing the value in a dictionary, where the argument name is the key. | ||
|
||
### Arguments | ||
|
||
+ **name**: (required) The name of the argument. | ||
+ **env_prefix**: env_prefix is used to avoid namespace clashes with environment variables. If set, all environment variables must include this prefix followed by an "_" character and the name of the argument. | ||
|
||
+ **env**: The name of the associated environment variable. If not set, env defaults to the uppercase equivalent of the argument name. | ||
+ **priority**: By default arguments will be set based on the priority env, arg, default. An alternate priority of arg, env, default is available by setting priority=ARG_PRIORITY. | ||
|
||
+ **default**: The default value to be applied if both arg and env values are not used. | ||
|
||
+ **attr**: The name of the argument in the args dictionary. Setting this value allows the argument to be referenced by a different name to that of the argument. If not set, defaults to the argument name | ||
|
||
+ **force_arg**: If True, set the value if the arg value is None | ||
+ **use_kwargs**: When initialising arguments, only named arguments will be initialised by default. If use_kwargs=True, then any keyword arguments will also be initialised | ||
|
||
+ **force_env**: If True, set the value if the env value is "" (an empty string) | ||
+ **defaults**: A list of ArgDefault objects. | ||
|
||
+ **disable_env**: If True then do not consider the env value when resolving the value. | ||
### Attributes | ||
|
||
### Methods | ||
#### args | ||
|
||
+ **resolve** | ||
An object representing the resolved arguments. Arguments are exposed as attributes or key/value pairs. | ||
|
||
Important: This method is only intended to be called by ArgInit. | ||
Note: The returned object is a [python-box](https://github.com/cdgriffith/Box) Box class. | ||
|
||
Resolve a value for the Arg using the specified priority system. | ||
### ArgDefaults | ||
|
||
```python | ||
resolve(self, priority=DEFAULT_PRIORITY_SYSTEM) | ||
ArgDefaults(name, default_value=None, env_name="", disable_env=False) | ||
``` | ||
|
||
## AttributeExistsError | ||
A class that can be used to modify settings for an individual argument. | ||
|
||
Raised if attempting to set an attribute of an object and an attribute with the same name already exists. | ||
### Arguments | ||
|
||
```python | ||
AttributeExistsError(Exception) | ||
``` | ||
+ **env_name**: The name of the associated environment variable. If not set, env defaults to the uppercase equivalent of the argument name. | ||
|
||
+ **default_value**: The default value to be applied if both arg and env values are not used. | ||
|
||
+ **disable_env**: If True then do not consider the env value when resolving the value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.