bitmapist 3.115__tar.gz → 3.117__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .*.swp
2
+ *.pyc
3
+ *.egg-info
4
+ /dist
5
+ .tox
6
+ dump.rdb
@@ -0,0 +1,26 @@
1
+ Copyright 2012 Doist Ltd.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification,
4
+ are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation and/or
11
+ other materials provided with the distribution.
12
+
13
+ 3. Neither the name of the copyright holder nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software without
15
+ specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
18
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,30 +1,28 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: bitmapist
3
- Version: 3.115
3
+ Version: 3.117
4
4
  Summary: Implements a powerful analytics library using Redis bitmaps.
5
- Home-page: https://github.com/Doist/bitmapist
6
- License: BSD
7
- Keywords: redis,bitmap,analytics,bitmaps,realtime,cohort
8
- Author: Amir Salihefendic
9
- Author-email: dev@doist.com
10
- Requires-Python: >=3.9,<3.13
5
+ Project-URL: Repository, https://github.com/Doist/bitmapist
6
+ Author-email: Amir Salihefendic <dev@doist.com>, Doist Developers <dev@doist.com>
7
+ License-Expression: BSD-3-Clause
8
+ License-File: AUTHORS
9
+ License-File: LICENSE
10
+ Keywords: analytics,bitmap,bitmaps,cohort,realtime,redis
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: BSD License
14
- Classifier: License :: Other/Proprietary License
15
13
  Classifier: Operating System :: OS Independent
16
14
  Classifier: Programming Language :: Python
17
- Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
18
16
  Classifier: Programming Language :: Python :: 3.9
19
17
  Classifier: Programming Language :: Python :: 3.10
20
18
  Classifier: Programming Language :: Python :: 3.11
21
19
  Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
22
21
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
- Requires-Dist: Mako (>=1.0.4,<2.0.0)
24
- Requires-Dist: future (>=0.14.3,<0.19.0)
22
+ Requires-Python: <3.14,>=3.9
23
+ Requires-Dist: mako<2,>=1.0.4
25
24
  Requires-Dist: python-dateutil
26
- Requires-Dist: redis (>=2.10,<6.0)
27
- Project-URL: Repository, https://github.com/Doist/bitmapist
25
+ Requires-Dist: redis<6.0,>=2.10
28
26
  Description-Content-Type: text/markdown
29
27
 
30
28
  ![bitmapist](https://raw.githubusercontent.com/Doist/bitmapist/master/static/bitmapist.png "bitmapist")
@@ -72,6 +70,10 @@ Can be installed very easily via:
72
70
 
73
71
  $ pip install bitmapist
74
72
 
73
+ Or, if you use `uv`:
74
+
75
+ $ uv add bitmapist
76
+
75
77
 
76
78
  # Ports
77
79
 
@@ -83,13 +85,13 @@ Can be installed very easily via:
83
85
  Setting things up:
84
86
 
85
87
  ```python
86
- from datetime import datetime, timedelta
88
+ from datetime import datetime, timedelta, timezone
87
89
  from bitmapist import setup_redis, delete_all_events, mark_event,\
88
90
  MonthEvents, WeekEvents, DayEvents, HourEvents,\
89
91
  BitOpAnd, BitOpOr
90
92
 
91
- now = datetime.utcnow()
92
- last_month = datetime.utcnow() - timedelta(days=30)
93
+ now = datetime.now(tz=timezone.utc)
94
+ last_month = now - timedelta(days=30)
93
95
  ```
94
96
 
95
97
  Mark user 123 as active and has played a song:
@@ -360,36 +362,49 @@ Please see our guide [here](./CONTRIBUTING.md)
360
362
 
361
363
  ## Local Development
362
364
 
363
- We use Poetry for dependency management & packaging. Please see [here for setup instructions](https://python-poetry.org/docs/#installation).
365
+ We use `uv` for dependency management & packaging. Please see [here for setup instructions](https://docs.astral.sh/uv/getting-started/).
364
366
 
365
- Once you have Poetry installed, you can run the following to install the dependencies in a virtual environment:
367
+ Once you have `uv` installed, you can run the following to install the dependencies in a virtual environment:
366
368
 
367
369
  ```bash
368
- poetry install
370
+ uv sync
369
371
  ```
370
372
 
371
373
  ## Testing
372
374
 
373
375
  To run our tests will need to ensure a local redis server is installed.
374
376
 
375
- We use pytest to run unittests which you can run in a poetry shell with
377
+ You can use these environment variables to tell the tests about Redis:
378
+
379
+ * `BITMAPIST_REDIS_SERVER_PATH`: Path to the Redis server executable (defaults to the first one in the path or `/usr/bin/redis-server`)
380
+ * `BITMAPIST_REDIS_PORT`: Port number for the Redis server (defaults to 6399)
381
+
382
+ We use `pytest` to run unit tests, which you can run with:
376
383
 
377
384
  ```bash
378
- poetry run pytest
385
+ uv run pytest
379
386
  ```
380
387
 
381
388
  ## Releasing new versions
382
389
 
383
- - Bump version in `pyproject.toml`
384
- - Update the CHANGELOG
385
- - Commit the changes with a commit message "Version X.X.X"
386
- - Tag the current commit with `vX.X.X`
387
- - Create a new release on GitHub named `vX.X.X`
388
- - GitHub Actions will publish the new version to PIP for you
390
+ 1. Bump version in `pyproject.toml` (or use `uv version`)
391
+ ```sh
392
+ uv version --bump minor
393
+ ```
394
+ 1. Update the CHANGELOG
395
+ 1. Commit the changes with a commit message "Version X.X.X"
396
+ ```sh
397
+ git commit -m "Version $(uv version --short)"
398
+ ```
399
+ 1. Tag the current commit with `vX.X.X`
400
+ ```sh
401
+ git tag -a -m "Release $(uv version --short)" "v$(uv version --short)"
402
+ ```
403
+ 1. Create a new release on GitHub named `vX.X.X`
404
+ 1. GitHub Actions will publish the new version to PyPI for you
389
405
 
390
406
  ## Legal
391
407
 
392
408
  Copyright: 2012 by Doist Ltd.
393
409
 
394
- License: BSD
395
-
410
+ License: BSD-3-Clause
@@ -43,6 +43,10 @@ Can be installed very easily via:
43
43
 
44
44
  $ pip install bitmapist
45
45
 
46
+ Or, if you use `uv`:
47
+
48
+ $ uv add bitmapist
49
+
46
50
 
47
51
  # Ports
48
52
 
@@ -54,13 +58,13 @@ Can be installed very easily via:
54
58
  Setting things up:
55
59
 
56
60
  ```python
57
- from datetime import datetime, timedelta
61
+ from datetime import datetime, timedelta, timezone
58
62
  from bitmapist import setup_redis, delete_all_events, mark_event,\
59
63
  MonthEvents, WeekEvents, DayEvents, HourEvents,\
60
64
  BitOpAnd, BitOpOr
61
65
 
62
- now = datetime.utcnow()
63
- last_month = datetime.utcnow() - timedelta(days=30)
66
+ now = datetime.now(tz=timezone.utc)
67
+ last_month = now - timedelta(days=30)
64
68
  ```
65
69
 
66
70
  Mark user 123 as active and has played a song:
@@ -331,35 +335,49 @@ Please see our guide [here](./CONTRIBUTING.md)
331
335
 
332
336
  ## Local Development
333
337
 
334
- We use Poetry for dependency management & packaging. Please see [here for setup instructions](https://python-poetry.org/docs/#installation).
338
+ We use `uv` for dependency management & packaging. Please see [here for setup instructions](https://docs.astral.sh/uv/getting-started/).
335
339
 
336
- Once you have Poetry installed, you can run the following to install the dependencies in a virtual environment:
340
+ Once you have `uv` installed, you can run the following to install the dependencies in a virtual environment:
337
341
 
338
342
  ```bash
339
- poetry install
343
+ uv sync
340
344
  ```
341
345
 
342
346
  ## Testing
343
347
 
344
348
  To run our tests will need to ensure a local redis server is installed.
345
349
 
346
- We use pytest to run unittests which you can run in a poetry shell with
350
+ You can use these environment variables to tell the tests about Redis:
351
+
352
+ * `BITMAPIST_REDIS_SERVER_PATH`: Path to the Redis server executable (defaults to the first one in the path or `/usr/bin/redis-server`)
353
+ * `BITMAPIST_REDIS_PORT`: Port number for the Redis server (defaults to 6399)
354
+
355
+ We use `pytest` to run unit tests, which you can run with:
347
356
 
348
357
  ```bash
349
- poetry run pytest
358
+ uv run pytest
350
359
  ```
351
360
 
352
361
  ## Releasing new versions
353
362
 
354
- - Bump version in `pyproject.toml`
355
- - Update the CHANGELOG
356
- - Commit the changes with a commit message "Version X.X.X"
357
- - Tag the current commit with `vX.X.X`
358
- - Create a new release on GitHub named `vX.X.X`
359
- - GitHub Actions will publish the new version to PIP for you
363
+ 1. Bump version in `pyproject.toml` (or use `uv version`)
364
+ ```sh
365
+ uv version --bump minor
366
+ ```
367
+ 1. Update the CHANGELOG
368
+ 1. Commit the changes with a commit message "Version X.X.X"
369
+ ```sh
370
+ git commit -m "Version $(uv version --short)"
371
+ ```
372
+ 1. Tag the current commit with `vX.X.X`
373
+ ```sh
374
+ git tag -a -m "Release $(uv version --short)" "v$(uv version --short)"
375
+ ```
376
+ 1. Create a new release on GitHub named `vX.X.X`
377
+ 1. GitHub Actions will publish the new version to PyPI for you
360
378
 
361
379
  ## Legal
362
380
 
363
381
  Copyright: 2012 by Doist Ltd.
364
382
 
365
- License: BSD
383
+ License: BSD-3-Clause
@@ -33,8 +33,8 @@ Setting things up::
33
33
  from datetime import datetime, timedelta
34
34
  from bitmapist import mark_event, MonthEvents
35
35
 
36
- now = datetime.utcnow()
37
- last_month = datetime.utcnow() - timedelta(days=30)
36
+ now = datetime.now(tz=timezone.utc)
37
+ last_month = now - timedelta(days=30)
38
38
 
39
39
  Mark user 123 as active::
40
40
 
@@ -76,15 +76,16 @@ Additionally you can supply an extra argument to mark_event to bypass the defaul
76
76
 
77
77
  :copyright: 2012 by Doist Ltd.
78
78
  :developer: Amir Salihefendic ( http://amix.dk )
79
- :license: BSD
79
+ :license: BSD-3-Clause
80
80
  """
81
81
 
82
82
  from __future__ import annotations
83
83
 
84
+ import abc
84
85
  import calendar
85
86
  import threading
86
87
  from collections import defaultdict
87
- from datetime import date, datetime, timedelta
88
+ from datetime import date, datetime, timedelta, timezone
88
89
  from typing import TYPE_CHECKING, Any, Optional, Union
89
90
 
90
91
  import redis
@@ -159,7 +160,7 @@ def mark_event(
159
160
  :param :system The Redis system to use (string, Redis instance, or Pipeline
160
161
  instance).
161
162
  :param :now Which date should be used as a reference point, default is
162
- `datetime.utcnow()`
163
+ `datetime.now(tz=timezone.utc)`
163
164
  :param :track_hourly Should hourly stats be tracked, defaults to
164
165
  bitmapist.TRACK_HOURLY
165
166
  :param :track_unique Should unique stats be tracked, defaults to
@@ -200,7 +201,7 @@ def _mark(
200
201
  event_name,
201
202
  uuid: int,
202
203
  system="default",
203
- now=None,
204
+ now: Optional[datetime] = None,
204
205
  track_hourly=None,
205
206
  track_unique=None,
206
207
  use_pipeline: bool = True,
@@ -210,9 +211,8 @@ def _mark(
210
211
  track_hourly = TRACK_HOURLY
211
212
  if track_unique is None:
212
213
  track_unique = TRACK_UNIQUE
213
-
214
- if not now:
215
- now = datetime.utcnow()
214
+ if now is None:
215
+ now = datetime.now(tz=timezone.utc)
216
216
 
217
217
  obj_classes: list[
218
218
  type[MonthEvents]
@@ -293,7 +293,7 @@ def get_event_names(
293
293
  `prefix` value is used to filter only subset of keys
294
294
  """
295
295
  cli = get_redis(system)
296
- expr = "trackist_%s*" % prefix
296
+ expr = f"trackist_{prefix}*"
297
297
  ret = set()
298
298
  for result in cli.scan_iter(match=expr, count=batch):
299
299
  result = result.decode()
@@ -401,6 +401,9 @@ class MixinEventsMisc:
401
401
  return NotImplemented
402
402
  return self.redis_key == other_key
403
403
 
404
+ def __hash__(self):
405
+ return hash(self.redis_key)
406
+
404
407
 
405
408
  class MixinCounts:
406
409
  """
@@ -428,9 +431,7 @@ class MixinContains:
428
431
 
429
432
  def __contains__(self, uuid):
430
433
  cli = get_redis(self.system)
431
- if cli.getbit(self.redis_key, uuid):
432
- return True
433
- return False
434
+ return bool(cli.getbit(self.redis_key, uuid))
434
435
 
435
436
 
436
437
  class UniqueEvents(
@@ -453,8 +454,34 @@ class UniqueEvents(
453
454
 
454
455
 
455
456
  class GenericPeriodEvents(
456
- MixinIter, MixinCounts, MixinContains, MixinEventsMisc, MixinBitOperations
457
+ MixinIter, MixinCounts, MixinContains, MixinEventsMisc, MixinBitOperations, abc.ABC
457
458
  ):
459
+ """
460
+ This is an abstract base class - subclasses must call super().__init__()
461
+ and implement their specific initialization logic. They all must set the
462
+ redis_key attribute in __init__.
463
+ """
464
+
465
+ def __init__(self, event_name: str, *, system: str = "default"):
466
+ self.event_name = event_name
467
+ self.system = system
468
+ # redis_key will be set by subclasses
469
+
470
+ @abc.abstractmethod
471
+ def delta(self, value: int):
472
+ """Return a new instance with the period offset by value."""
473
+ ...
474
+
475
+ @abc.abstractmethod
476
+ def period_start(self) -> datetime:
477
+ """Return the start datetime of this period."""
478
+ ...
479
+
480
+ @abc.abstractmethod
481
+ def period_end(self) -> datetime:
482
+ """Return the end datetime of this period."""
483
+ ...
484
+
458
485
  def next(self):
459
486
  """Next object in a datetime line"""
460
487
  return self.delta(value=1)
@@ -474,12 +501,14 @@ class YearEvents(GenericPeriodEvents):
474
501
  """
475
502
 
476
503
  @classmethod
477
- def from_date(cls, event_name, dt=None, system="default"):
478
- dt = dt or datetime.utcnow()
504
+ def from_date(
505
+ cls, event_name, dt: Optional[date | datetime] = None, system="default"
506
+ ):
507
+ dt = dt or datetime.now(tz=timezone.utc)
479
508
  return cls(event_name, dt.year, system=system)
480
509
 
481
510
  def __init__(self, event_name, year=None, system="default"):
482
- now = datetime.utcnow()
511
+ now = datetime.now(tz=timezone.utc)
483
512
  self.event_name = event_name
484
513
  self.year = not_none(year, now.year)
485
514
  self.system = system
@@ -492,10 +521,10 @@ class YearEvents(GenericPeriodEvents):
492
521
  return self.__class__(self.event_name, self.year + value, self.system)
493
522
 
494
523
  def period_start(self):
495
- return datetime(self.year, 1, 1)
524
+ return datetime(self.year, 1, 1, tzinfo=timezone.utc)
496
525
 
497
526
  def period_end(self):
498
- return datetime(self.year, 12, 31, 23, 59, 59, 999999)
527
+ return datetime(self.year, 12, 31, 23, 59, 59, 999999, tzinfo=timezone.utc)
499
528
 
500
529
 
501
530
  class MonthEvents(GenericPeriodEvents):
@@ -508,16 +537,17 @@ class MonthEvents(GenericPeriodEvents):
508
537
  """
509
538
 
510
539
  @classmethod
511
- def from_date(cls, event_name, dt=None, system="default"):
512
- dt = dt or datetime.utcnow()
540
+ def from_date(
541
+ cls, event_name, dt: Optional[date | datetime] = None, system="default"
542
+ ):
543
+ dt = dt or datetime.now(tz=timezone.utc)
513
544
  return cls(event_name, dt.year, dt.month, system=system)
514
545
 
515
546
  def __init__(self, event_name, year=None, month=None, system="default"):
516
- now = datetime.utcnow()
517
- self.event_name = event_name
547
+ super().__init__(event_name, system=system)
548
+ now = datetime.now(tz=timezone.utc)
518
549
  self.year = not_none(year, now.year)
519
550
  self.month = not_none(month, now.month)
520
- self.system = system
521
551
  self.redis_key = _prefix_key(event_name, f"{self.year}-{self.month}")
522
552
 
523
553
  def delta(self, value):
@@ -525,11 +555,13 @@ class MonthEvents(GenericPeriodEvents):
525
555
  return self.__class__(self.event_name, year, month, self.system)
526
556
 
527
557
  def period_start(self):
528
- return datetime(self.year, self.month, 1)
558
+ return datetime(self.year, self.month, 1, tzinfo=timezone.utc)
529
559
 
530
560
  def period_end(self):
531
561
  _, day = calendar.monthrange(self.year, self.month)
532
- return datetime(self.year, self.month, day, 23, 59, 59, 999999)
562
+ return datetime(
563
+ self.year, self.month, day, 23, 59, 59, 999999, tzinfo=timezone.utc
564
+ )
533
565
 
534
566
 
535
567
  class WeekEvents(GenericPeriodEvents):
@@ -543,19 +575,21 @@ class WeekEvents(GenericPeriodEvents):
543
575
 
544
576
  @classmethod
545
577
  def from_date(
546
- cls, event_name: str, dt: Optional[date] = None, system: str = "default"
578
+ cls,
579
+ event_name: str,
580
+ dt: Optional[date | datetime] = None,
581
+ system: str = "default",
547
582
  ):
548
- dt = dt or datetime.utcnow()
583
+ dt = dt or datetime.now(tz=timezone.utc)
549
584
  dt_year, dt_week, _ = dt.isocalendar()
550
585
  return cls(event_name, dt_year, dt_week, system=system)
551
586
 
552
587
  def __init__(self, event_name: str, year=None, week=None, system="default"):
553
- now = datetime.utcnow()
588
+ super().__init__(event_name, system=system)
589
+ now = datetime.now(tz=timezone.utc)
554
590
  now_year, now_week, _ = now.isocalendar()
555
- self.event_name = event_name
556
591
  self.year = not_none(year, now_year)
557
592
  self.week = not_none(week, now_week)
558
- self.system = system
559
593
  self.redis_key = _prefix_key(event_name, f"W{self.year}-{self.week}")
560
594
 
561
595
  def delta(self, value):
@@ -565,11 +599,11 @@ class WeekEvents(GenericPeriodEvents):
565
599
 
566
600
  def period_start(self):
567
601
  s = iso_to_gregorian(self.year, self.week, 1) # mon
568
- return datetime(s.year, s.month, s.day)
602
+ return datetime(s.year, s.month, s.day, tzinfo=timezone.utc)
569
603
 
570
604
  def period_end(self):
571
605
  e = iso_to_gregorian(self.year, self.week, 7) # mon
572
- return datetime(e.year, e.month, e.day, 23, 59, 59, 999999)
606
+ return datetime(e.year, e.month, e.day, 23, 59, 59, 999999, tzinfo=timezone.utc)
573
607
 
574
608
 
575
609
  class DayEvents(GenericPeriodEvents):
@@ -582,17 +616,18 @@ class DayEvents(GenericPeriodEvents):
582
616
  """
583
617
 
584
618
  @classmethod
585
- def from_date(cls, event_name: str, dt: Optional[date] = None, system="default"):
586
- dt = dt or datetime.utcnow()
619
+ def from_date(
620
+ cls, event_name: str, dt: Optional[date | datetime] = None, system="default"
621
+ ):
622
+ dt = dt or datetime.now(tz=timezone.utc)
587
623
  return cls(event_name, dt.year, dt.month, dt.day, system=system)
588
624
 
589
625
  def __init__(self, event_name, year=None, month=None, day=None, system="default"):
590
- now = datetime.utcnow()
591
- self.event_name = event_name
626
+ super().__init__(event_name, system=system)
627
+ now = datetime.now(tz=timezone.utc)
592
628
  self.year = not_none(year, now.year)
593
629
  self.month = not_none(month, now.month)
594
630
  self.day = not_none(day, now.day)
595
- self.system = system
596
631
  self.redis_key = _prefix_key(event_name, f"{self.year}-{self.month}-{self.day}")
597
632
 
598
633
  def delta(self, value):
@@ -600,10 +635,12 @@ class DayEvents(GenericPeriodEvents):
600
635
  return self.__class__(self.event_name, dt.year, dt.month, dt.day, self.system)
601
636
 
602
637
  def period_start(self) -> datetime:
603
- return datetime(self.year, self.month, self.day)
638
+ return datetime(self.year, self.month, self.day, tzinfo=timezone.utc)
604
639
 
605
640
  def period_end(self) -> datetime:
606
- return datetime(self.year, self.month, self.day, 23, 59, 59, 999999)
641
+ return datetime(
642
+ self.year, self.month, self.day, 23, 59, 59, 999999, tzinfo=timezone.utc
643
+ )
607
644
 
608
645
 
609
646
  class HourEvents(GenericPeriodEvents):
@@ -619,7 +656,7 @@ class HourEvents(GenericPeriodEvents):
619
656
  def from_date(
620
657
  cls, event_name: str, dt: Optional[datetime] = None, system="default"
621
658
  ):
622
- dt = dt or datetime.utcnow()
659
+ dt = dt or datetime.now(tz=timezone.utc)
623
660
  return cls(event_name, dt.year, dt.month, dt.day, dt.hour, system=system)
624
661
 
625
662
  def __init__(
@@ -631,30 +668,38 @@ class HourEvents(GenericPeriodEvents):
631
668
  hour: Optional[int] = None,
632
669
  system: str = "default",
633
670
  ):
634
- now = datetime.utcnow()
635
- self.event_name = event_name
671
+ super().__init__(event_name, system=system)
672
+ now = datetime.now(tz=timezone.utc)
636
673
  self.year = not_none(year, now.year)
637
674
  self.month = not_none(month, now.month)
638
675
  self.day = not_none(day, now.day)
639
676
  self.hour = not_none(hour, now.hour)
640
- self.system = system
641
677
  self.redis_key = _prefix_key(
642
678
  event_name, f"{self.year}-{self.month}-{self.day}-{self.hour}"
643
679
  )
644
680
 
645
681
  def delta(self, value):
646
- dt = datetime(self.year, self.month, self.day, self.hour) + timedelta(
647
- hours=value
648
- )
682
+ dt = datetime(
683
+ self.year, self.month, self.day, self.hour, tzinfo=timezone.utc
684
+ ) + timedelta(hours=value)
649
685
  return self.__class__(
650
686
  self.event_name, dt.year, dt.month, dt.day, dt.hour, self.system
651
687
  )
652
688
 
653
689
  def period_start(self) -> datetime:
654
- return datetime(self.year, self.month, self.day, self.hour)
690
+ return datetime(self.year, self.month, self.day, self.hour, tzinfo=timezone.utc)
655
691
 
656
692
  def period_end(self) -> datetime:
657
- return datetime(self.year, self.month, self.day, self.hour, 59, 59, 999999)
693
+ return datetime(
694
+ self.year,
695
+ self.month,
696
+ self.day,
697
+ self.hour,
698
+ 59,
699
+ 59,
700
+ 999999,
701
+ tzinfo=timezone.utc,
702
+ )
658
703
 
659
704
 
660
705
  # --- Bit operations
@@ -59,10 +59,10 @@ Get the data and render it via HTML::
59
59
 
60
60
  :copyright: 2012 by Doist Ltd.
61
61
  :developer: Amir Salihefendic ( http://amix.dk )
62
- :license: BSD
62
+ :license: BSD-3-Clause
63
63
  """
64
64
 
65
- from datetime import date, datetime, timedelta
65
+ from datetime import date, datetime, timedelta, timezone
66
66
  from os import path
67
67
  from typing import Any, Callable, Literal, Optional, Union
68
68
 
@@ -228,10 +228,10 @@ def get_dates_data(
228
228
  num_of_rows = int(num_of_rows)
229
229
 
230
230
  if start_date:
231
- now = datetime.strptime(start_date, "%Y-%m-%d")
231
+ now = datetime.strptime(start_date, "%Y-%m-%d").replace(tzinfo=timezone.utc)
232
232
  now = now + timedelta(days=num_results - 1)
233
233
  else:
234
- now = datetime.utcnow()
234
+ now = datetime.now(tz=timezone.utc)
235
235
 
236
236
  # Days
237
237
  if time_group == "days":
@@ -415,4 +415,4 @@ def get_lookup() -> TemplateLookup:
415
415
  return _LOOKUP
416
416
 
417
417
 
418
- __all__ = ["render_html_form", "render_html_data", "get_dates_data"]
418
+ __all__ = ["get_dates_data", "render_html_data", "render_html_form"]
@@ -1,55 +1,77 @@
1
- [tool.poetry]
1
+ [project]
2
2
  name = "bitmapist"
3
- version = "3.115"
4
- description="Implements a powerful analytics library using Redis bitmaps."
3
+ version = "3.117"
4
+ description = "Implements a powerful analytics library using Redis bitmaps."
5
5
  authors = [
6
- "Amir Salihefendic <dev@doist.com>",
7
- "Doist Developers <dev@doist.com>",
6
+ { name = "Amir Salihefendic", email = "dev@doist.com" },
7
+ { name = "Doist Developers", email = "dev@doist.com" },
8
8
  ]
9
- license="BSD"
9
+ requires-python = ">=3.9,<3.14"
10
10
  readme = "README.md"
11
- repository = "https://github.com/Doist/bitmapist"
12
- keywords=[ "redis", "bitmap", "analytics", "bitmaps", "realtime", "cohort", ]
13
- classifiers=[
11
+ license = "BSD-3-Clause"
12
+ keywords = [
13
+ "redis",
14
+ "bitmap",
15
+ "analytics",
16
+ "bitmaps",
17
+ "realtime",
18
+ "cohort",
19
+ ]
20
+ classifiers = [
14
21
  "Development Status :: 5 - Production/Stable",
15
22
  "Intended Audience :: Developers",
16
- "License :: OSI Approved :: BSD License",
17
23
  "Operating System :: OS Independent",
18
24
  "Programming Language :: Python",
19
- "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3 :: Only",
20
26
  "Programming Language :: Python :: 3.9",
21
27
  "Programming Language :: Python :: 3.10",
22
28
  "Programming Language :: Python :: 3.11",
23
29
  "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
24
31
  "Topic :: Software Development :: Libraries :: Python Modules",
25
32
  ]
26
- packages=[ { include = "bitmapist" } ]
27
- exclude = ['tests/']
33
+ dependencies = [
34
+ "redis>=2.10,<6.0",
35
+ "python-dateutil",
36
+ "Mako>=1.0.4,<2",
37
+ ]
38
+
39
+ [project.urls]
40
+ Repository = "https://github.com/Doist/bitmapist"
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "pytest-runner",
45
+ "pytest",
46
+ "pre-commit",
47
+ "tox",
48
+ "mypy",
49
+ "ruff>=0.12.0",
50
+ ]
51
+
52
+ [tool.hatch.build.targets.sdist]
28
53
  include = [
29
- 'AUTHORS',
30
- 'README.md',
31
- 'static/bitmapist.png',
32
- 'static/bitmapist.svg',
54
+ "bitmapist",
55
+ "AUTHORS",
56
+ "README.md",
57
+ "static/bitmapist.png",
58
+ "static/bitmapist.svg",
33
59
  ]
60
+ exclude = ["tests/"]
34
61
 
35
- [tool.poetry.dependencies]
36
- python = ">=3.9,<3.13"
37
- redis = ">=2.10,<6.0"
38
- python-dateutil = "*"
39
- future = ">=0.14.3,<0.19.0"
40
- Mako= "^1.0.4"
41
-
42
- [tool.poetry.dev-dependencies]
43
- pytest-runner = "*"
44
- pytest = "*"
45
- pre-commit = "*"
46
- tox = "*"
47
- mypy = "*"
48
- ruff = "^0.4.1"
62
+ [tool.hatch.build.targets.wheel]
63
+ include = [
64
+ "bitmapist",
65
+ "AUTHORS",
66
+ "README.md",
67
+ "static/bitmapist.png",
68
+ "static/bitmapist.svg",
69
+ ]
70
+ exclude = ["tests/"]
49
71
 
50
72
  [build-system]
51
- requires = ["poetry-core>=1.0.0"]
52
- build-backend = "poetry.core.masonry.api"
73
+ requires = ["hatchling"]
74
+ build-backend = "hatchling.build"
53
75
 
54
76
  [tool.ruff]
55
77
  # By default, always show source code snippets.
@@ -140,11 +162,9 @@ ignore = [
140
162
  "RUF002", # ambiguous-unicode-character-docstring
141
163
  "RUF003", # ambiguous-unicode-character-comment
142
164
  "RUF012", # mutable-class-default
165
+ "RUF200", # invalid-pyproject-toml
143
166
 
144
- # Enable when Poetry supports PEP 621 and we migrate our confguration to it.
145
- # See: https://github.com/python-poetry/poetry-core/pull/567
146
- "RUF200",
147
-
167
+ ## S - flake8-bandit ##
148
168
  "S101", # assert
149
169
  "S104", # hardcoded-bind-all-interfaces
150
170
  "S105", # hardcoded-password-string
@@ -161,9 +181,6 @@ ignore = [
161
181
  "SIM102", # collapsible-if
162
182
  "SIM114", # if-with-same-arms
163
183
  "SIM117", # multiple-with-statements
164
-
165
- # Enable when the rule is out of preview and false-positives are handled.
166
- # See: https://docs.astral.sh/ruff/rules/in-dict-keys/
167
184
  "SIM118", # in-dict-keys
168
185
 
169
186
  ## TRY - tryceratops ##
@@ -178,12 +195,8 @@ ignore = [
178
195
  "RET504", # unnecessary-assign
179
196
 
180
197
  ## PT - flake8-pytest-style ##
181
- "PT004", # pytest-missing-fixture-name-underscore
182
198
  "PT012", # pytest-raises-with-multiple-statements
183
199
 
184
- ## UP - pyupgrade ##
185
- "UP038", # non-pep604-isinstance
186
-
187
200
  ## B - flake8-bugbear ##
188
201
  "B008", # function-call-in-default-argument
189
202
  "B009", # get-attr-with-constant
@@ -233,3 +246,7 @@ keep-runtime-typing = true
233
246
 
234
247
  [tool.ruff.format]
235
248
  docstring-code-format = true
249
+
250
+ [[tool.mypy.overrides]]
251
+ module = ["mako.*"]
252
+ ignore_missing_imports = true
File without changes
File without changes