From b735d6090f21fadcd65f03a0062c0e538d49552f Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 11:07:46 +0100 Subject: [PATCH 01/22] mise venv for local development --- .gitignore | 1 + .mise.toml | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 .mise.toml diff --git a/.gitignore b/.gitignore index 0211f3ae..ccadd9ee 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build .idea/ .python-version venv +.venv diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 00000000..bb4904ac --- /dev/null +++ b/.mise.toml @@ -0,0 +1,13 @@ +[env] +MISE_FETCH_REMOTE_VERSIONS_TIMEOUT = "30s" + +_.python.venv = { + path = ".venv", + create = true, +} + +[tools] +python = "3.9" + +[tasks.test] +run = 'make install test' From aa04d43928b0c83015698c0aeb1754abb0749dc0 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 11:08:10 +0100 Subject: [PATCH 02/22] Test with more recent Python 3.x versions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da2daf6d..8b5ea537 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14] steps: - uses: actions/checkout@v2 From 7edc1598e697dd5915aefe2e010ffadbd53a11a7 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 11:30:29 +0100 Subject: [PATCH 03/22] Sync setup and test matrix Python versions --- .github/workflows/test.yml | 2 +- setup.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b5ea537..4fb84ccc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14] + python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14] steps: - uses: actions/checkout@v2 diff --git a/setup.py b/setup.py index 143a9ab5..7f7048b7 100644 --- a/setup.py +++ b/setup.py @@ -56,5 +56,10 @@ "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", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", ], ) From 01bff49f1a2a99d0a3e99c66b6c8dafdbc565de9 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 13:36:44 +0100 Subject: [PATCH 04/22] Update GHA; quote Python versions in test matrix --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 6 +++--- requirements.txt | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 871263d5..1f28c5c0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,9 +18,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v6 with: python-version: '3.x' cache: 'pip' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4fb84ccc..a3245a29 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,12 +8,12 @@ jobs: strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14] + python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} cache: 'pip' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..c9aa3cc8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +backoff==2.2.1 +monotonic==1.6 +mock==2.0.0 +pylint==3.3.3 +python-dateutil==2.8.2 +requests>=2.32.2 \ No newline at end of file From e866debadea78f1d3b2be943d2dc0335c7379abd Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 13:42:10 +0100 Subject: [PATCH 05/22] Python 3.6 is not supported by newer setup-python action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3245a29..2081dc18 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] + python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] steps: - uses: actions/checkout@v6 From e068f47b9500bb9f6d28a4ee60184d1b0d244faa Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 13:46:18 +0100 Subject: [PATCH 06/22] Downgrade setup-python, re-enable Python 3.6, and run whole test matrix on failure --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2081dc18..de3b1bff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,13 +7,14 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] + python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] steps: - uses: actions/checkout@v6 - - uses: actions/setup-python@v6 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' From 880bd73164e8276c705e071ae999cd53b8723009 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 13:54:08 +0100 Subject: [PATCH 07/22] Split linting out from tests --- .github/workflows/lint.yml | 19 +++++++++++++++++++ .mise.toml | 3 +++ Makefile | 6 ++++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..565e7cb2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: Test + +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v5 + with: + python-version: "3.10" + cache: 'pip' + cache-dependency-path: setup.py + + - run: pip3 install -e '.[test]' + - run: make lint diff --git a/.mise.toml b/.mise.toml index bb4904ac..4522c872 100644 --- a/.mise.toml +++ b/.mise.toml @@ -11,3 +11,6 @@ python = "3.9" [tasks.test] run = 'make install test' + +[tasks.lint] +run = 'make install lint' diff --git a/Makefile b/Makefile index 8ea2abef..885bed58 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,10 @@ install: pip install --edit .[test] test: + python -m unittest customerio/analytics/test/*.py -v + +lint: pylint --rcfile=.pylintrc --reports=y --exit-zero customerio/analytics flake8 --max-complexity=10 --statistics customerio/analytics || true - python -m unittest customerio/analytics/test/*.py -v -.PHONY: install test +.PHONY: install test lint From d7873feab11f426bfa2d86c192f2aa0c546fd487 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 13:59:49 +0100 Subject: [PATCH 08/22] Remove Python 3.6, 3.7 from test matrix --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index de3b1bff..adb4a249 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,12 +9,12 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14" ] steps: - uses: actions/checkout@v6 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} cache: 'pip' From c747ab137e6029bdf5aa61453795fc389bd49fbf Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 14:00:32 +0100 Subject: [PATCH 09/22] Bump setup-python in lint too --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 565e7cb2..e06f1cba 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v6 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v6 with: python-version: "3.10" cache: 'pip' From c65edf8c49aa17ceddb56b4deeb950f127865874 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 14:02:08 +0100 Subject: [PATCH 10/22] Typo --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e06f1cba..ab54ed3c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Test +name: Lint on: [push] From 5a8da0c53c29c80d1f4c41d445bcffb1c46123b6 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Wed, 17 Jun 2026 14:03:01 +0100 Subject: [PATCH 11/22] Another typo --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ab54ed3c..be41a45e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,7 +3,7 @@ name: Lint on: [push] jobs: - test: + lint: runs-on: ubuntu-latest steps: From c6b8a3fdb0363663d69f216251af48de21d691f4 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Mon, 22 Jun 2026 14:07:08 +0100 Subject: [PATCH 12/22] Remove support for Python 3.6, 3.7 --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 7f7048b7..0c6e4e60 100644 --- a/setup.py +++ b/setup.py @@ -52,8 +52,6 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", From 1688eba0e47d18a64cb2d98cfd7e187297de8fa7 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Mon, 22 Jun 2026 14:07:24 +0100 Subject: [PATCH 13/22] Latest doc URLs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b21aa40c..7c2f61b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Customer.io Data Pipelines analytics client for Python. +# Customer.io Data Pipelines analytics client for Python. ## Installation @@ -40,6 +40,6 @@ analytics.track(user_id=4, event='order_complete') The links below contain more detailed documentation on how to use this library: -* [Documentation](https://customer.io/docs/cdp/sources/connections/servers/python/) -* [Specs](https://customer.io/docs/cdp/sources/source-spec/source-events/) +* [Documentation](https://docs.customer.io/integrations/data-in/connections/servers/python/) +* [Specs](https://docs.customer.io/integrations/data-in/source-spec/incoming-data/) * [PyPi](https://pypi.org/project/customerio-cdp-analytics/) From 1fc2506c305dc0a354b97860f7167fa7029c5083 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Mon, 22 Jun 2026 14:08:37 +0100 Subject: [PATCH 14/22] Bump version to 0.1.0 --- customerio/analytics/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/customerio/analytics/version.py b/customerio/analytics/version.py index bc784a3b..1f6518e6 100644 --- a/customerio/analytics/version.py +++ b/customerio/analytics/version.py @@ -1 +1 @@ -VERSION = '0.0.2' +VERSION = '0.1.0' From 9f4d9918746e190ad3f9e5db727cd0cd3f414dfc Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Mon, 22 Jun 2026 14:18:11 +0100 Subject: [PATCH 15/22] Synchronise setup.py and requirements.txt --- requirements.txt | 1 + setup.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index c9aa3cc8..0867b28b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ backoff==2.2.1 +flake8==3.7.9 monotonic==1.6 mock==2.0.0 pylint==3.3.3 diff --git a/setup.py b/setup.py index 0c6e4e60..1988acb4 100644 --- a/setup.py +++ b/setup.py @@ -16,15 +16,15 @@ ''' install_requires = [ - "requests~=2.7", - "monotonic~=1.5", - "backoff~=2.1", - "python-dateutil~=2.2" + "requests>=2.32.2", + "monotonic~=1.6", + "backoff~=2.2", + "python-dateutil~=2.8" ] tests_require = [ "mock==2.0.0", - "pylint==2.8.0", + "pylint==3.3.3", "flake8==3.7.9", ] @@ -38,6 +38,7 @@ maintainer_email='cdp@customer.io', test_suite='analytics.test.all', packages=['customerio.analytics'], + # Newer versions are not tested with Python 3.6 or 3.7. python_requires='>=3.6.0', license='MIT License', install_requires=install_requires, From 22b9a98aacd9d11a2d606a9eb0c17a3e7d3b671c Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Mon, 22 Jun 2026 14:20:45 +0100 Subject: [PATCH 16/22] Relax pylint --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1988acb4..d1802d24 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ tests_require = [ "mock==2.0.0", - "pylint==3.3.3", + "pylint>=3.2.0", "flake8==3.7.9", ] From c761e3134f49b398bd17f5fd17506e250f25363c Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 10:09:38 +0100 Subject: [PATCH 17/22] Bump version to 1.0.0; drop support for Python 3.6, 3.7 because of requests requirement --- .mise.toml | 2 +- Makefile | 6 +++++- customerio/analytics/version.py | 2 +- requirements.txt | 2 +- setup.py | 3 +-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.mise.toml b/.mise.toml index 4522c872..de3ab232 100644 --- a/.mise.toml +++ b/.mise.toml @@ -7,7 +7,7 @@ _.python.venv = { } [tools] -python = "3.9" +python = "3.11" [tasks.test] run = 'make install test' diff --git a/Makefile b/Makefile index 885bed58..a0011a00 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,8 @@ lint: pylint --rcfile=.pylintrc --reports=y --exit-zero customerio/analytics flake8 --max-complexity=10 --statistics customerio/analytics || true -.PHONY: install test lint +clean: + rm -rf .venv + mise deps + +.PHONY: install test lint clean diff --git a/customerio/analytics/version.py b/customerio/analytics/version.py index 1f6518e6..1e5a6058 100644 --- a/customerio/analytics/version.py +++ b/customerio/analytics/version.py @@ -1 +1 @@ -VERSION = '0.1.0' +VERSION = '1.0.0' diff --git a/requirements.txt b/requirements.txt index 0867b28b..86364777 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ monotonic==1.6 mock==2.0.0 pylint==3.3.3 python-dateutil==2.8.2 -requests>=2.32.2 \ No newline at end of file +requests>=2.32.4 \ No newline at end of file diff --git a/setup.py b/setup.py index d1802d24..1ec92d33 100644 --- a/setup.py +++ b/setup.py @@ -38,8 +38,7 @@ maintainer_email='cdp@customer.io', test_suite='analytics.test.all', packages=['customerio.analytics'], - # Newer versions are not tested with Python 3.6 or 3.7. - python_requires='>=3.6.0', + python_requires='>=3.8.0', license='MIT License', install_requires=install_requires, extras_require={ From 5b5a65b8d7514fadefdbedcd00b6f6687157cea2 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 10:16:07 +0100 Subject: [PATCH 18/22] Bump version to 1.0.0 --- .bumpversion.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 6ad311a9..facbe377 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.0.2 +current_version = 1.0.0 parse = (?P\d+)\.(?P\d+)\.(?P\d+) serialize = {major}.{minor}.{patch} From d5ded78302b0c16c2825f20c2cc1a2a3ab2163ef Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 10:20:36 +0100 Subject: [PATCH 19/22] Review feedback --- Makefile | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a0011a00..5f587814 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ test: lint: pylint --rcfile=.pylintrc --reports=y --exit-zero customerio/analytics - flake8 --max-complexity=10 --statistics customerio/analytics || true + flake8 --max-complexity=10 --statistics --exit-zero customerio/analytics clean: rm -rf .venv diff --git a/setup.py b/setup.py index 1ec92d33..e2463395 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ ''' install_requires = [ - "requests>=2.32.2", + "requests>=2.32.4", "monotonic~=1.6", "backoff~=2.2", "python-dateutil~=2.8" From 7673d4e8b5fe7a90e02acd2c22ce7a91d38d87bc Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 10:44:15 +0100 Subject: [PATCH 20/22] Add lint-ci which fails only on linting errors --- .github/workflows/lint.yml | 2 +- Makefile | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index be41a45e..c2a97a51 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,4 +16,4 @@ jobs: cache-dependency-path: setup.py - run: pip3 install -e '.[test]' - - run: make lint + - run: make lint-ci diff --git a/Makefile b/Makefile index 5f587814..0d6122af 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,12 @@ lint: pylint --rcfile=.pylintrc --reports=y --exit-zero customerio/analytics flake8 --max-complexity=10 --statistics --exit-zero customerio/analytics +lint-ci: + pylint --rcfile=.pylintrc --exit-zero --fail-on=E customerio/analytics + flake8 --max-complexity=10 --max-line-length=100 --statistics customerio/analytics + clean: rm -rf .venv mise deps -.PHONY: install test lint clean +.PHONY: install test lint lint-ci clean From de0ee97b7eaba4b76fb037edb67267978703aa95 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 10:58:46 +0100 Subject: [PATCH 21/22] Prefer using pip from venv to uv --- .mise.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.mise.toml b/.mise.toml index de3ab232..826f9b46 100644 --- a/.mise.toml +++ b/.mise.toml @@ -6,6 +6,10 @@ _.python.venv = { create = true, } +[settings] +python.uv_venv_auto = false +python.venv_stdlib = true + [tools] python = "3.11" From ddc5d6ad37d93a57dd64e55cbccdf0ed4d812e63 Mon Sep 17 00:00:00 2001 From: Richard Dawe Date: Thu, 25 Jun 2026 11:00:10 +0100 Subject: [PATCH 22/22] Fix pylint errors: missing __init__.py, import ordering, exception handling Add customerio/__init__.py so pylint can resolve the package hierarchy. Fix raise-missing-from, return-in-finally, and import ordering warnings. Fix RuntimeError formatting bug where %-placeholders were not interpolated. Co-Authored-By: Claude Opus 4.6 (1M context) --- customerio/__init__.py | 0 customerio/analytics/client.py | 17 +++++++++-------- customerio/analytics/consumer.py | 10 +++++----- customerio/analytics/request.py | 4 ++-- customerio/analytics/test/consumer.py | 5 +++-- 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 customerio/__init__.py diff --git a/customerio/__init__.py b/customerio/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/customerio/analytics/client.py b/customerio/analytics/client.py index 4185d776..c5387fb3 100644 --- a/customerio/analytics/client.py +++ b/customerio/analytics/client.py @@ -1,19 +1,18 @@ -from datetime import datetime -from uuid import uuid4 -import logging -import numbers import atexit import json +import logging +import numbers +import queue +from datetime import datetime +from uuid import uuid4 from dateutil.tz import tzutc -from customerio.analytics.utils import guess_timezone, clean from customerio.analytics.consumer import Consumer, MAX_MSG_SIZE from customerio.analytics.request import post, DatetimeSerializer +from customerio.analytics.utils import guess_timezone, clean from customerio.analytics.version import VERSION -import queue - ID_TYPES = (numbers.Number, str) @@ -269,7 +268,9 @@ def _enqueue(self, msg): # Check message size. msg_size = len(json.dumps(msg, cls=DatetimeSerializer).encode()) if msg_size > MAX_MSG_SIZE: - raise RuntimeError('Message exceeds %skb limit. (%s)', str(int(MAX_MSG_SIZE / 1024)), str(msg)) + raise RuntimeError( + 'Message exceeds %dkb limit. (%s)' % (MAX_MSG_SIZE // 1024, msg) + ) # if send is False, return msg as if it was successfully queued if not self.send: diff --git a/customerio/analytics/consumer.py b/customerio/analytics/consumer.py index d9b05479..8f478b54 100644 --- a/customerio/analytics/consumer.py +++ b/customerio/analytics/consumer.py @@ -1,13 +1,13 @@ +import json import logging +from queue import Empty from threading import Thread -import monotonic + import backoff -import json +import monotonic from customerio.analytics.request import post, APIError, DatetimeSerializer -from queue import Empty - MAX_MSG_SIZE = 32 << 10 # Our servers only accept batches less than 500KB. Here limit is set slightly @@ -73,7 +73,7 @@ def upload(self): # mark items as acknowledged from queue for _ in batch: self.queue.task_done() - return success + return success def next(self): """Return the next batch of items to upload.""" diff --git a/customerio/analytics/request.py b/customerio/analytics/request.py index 0b92f4cf..5b0eb99a 100644 --- a/customerio/analytics/request.py +++ b/customerio/analytics/request.py @@ -56,8 +56,8 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, **kwargs): payload = res.json() log.debug('received response: %s', payload) raise APIError(res.status_code, payload['code'], payload['message']) - except ValueError: - raise APIError(res.status_code, 'unknown', res.text) + except ValueError as exc: + raise APIError(res.status_code, 'unknown', res.text) from exc class APIError(Exception): diff --git a/customerio/analytics/test/consumer.py b/customerio/analytics/test/consumer.py index 5ef02fc5..057f6338 100644 --- a/customerio/analytics/test/consumer.py +++ b/customerio/analytics/test/consumer.py @@ -1,7 +1,8 @@ +import json +import time import unittest + import mock -import time -import json try: from queue import Queue