diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 4fbff3d..04bef3c 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: [3.7, 3.8, 3.9, "3.10"] + python: [3.7, 3.8, 3.9, "3.10", "3.11"] steps: - uses: actions/checkout@v3 diff --git a/README.rst b/README.rst index 489a6b6..4adc5a6 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,7 @@ aiocron - Crontabs for asyncio ================================================ -.. image:: https://travis-ci.org/gawel/aiocron.svg?branch=master - :target: https://travis-ci.org/gawel/aiocron + .. image:: https://img.shields.io/pypi/v/aiocron.svg :target: https://pypi.python.org/pypi/aiocron .. image:: https://img.shields.io/pypi/dm/aiocron.svg diff --git a/aiocron/__init__.py b/aiocron/__init__.py index aba475f..9d9663c 100644 --- a/aiocron/__init__.py +++ b/aiocron/__init__.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- from croniter.croniter import croniter from datetime import datetime +from functools import wraps, partial from tzlocal import get_localzone from uuid import uuid4 import time -import functools import asyncio import sys import inspect @@ -16,7 +16,7 @@ async def null_callback(*args): def wrap_func(func): """wrap in a coroutine""" - @functools.wraps(func) + @wraps(func) async def wrapper(*args, **kwargs): result = func(*args, **kwargs) if inspect.isawaitable(result): @@ -28,11 +28,12 @@ async def wrapper(*args, **kwargs): class Cron(object): - def __init__(self, spec, func=None, args=(), start=False, uuid=None, - loop=None, tz=None, croniter_kwargs=None): + def __init__(self, spec, func=None, args=(), kwargs=None, start=False, + uuid=None, loop=None, tz=None, croniter_kwargs=None): self.spec = spec if func is not None: - self.func = func if not args else functools.partial(func, *args) + kwargs = kwargs or {} + self.func = func if not (args or kwargs) else partial(func, *args, **kwargs) else: self.func = null_callback self.tz = get_localzone() if tz is None else tz @@ -110,7 +111,7 @@ def set_result(self, result): if isinstance(result, Exception): self.future.set_exception(result) elif not self.future.done(): - self.future.set_result(result) + self.future.set_result(result) self.future = None elif isinstance(result, Exception): raise result @@ -130,5 +131,5 @@ def __repr__(self): return ''.format(self) -def crontab(spec, func=None, args=(), start=True, loop=None, tz=None): - return Cron(spec, func=func, args=args, start=start, loop=loop, tz=tz) +def crontab(spec, func=None, args=(), kwargs=None, start=True, loop=None, tz=None): + return Cron(spec, func=func, args=args, kwargs=kwargs, start=start, loop=loop, tz=tz) diff --git a/setup.py b/setup.py index cd0e672..161ed52 100644 --- a/setup.py +++ b/setup.py @@ -24,10 +24,12 @@ def read(name): 'Environment :: Web Environment', 'Intended Audience :: Developers', 'Operating System :: POSIX', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', 'License :: OSI Approved :: MIT License', 'Topic :: Software Development :: Libraries :: Python Modules', ], diff --git a/tox.ini b/tox.ini index a73b3f8..ba186a3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py37,py38,py39,py310 +envlist = py{37,38,39,310,311} [testenv] commands =