%global _empty_manifest_terminate_build 0 Name: python-biwrap Version: 0.1.6 Release: 1 Summary: Yet simple util to make wrapper with optional arguments License: MIT License URL: https://github.com/ferrine/biwrap Source0: https://mirrors.nju.edu.cn/pypi/web/packages/ac/54/78d4d5459d7385f90908185641647ff2e8ed4a4b5c239976f78e26888679/biwrap-0.1.6.tar.gz BuildArch: noarch %description The above example shows redundancy in - decorator definition has double nesting (double ``def``) - usage requires trailing parenthesis ``@register()`` even in case we do not use optional argument More readable code should avoid these two points and look like: def register(fn, alias=None): @register def f1(a): return a @register(alias='fn3') # <- (1) def f2(a): return a Naive implementation of the above API won't work. Line marked above as ``(1)`` will fail as first argument ``fn`` is not passed. But we want the output to be the same. Better solution *************** import biwrap @biwrap.biwrap def register(fn, alias=None): if fn.__name__ not in register.storage: register.storage[fn.__name__] = fn elif register.storage[fn.__name__] is not fn: raise KeyError('{} is already in storage'.format(fn.__name__)) if alias is not None and alias not in register.storage: register.storage[alias] = fn elif alias is not None: raise KeyError('{} is already in storage'.format(alias)) return fn register.storage = {} @register def f1(a): return a print(register.storage) #> {'f1': } @register(alias='fn3') def f2(a): return a print(register.storage) #> {'f1': , 'f2': , 'fn3': } Functionality Overview ###################### Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread `__). This package takes the best and implements yet simple but generic solution to resolve them all(?). Setup ***** Let's take a simple wrapper as an example. It will print ``hi`` or ``bye`` depending on parametrization, default is ``hi``. import biwrap @biwrap.biwrap def hiwrap(fn, hi=True): def new(*args, **kwargs): if hi: print('hi') else: print('bye') return fn(*args, **kwargs) return new Cases ***** %package -n python3-biwrap Summary: Yet simple util to make wrapper with optional arguments Provides: python-biwrap BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-biwrap The above example shows redundancy in - decorator definition has double nesting (double ``def``) - usage requires trailing parenthesis ``@register()`` even in case we do not use optional argument More readable code should avoid these two points and look like: def register(fn, alias=None): @register def f1(a): return a @register(alias='fn3') # <- (1) def f2(a): return a Naive implementation of the above API won't work. Line marked above as ``(1)`` will fail as first argument ``fn`` is not passed. But we want the output to be the same. Better solution *************** import biwrap @biwrap.biwrap def register(fn, alias=None): if fn.__name__ not in register.storage: register.storage[fn.__name__] = fn elif register.storage[fn.__name__] is not fn: raise KeyError('{} is already in storage'.format(fn.__name__)) if alias is not None and alias not in register.storage: register.storage[alias] = fn elif alias is not None: raise KeyError('{} is already in storage'.format(alias)) return fn register.storage = {} @register def f1(a): return a print(register.storage) #> {'f1': } @register(alias='fn3') def f2(a): return a print(register.storage) #> {'f1': , 'f2': , 'fn3': } Functionality Overview ###################### Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread `__). This package takes the best and implements yet simple but generic solution to resolve them all(?). Setup ***** Let's take a simple wrapper as an example. It will print ``hi`` or ``bye`` depending on parametrization, default is ``hi``. import biwrap @biwrap.biwrap def hiwrap(fn, hi=True): def new(*args, **kwargs): if hi: print('hi') else: print('bye') return fn(*args, **kwargs) return new Cases ***** %package help Summary: Development documents and examples for biwrap Provides: python3-biwrap-doc %description help The above example shows redundancy in - decorator definition has double nesting (double ``def``) - usage requires trailing parenthesis ``@register()`` even in case we do not use optional argument More readable code should avoid these two points and look like: def register(fn, alias=None): @register def f1(a): return a @register(alias='fn3') # <- (1) def f2(a): return a Naive implementation of the above API won't work. Line marked above as ``(1)`` will fail as first argument ``fn`` is not passed. But we want the output to be the same. Better solution *************** import biwrap @biwrap.biwrap def register(fn, alias=None): if fn.__name__ not in register.storage: register.storage[fn.__name__] = fn elif register.storage[fn.__name__] is not fn: raise KeyError('{} is already in storage'.format(fn.__name__)) if alias is not None and alias not in register.storage: register.storage[alias] = fn elif alias is not None: raise KeyError('{} is already in storage'.format(alias)) return fn register.storage = {} @register def f1(a): return a print(register.storage) #> {'f1': } @register(alias='fn3') def f2(a): return a print(register.storage) #> {'f1': , 'f2': , 'fn3': } Functionality Overview ###################### Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread `__). This package takes the best and implements yet simple but generic solution to resolve them all(?). Setup ***** Let's take a simple wrapper as an example. It will print ``hi`` or ``bye`` depending on parametrization, default is ``hi``. import biwrap @biwrap.biwrap def hiwrap(fn, hi=True): def new(*args, **kwargs): if hi: print('hi') else: print('bye') return fn(*args, **kwargs) return new Cases ***** %prep %autosetup -n biwrap-0.1.6 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-biwrap -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Mon May 15 2023 Python_Bot - 0.1.6-1 - Package Spec generated