Package: argsloader
argsloaderConfiguration Parsing and Management Based onchainloader.The argsloader library's main goal is to extract and change configuration data before implementing it using its computational mechanism:Reusability of local configuration modulesScalability and composition of configuration componentsConstructing complicated configuration data validation quicklyInstallationYou can simply install it withpipcommand line from the official PyPI site.pipinstallargsloaderFor more information about installation, you can refer toInstallation.Quick StartPainless TryA simple usage is like abovefromargsloader.unitsimportyesno,number,is_type,intervalif__name__=='__main__':yn=yesno()# yes-no optionprint(yn('yes'))# Trueprint(yn('no'))# Falseprint(yn(True))# Trueprint(yn(False))# Falsenum=number()# any numberprint(num(1))# 1print(num('1.2'))# 1.2print(num('0x4f'))# 79int_=number()>>is_type(int)# any int numberprint(num(1))# 1print(num('0x4f'))# 79print(num(1.2))# TypeErrorval_=number()>>interval.LR(0,10)# number within [0, 10]print(num(1))# 1print(num(1.2))# 1.2print(num(11))# ValueErrorAfter the unit is built, it can be used to transform and validate the given value.Full ValidationSometimes, there may be multiple errors in the given value, but if you directly call corresponding loader (i.e. call the pre-defined__call__method), only the first error will be raised.fromargsloader.unitsimportis_type,intervalif__name__=='__main__':in_=is_type(int)&interval.LR(0,10)# int within [0, 10]print(in_(1))# OKprint(in_(10))# OKprint(in_(11.2))# not an int, not in [0, 10] neitherThe output should be1
10
Traceback (most recent call last):
  File "test_main.py", line 7, in <module>
    print(in_(11.2))  # not an int, not in [0, 10] neither
  File "/home/hansbug/projects/argsloader/argsloader/units/base.py", line 237, in __call__
    return self.call(v, 'FIRST')
  File "/home/hansbug/projects/argsloader/argsloader/units/base.py", line 249, in call
    return self._process(PValue(v, ())).act(err_mode)
  File "/home/hansbug/projects/argsloader/argsloader/base/result.py", line 264, in act
    raise self._first_error()
  File "/home/hansbug/projects/argsloader/argsloader/units/build.py", line 80, in _easy_process
    pres = self._transform(v, pvalues)
  File "/home/hansbug/projects/argsloader/argsloader/units/build.py", line 105, in _transform
    v.value, nested_map(lambda x: x.value, pres)
  File "/home/hansbug/projects/argsloader/argsloader/units/type.py", line 43, in _calculate
    raise TypeError(f'Value type not match - {_tname(type_)} expected but {_tname(type(v))} found.')
TypeParseError: Value type not match - int expected but float found.To resolve this problem, you can use methodcallto show them all.fromargsloader.unitsimportis_type,intervalif__name__=='__main__':in_=is_type(int)&interval.LR(0,10)# int within [0, 10]print(in_.call(1))# OKprint(in_.call(10))# OKprint(in_.call(11.2))# not an int, not in [0, 10] neitherThe output should be1
10
Traceback (most recent call last):
  File "test_main.py", line 7, in <module>
    print(in_.call(11.2))
  File "/home/hansbug/projects/argsloader/argsloader/units/base.py", line 249, in call
    return self._process(PValue(v, ())).act(err_mode)
  File "/home/hansbug/projects/argsloader/argsloader/base/result.py", line 268, in act
    raise self._full_error()
argsloader.base.exception.MultipleParseError: (2 errors)
  <root>: TypeParseError: Value type not match - int expected but float found.
  <root>: ValueParseError: Value not in interval - [0, 10] expected but 11.2 found.For further examples and best practice, seeCheat Sheet of Units (still under developing)Example of C51 ConfigurationExample of Subprocess Env ManagerExample of One vs One ConfigurationContributingWe appreciate all contributions to improveargsloader, both logic and system designs. Please refer to CONTRIBUTING.md for more guides.Licenseargsloaderreleased under the Apache 2.0 license.