Skip to content

Commit f6d210b

Browse files
authored
Merge pull request #5 from dapper91/dev
Dev
2 parents 1458d63 + f127736 commit f6d210b

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
13-
- name: Set up Python ${{ matrix.python-version }}
13+
- name: Set up Python
1414
uses: actions/setup-python@v2
1515
with:
1616
python-version: '3.x'

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
0.1.3 (2021-03-18)
5+
------------------
6+
7+
- performance fixes
8+
49
0.1.2 (2021-03-16)
510
------------------
611

crontools/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__ = 'Python cron tools'
33
__url__ = 'https://github.com/dapper91/crontools'
44

5-
__version__ = '0.1.2'
5+
__version__ = '0.1.3'
66

77
__author__ = 'Dmitry Pershin'
88
__email__ = '[email protected]'

crontools/crontab.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import dataclasses as dc
33
import datetime as dt
44
import heapq
5-
import itertools as it
65
import operator as op
76
import tzlocal
87
from typing import Any, ClassVar, Dict, Generic, Iterator, Iterable, Optional, Type, TypeVar, Tuple
98

9+
SENTINEL = object()
10+
1011

1112
def unique(iterable: Iterable[Any]) -> Iterator[Any]:
1213
"""
@@ -18,7 +19,7 @@ def unique(iterable: Iterable[Any]) -> Iterator[Any]:
1819

1920
it = iter(iterable)
2021

21-
prev = None
22+
prev = SENTINEL
2223
for val in it:
2324
if val == prev:
2425
continue
@@ -296,7 +297,7 @@ def __init__(self, monthday_field: Field[MonthdayRange], weekday_field: Field[W
296297
def __iter__(self) -> Iterator[int]:
297298
return self.iter()
298299

299-
def iter(self, year: Optional[int] = None, month: Optional[int] = None, start_from: Optional[int] = None) -> Iterator[int]:
300+
def iter(self, year: Optional[int] = None, month: Optional[int] = None, start_from: int = 1) -> Iterator[int]:
300301
"""
301302
Returns iterator over month days and week days values of a particular month and year starting from `start_from`.
302303
@@ -311,21 +312,18 @@ def iter(self, year: Optional[int] = None, month: Optional[int] = None, start_fr
311312
month = now.month if month is None else month
312313

313314
if self._weekday_field.is_default:
314-
day_iter = self._monthday_iter(year, month)
315+
day_iter = self._monthday_iter(year, month, start_from)
315316
elif self._monthday_field.is_default:
316-
day_iter = self._weekday_iter(year, month)
317+
day_iter = self._weekday_iter(year, month, start_from)
317318
else:
318-
day_iter = heapq.merge(self._monthday_iter(year, month), self._weekday_iter(year, month))
319-
320-
if start_from is not None:
321-
day_iter = it.dropwhile(lambda value: value < start_from, day_iter)
319+
day_iter = heapq.merge(self._monthday_iter(year, month, start_from), self._weekday_iter(year, month, start_from))
322320

323321
return unique(day_iter)
324322

325-
def _monthday_iter(self, year: int, month: int) -> Iterator[int]:
326-
for day in self._monthday_field:
323+
def _monthday_iter(self, year: int, month: int, start_from: int = 1) -> Iterator[int]:
324+
for day in self._monthday_field.iter(start_from=start_from):
327325
if day > calendar.monthrange(year, month)[1]:
328-
continue
326+
break
329327

330328
yield day
331329

@@ -334,7 +332,8 @@ def _weekday_iter(self, year: int, month: int, start_day: int = 1) -> Iterator[i
334332
curr_weekday = calendar.weekday(year, month, curr_day) + 1
335333
weekday_iter = self._weekday_field.iter(start_from=curr_weekday)
336334

337-
for _ in range(6):
335+
max_weeks_in_month = 6
336+
for _ in range(max_weeks_in_month):
338337
for weekday in weekday_iter:
339338
curr_day += (weekday - curr_weekday)
340339
curr_weekday += (weekday - curr_weekday)

0 commit comments

Comments
 (0)