summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-05-15 06:45:41 +0000
committerCoprDistGit <infra@openeuler.org>2023-05-15 06:45:41 +0000
commitad40cf14e419a65a8706ef2a696a028b1aa5ec22 (patch)
tree64c71b2841a11d8eb7ebcf7bc5eaad07848c5166
parent896a85f6380cc322a13b96e5b88a4a55fbc33ace (diff)
automatic import of python-biwrap
-rw-r--r--.gitignore1
-rw-r--r--python-biwrap.spec234
-rw-r--r--sources1
3 files changed, 236 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..d1f1917 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/biwrap-0.1.6.tar.gz
diff --git a/python-biwrap.spec b/python-biwrap.spec
new file mode 100644
index 0000000..db7a6b5
--- /dev/null
+++ b/python-biwrap.spec
@@ -0,0 +1,234 @@
+%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': <function f1 at 0x10f45a048>}
+ @register(alias='fn3')
+ def f2(a):
+ return a
+ print(register.storage)
+ #> {'f1': <function f1 at 0x10f45a048>, 'f2': <function f2 at 0x10f45a488>, 'fn3': <function f2 at 0x10f45a488>}
+Functionality Overview
+######################
+Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread <https://stackoverflow.com/questions/3888158/making-decorators-with-optional-arguments>`__). 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': <function f1 at 0x10f45a048>}
+ @register(alias='fn3')
+ def f2(a):
+ return a
+ print(register.storage)
+ #> {'f1': <function f1 at 0x10f45a048>, 'f2': <function f2 at 0x10f45a488>, 'fn3': <function f2 at 0x10f45a488>}
+Functionality Overview
+######################
+Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread <https://stackoverflow.com/questions/3888158/making-decorators-with-optional-arguments>`__). 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': <function f1 at 0x10f45a048>}
+ @register(alias='fn3')
+ def f2(a):
+ return a
+ print(register.storage)
+ #> {'f1': <function f1 at 0x10f45a048>, 'f2': <function f2 at 0x10f45a488>, 'fn3': <function f2 at 0x10f45a488>}
+Functionality Overview
+######################
+Some corner cases may exist and custom coding can create a boilerplate for each usecase (see this `SO thread <https://stackoverflow.com/questions/3888158/making-decorators-with-optional-arguments>`__). 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 <Python_Bot@openeuler.org> - 0.1.6-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..ccb532f
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+10b52d62edcdb656e72ae1bfb67cb821 biwrap-0.1.6.tar.gz