ahvn.utils.basic package¶
Basic utilities for AgentHeaven.
This subpackage groups helpers for logging, colors, paths, files, configs, serialization, hashing, templating, and small conveniences used across the project.
- ahvn.utils.basic.lazy_getattr(name, export_map, package)[源代码]¶
Helper function to implement __getattr__ for lazy loading modules.
- 参数:
- 返回:
The requested attribute from the imported module.
- 抛出:
AttributeError -- If the name is not in the export_map.
- ahvn.utils.basic.collect_exports(package_names, parent_package)[源代码]¶
Collects exported names from a list of subpackages to build a master lazy map.
- ahvn.utils.basic.deepcopy(x, memo=None, _nil=[])[源代码]¶
Deep copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
- ahvn.utils.basic.dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)[源代码]¶
Add dunder methods based on the fields defined in the class.
Examines PEP 526 __annotations__ to determine fields.
If init is true, an __init__() method is added to the class. If repr is true, a __repr__() method is added. If order is true, rich comparison dunder methods are added. If unsafe_hash is true, a __hash__() method is added. If frozen is true, fields may not be assigned to after instance creation. If match_args is true, the __match_args__ tuple is added. If kw_only is true, then by default all fields are keyword-only. If slots is true, a new class with a __slots__ attribute is returned.
- ahvn.utils.basic.field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING)[源代码]¶
Return an object to identify dataclass fields.
default is the default value of the field. default_factory is a 0-argument function called to initialize a field's value. If init is true, the field will be a parameter to the class's __init__() function. If repr is true, the field will be included in the object's repr(). If hash is true, the field will be included in the object's hash(). If compare is true, the field will be used in comparison functions. metadata, if specified, must be a mapping which is stored but not otherwise examined by dataclass. If kw_only is true, the field will become a keyword-only parameter to __init__().
It is an error to specify both default and default_factory.
- class ahvn.utils.basic.ABC[源代码]¶
基类:
objectHelper class that provides a standard way to create an ABC using inheritance.
- ahvn.utils.basic.abstractmethod(funcobj)[源代码]¶
A decorator indicating abstract methods.
Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal 'super' call mechanisms. abstractmethod() may be used to declare abstract methods for properties and descriptors.
Usage:
- class C(metaclass=ABCMeta):
@abstractmethod def my_abstract_method(self, arg1, arg2, argN):
...
- class ahvn.utils.basic.defaultdict¶
基类:
dictdefaultdict(default_factory=None, /, [...]) --> dict with default factory
The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments.
- __init__(*args, **kwargs)¶
- copy() a shallow copy of D.¶
- default_factory¶
Factory for default value called by __missing__().
- class ahvn.utils.basic.Any(*args, **kwargs)[源代码]¶
基类:
objectSpecial type indicating an unconstrained type.
Any is compatible with every type.
Any assumed to have all methods.
All values assumed to be instances of Any.
Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance checks.
Submodules¶
- ahvn.utils.basic.cmd_utils module
- ahvn.utils.basic.color_utils module
color_black()color_red()color_green()color_yellow()color_blue()color_magenta()color_cyan()color_white()color_grey()no_color()color_debug()color_info()color_info1()color_info2()color_info3()color_warning()color_error()color_success()print_debug()print_info()print_warning()print_error()print_success()
- ahvn.utils.basic.config_utils module
dmerge()dget()dset()dunset()dsetdef()dflat()dunflat()ConfigManagerConfigManager.__init__()ConfigManager.nameConfigManager.packageConfigManager.set_cwd()ConfigManager.local_dirConfigManager.local_config_pathConfigManager.global_config_pathConfigManager.system_config_pathConfigManager.config_path()ConfigManager.resource()ConfigManager.configConfigManager.system_configConfigManager.global_configConfigManager.local_configConfigManager.load()ConfigManager.save()ConfigManager.init()ConfigManager.setup()ConfigManager.get()ConfigManager.set()ConfigManager.unset()
hpj()encrypt_config()
- ahvn.utils.basic.debug_utils module
- ahvn.utils.basic.deps_utils module
- ahvn.utils.basic.file_utils module
- ahvn.utils.basic.func_utils module
- ahvn.utils.basic.hash_utils module
- ahvn.utils.basic.jinja_utils module
- ahvn.utils.basic.log_utils module
- ahvn.utils.basic.misc_utils module
- ahvn.utils.basic.parallel_utils module
- ahvn.utils.basic.parser_utils module
- ahvn.utils.basic.path_utils module
- ahvn.utils.basic.progress_utils module
- ahvn.utils.basic.request_utils module
- ahvn.utils.basic.rnd_utils module
- ahvn.utils.basic.serialize_utils module
load_txt()iter_txt()save_txt()append_txt()loads_yaml()dumps_yaml()load_yaml()dump_yaml()save_yaml()load_pkl()dump_pkl()save_pkl()load_hex()dump_hex()save_hex()load_b64()dump_b64()save_b64()serialize_path()deserialize_path()serialize_func()deserialize_func()AhvnJsonEncoderAhvnJsonDecoderloads_json()dumps_json()load_json()dump_json()save_json()escape_json()loads_jsonl()dumps_jsonl()load_jsonl()iter_jsonl()dump_jsonl()save_jsonl()append_jsonl()
- ahvn.utils.basic.str_utils module
- ahvn.utils.basic.type_utils module