Accepting request 989020 from home:bnavigator:branches:devel:languages:python
required by pip-run which is used by setuptools 63 test suite OBS-URL: https://build.opensuse.org/request/show/989020 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-autocommand?expand=0&rev=1
This commit is contained in:
commit
145ca1bde9
23
.gitattributes
vendored
Normal file
23
.gitattributes
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
## Default LFS
|
||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bsp filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gem filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.jar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lzma filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.obscpio filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.oxt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rpm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tbz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tbz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ttf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.txz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.whl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.osc
|
3
autocommand-2.2.1.tar.gz
Normal file
3
autocommand-2.2.1.tar.gz
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:fed420e9d02745821a782971b583c6970259ee0b229be2a0a401e1467a4f170f
|
||||||
|
size 23151
|
285
autocommand-fixtests.patch
Normal file
285
autocommand-fixtests.patch
Normal file
@ -0,0 +1,285 @@
|
|||||||
|
From 031c9750c74e3313b954b09e3027aaa6595649bb Mon Sep 17 00:00:00 2001
|
||||||
|
From: Nathan West <Lucretiel@gmail.com>
|
||||||
|
Date: Thu, 18 Nov 2021 14:06:30 -0500
|
||||||
|
Subject: [PATCH] Fix out of date patterns in autocommand
|
||||||
|
|
||||||
|
- Use async def instead of asyncio.coroutine
|
||||||
|
- Use create_task instead of asyncio.async
|
||||||
|
- Use pytest.fixture instead of pytest.yield_fixture
|
||||||
|
---
|
||||||
|
src/autocommand/autoasync.py | 6 +--
|
||||||
|
test/test_autoasync.py | 95 ++++++++++++++++--------------------
|
||||||
|
test/test_autocommand.py | 6 +--
|
||||||
|
3 files changed, 49 insertions(+), 58 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/autocommand/autoasync.py b/src/autocommand/autoasync.py
|
||||||
|
index 3c8ebdc..2e6e28a 100644
|
||||||
|
--- a/src/autocommand/autoasync.py
|
||||||
|
+++ b/src/autocommand/autoasync.py
|
||||||
|
@@ -20,7 +20,7 @@
|
||||||
|
from inspect import signature
|
||||||
|
|
||||||
|
|
||||||
|
-def _launch_forever_coro(coro, args, kwargs, loop):
|
||||||
|
+async def _run_forever_coro(coro, args, kwargs, loop):
|
||||||
|
'''
|
||||||
|
This helper function launches an async main function that was tagged with
|
||||||
|
forever=True. There are two possibilities:
|
||||||
|
@@ -48,7 +48,7 @@ def _launch_forever_coro(coro, args, kwargs, loop):
|
||||||
|
# forever=True feature from autoasync at some point in the future.
|
||||||
|
thing = coro(*args, **kwargs)
|
||||||
|
if iscoroutine(thing):
|
||||||
|
- loop.create_task(thing)
|
||||||
|
+ await thing
|
||||||
|
|
||||||
|
|
||||||
|
def autoasync(coro=None, *, loop=None, forever=False, pass_loop=False):
|
||||||
|
@@ -127,7 +127,7 @@ def autoasync_wrapper(*args, **kwargs):
|
||||||
|
args, kwargs = bound_args.args, bound_args.kwargs
|
||||||
|
|
||||||
|
if forever:
|
||||||
|
- _launch_forever_coro(coro, args, kwargs, local_loop)
|
||||||
|
+ local_loop.create_task(_run_forever_coro(coro, args, kwargs, local_loop))
|
||||||
|
local_loop.run_forever()
|
||||||
|
else:
|
||||||
|
return local_loop.run_until_complete(coro(*args, **kwargs))
|
||||||
|
diff --git a/test/test_autoasync.py b/test/test_autoasync.py
|
||||||
|
index 6ffb782..dfeb019 100644
|
||||||
|
--- a/test/test_autoasync.py
|
||||||
|
+++ b/test/test_autoasync.py
|
||||||
|
@@ -20,6 +20,10 @@
|
||||||
|
asyncio = pytest.importorskip('asyncio')
|
||||||
|
autoasync = pytest.importorskip('autocommand.autoasync').autoasync
|
||||||
|
|
||||||
|
+class YieldOnce:
|
||||||
|
+ def __await__(self):
|
||||||
|
+ yield
|
||||||
|
+
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def temporary_context_loop(loop):
|
||||||
|
@@ -35,7 +39,7 @@ def temporary_context_loop(loop):
|
||||||
|
asyncio.set_event_loop(old_loop)
|
||||||
|
|
||||||
|
|
||||||
|
-@pytest.yield_fixture
|
||||||
|
+@pytest.fixture
|
||||||
|
def new_loop():
|
||||||
|
'''
|
||||||
|
Get a new event loop. The loop is closed afterwards
|
||||||
|
@@ -44,7 +48,7 @@ def new_loop():
|
||||||
|
yield loop
|
||||||
|
|
||||||
|
|
||||||
|
-@pytest.yield_fixture
|
||||||
|
+@pytest.fixture
|
||||||
|
def context_loop():
|
||||||
|
'''
|
||||||
|
Create a new event loop and set it as the current context event loop.
|
||||||
|
@@ -63,29 +67,27 @@ def context_loop():
|
||||||
|
def test_basic_autoasync(context_loop):
|
||||||
|
data = set()
|
||||||
|
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def coro_1():
|
||||||
|
+ async def coro_1():
|
||||||
|
data.add(1)
|
||||||
|
- yield
|
||||||
|
+ await YieldOnce()
|
||||||
|
data.add(2)
|
||||||
|
|
||||||
|
return 1
|
||||||
|
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def coro_2():
|
||||||
|
+ async def coro_2():
|
||||||
|
data.add(3)
|
||||||
|
- yield
|
||||||
|
+ await YieldOnce()
|
||||||
|
data.add(4)
|
||||||
|
|
||||||
|
return 2
|
||||||
|
|
||||||
|
@autoasync
|
||||||
|
- def async_main():
|
||||||
|
- task1 = asyncio.async(coro_1())
|
||||||
|
- task2 = asyncio.async(coro_2())
|
||||||
|
+ async def async_main():
|
||||||
|
+ task1 = asyncio.create_task(coro_1())
|
||||||
|
+ task2 = asyncio.create_task(coro_2())
|
||||||
|
|
||||||
|
- result1 = yield from task1
|
||||||
|
- result2 = yield from task2
|
||||||
|
+ result1 = await task1
|
||||||
|
+ result2 = await task2
|
||||||
|
|
||||||
|
assert result1 == 1
|
||||||
|
assert result2 == 2
|
||||||
|
@@ -99,19 +101,19 @@ def async_main():
|
||||||
|
def test_custom_loop(context_loop, new_loop):
|
||||||
|
did_bad_coro_run = False
|
||||||
|
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def bad_coro():
|
||||||
|
+ async def bad_coro():
|
||||||
|
nonlocal did_bad_coro_run
|
||||||
|
did_bad_coro_run = True
|
||||||
|
- yield
|
||||||
|
+ await YieldOnce()
|
||||||
|
|
||||||
|
- asyncio.async(bad_coro())
|
||||||
|
+ # TODO: this fires a "task wasn't awaited" warning; figure out how to
|
||||||
|
+ # supress
|
||||||
|
+ context_loop.create_task(bad_coro())
|
||||||
|
|
||||||
|
@autoasync(loop=new_loop)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main():
|
||||||
|
- yield
|
||||||
|
- yield
|
||||||
|
+ async def async_main():
|
||||||
|
+ await YieldOnce()
|
||||||
|
+ await YieldOnce()
|
||||||
|
return 3
|
||||||
|
|
||||||
|
assert async_main() == 3
|
||||||
|
@@ -120,9 +122,7 @@ def async_main():
|
||||||
|
|
||||||
|
def test_pass_loop(context_loop):
|
||||||
|
@autoasync(pass_loop=True)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main(loop):
|
||||||
|
- yield
|
||||||
|
+ async def async_main(loop):
|
||||||
|
return loop
|
||||||
|
|
||||||
|
assert async_main() is asyncio.get_event_loop()
|
||||||
|
@@ -134,9 +134,7 @@ def test_pass_loop_prior_argument(context_loop):
|
||||||
|
still passed correctly
|
||||||
|
'''
|
||||||
|
@autoasync(pass_loop=True)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main(loop, argument):
|
||||||
|
- yield
|
||||||
|
+ async def async_main(loop, argument):
|
||||||
|
return loop, argument
|
||||||
|
|
||||||
|
loop, value = async_main(10)
|
||||||
|
@@ -146,9 +144,8 @@ def async_main(loop, argument):
|
||||||
|
|
||||||
|
def test_pass_loop_kwarg_only(context_loop):
|
||||||
|
@autoasync(pass_loop=True)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main(*, loop, argument):
|
||||||
|
- yield
|
||||||
|
+ async def async_main(*, loop, argument):
|
||||||
|
+ await YieldOnce()
|
||||||
|
return loop, argument
|
||||||
|
|
||||||
|
loop, value = async_main(argument=10)
|
||||||
|
@@ -157,48 +154,43 @@ def async_main(*, loop, argument):
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_forever(context_loop):
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def stop_loop_after(t):
|
||||||
|
- yield from asyncio.sleep(t)
|
||||||
|
+ async def stop_loop_after(t):
|
||||||
|
+ await asyncio.sleep(t)
|
||||||
|
context_loop.stop()
|
||||||
|
|
||||||
|
retrieved_value = False
|
||||||
|
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def set_value_after(t):
|
||||||
|
+ async def set_value_after(t):
|
||||||
|
nonlocal retrieved_value
|
||||||
|
- yield from asyncio.sleep(t)
|
||||||
|
+ await asyncio.sleep(t)
|
||||||
|
retrieved_value = True
|
||||||
|
|
||||||
|
@autoasync(forever=True)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main():
|
||||||
|
- asyncio.async(set_value_after(0.1))
|
||||||
|
- asyncio.async(stop_loop_after(0.2))
|
||||||
|
- yield
|
||||||
|
+ async def async_main():
|
||||||
|
+ asyncio.create_task(set_value_after(0.1))
|
||||||
|
+ asyncio.create_task(stop_loop_after(0.2))
|
||||||
|
+ await YieldOnce()
|
||||||
|
|
||||||
|
async_main()
|
||||||
|
assert retrieved_value
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_forever_func(context_loop):
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def stop_loop_after(t):
|
||||||
|
- yield from asyncio.sleep(t)
|
||||||
|
+ async def stop_loop_after(t):
|
||||||
|
+ await asyncio.sleep(t)
|
||||||
|
context_loop.stop()
|
||||||
|
|
||||||
|
retrieved_value = False
|
||||||
|
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def set_value_after(t):
|
||||||
|
+ async def set_value_after(t):
|
||||||
|
nonlocal retrieved_value
|
||||||
|
- yield from asyncio.sleep(t)
|
||||||
|
+ await asyncio.sleep(t)
|
||||||
|
retrieved_value = True
|
||||||
|
|
||||||
|
@autoasync(forever=True)
|
||||||
|
def main_func():
|
||||||
|
- asyncio.async(set_value_after(0.1))
|
||||||
|
- asyncio.async(stop_loop_after(0.2))
|
||||||
|
+ asyncio.create_task(set_value_after(0.1))
|
||||||
|
+ asyncio.create_task(stop_loop_after(0.2))
|
||||||
|
|
||||||
|
main_func()
|
||||||
|
assert retrieved_value
|
||||||
|
@@ -212,9 +204,8 @@ def test_defered_loop(context_loop, new_loop):
|
||||||
|
called.
|
||||||
|
'''
|
||||||
|
@autoasync(pass_loop=True)
|
||||||
|
- @asyncio.coroutine
|
||||||
|
- def async_main(loop):
|
||||||
|
- yield
|
||||||
|
+ async def async_main(loop):
|
||||||
|
+ await YieldOnce()
|
||||||
|
return loop
|
||||||
|
|
||||||
|
with temporary_context_loop(new_loop):
|
||||||
|
diff --git a/test/test_autocommand.py b/test/test_autocommand.py
|
||||||
|
index 6531146..791e1cc 100644
|
||||||
|
--- a/test/test_autocommand.py
|
||||||
|
+++ b/test/test_autocommand.py
|
||||||
|
@@ -41,7 +41,7 @@ def _asyncio_unavailable():
|
||||||
|
reason="async tests require asyncio (python3.4+)")
|
||||||
|
|
||||||
|
|
||||||
|
-@pytest.yield_fixture
|
||||||
|
+@pytest.fixture
|
||||||
|
def patched_autoparse():
|
||||||
|
with patch.object(
|
||||||
|
autocommand_module,
|
||||||
|
@@ -50,7 +50,7 @@ def patched_autoparse():
|
||||||
|
yield autoparse
|
||||||
|
|
||||||
|
|
||||||
|
-@pytest.yield_fixture
|
||||||
|
+@pytest.fixture
|
||||||
|
def patched_autoasync():
|
||||||
|
with patch.object(
|
||||||
|
autocommand_module,
|
||||||
|
@@ -62,7 +62,7 @@ def patched_autoasync():
|
||||||
|
yield autoasync
|
||||||
|
|
||||||
|
|
||||||
|
-@pytest.yield_fixture
|
||||||
|
+@pytest.fixture
|
||||||
|
def patched_automain():
|
||||||
|
with patch.object(
|
||||||
|
autocommand_module,
|
7
python-autocommand.changes
Normal file
7
python-autocommand.changes
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Wed Jul 13 14:36:43 UTC 2022 - Ben Greiner <code@bnavigator.de>
|
||||||
|
|
||||||
|
- initial specfile for v2.2.1
|
||||||
|
- Add autocommand-fixtests.patch gh#Lucretiel/autocommand#20
|
||||||
|
- Required by pip-run
|
||||||
|
|
60
python-autocommand.spec
Normal file
60
python-autocommand.spec
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#
|
||||||
|
# spec file for package python-autocommand
|
||||||
|
#
|
||||||
|
# Copyright (c) 2022 SUSE LLC
|
||||||
|
#
|
||||||
|
# All modifications and additions to the file contributed by third parties
|
||||||
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
|
# upon. The license for this file, and modifications and additions to the
|
||||||
|
# file, is the same license as for the pristine package itself (unless the
|
||||||
|
# license for the pristine package is not an Open Source License, in which
|
||||||
|
# case the license is the MIT License). An "Open Source License" is a
|
||||||
|
# license that conforms to the Open Source Definition (Version 1.9)
|
||||||
|
# published by the Open Source Initiative.
|
||||||
|
|
||||||
|
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
|
||||||
|
Name: python-autocommand
|
||||||
|
Version: 2.2.1
|
||||||
|
Release: 0
|
||||||
|
Summary: A library to create a command-line program from a function
|
||||||
|
License: LGPL-3.0
|
||||||
|
URL: https://github.com/Lucretiel/autocommand
|
||||||
|
Source: https://files.pythonhosted.org/packages/source/a/autocommand/autocommand-%{version}.tar.gz
|
||||||
|
# PATCH-FIX-UPSTREAM autocommand-fixtests.patch gh#Lucretiel/autocommand#20
|
||||||
|
Patch1: https://github.com/Lucretiel/autocommand/commit/031c9750c74e3313b954b09e3027aaa6595649bb.patch#/autocommand-fixtests.patch
|
||||||
|
BuildRequires: python-rpm-macros
|
||||||
|
BuildRequires: %{python_module setuptools}
|
||||||
|
BuildRequires: %{python_module pytest}
|
||||||
|
BuildRequires: fdupes
|
||||||
|
BuildArch: noarch
|
||||||
|
%python_subpackages
|
||||||
|
|
||||||
|
%description
|
||||||
|
Autocommand turns a function into a command-line program. It converts the function's parameter
|
||||||
|
signature into command-line arguments, and automatically runs the function if the module was
|
||||||
|
called as __main__. In effect, it lets your create a smart main function.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%autosetup -p1 -n autocommand-%{version}
|
||||||
|
|
||||||
|
%build
|
||||||
|
%python_build
|
||||||
|
|
||||||
|
%install
|
||||||
|
%python_install
|
||||||
|
%python_expand %fdupes %{buildroot}%{$python_sitelib}
|
||||||
|
|
||||||
|
%check
|
||||||
|
%pytest
|
||||||
|
|
||||||
|
%files %{python_files}
|
||||||
|
%doc README.rst
|
||||||
|
%license LICENSE
|
||||||
|
%{python_sitelib}/autocommand
|
||||||
|
%{python_sitelib}/autocommand-%{version}*-info
|
||||||
|
|
||||||
|
%changelog
|
Loading…
x
Reference in New Issue
Block a user