Skip to content

Commit

Permalink
Merge upstream remote (v0.10.0) (#6)
Browse files Browse the repository at this point in the history
* Fix pycontracts incompatibility with pyparsing v3 (closes snowplow#255)

* Update python versions in run-tests script (closes snowplow#256)

* Prepare for release

* Add Python 3.10 support (close snowplow#254)

PR snowplow#260

* Remove pycontracts library that wasn't compatible with Python 3.10
* Add Python type hints to all function arguments and return values
* Remove support for Python 2 due to the type hints
* Add custom contracts (e.g., non_empty_string) evaluated at the start of functions
* Run through Flake8 linter and correct style
* Remove Python 2 from Github action build
* Add Dockerfile for running tests under all supported Python versions

* Add configurable timeout for HTTP requests (close snowplow#258)

PR snowplow#259

* Prepare for release

* Increment version

Co-authored-by: adatzer <ada@snowplowanalytics.com>
Co-authored-by: Matúš Tomlein <matus.tomlein@gmail.com>
Co-authored-by: Deyan Deyanov <deyan@insurify.com>
  • Loading branch information
4 people committed Apr 5, 2022
1 parent f4d4b9d commit b357528
Show file tree
Hide file tree
Showing 28 changed files with 1,682 additions and 1,302 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/cd.yml
Expand Up @@ -36,7 +36,7 @@ jobs:

strategy:
matrix:
python-version: [2.7, 3.8]
python-version: [3.8]

steps:
- name: Checkout code
Expand All @@ -47,13 +47,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Ensure pip version for python 2
- name: Pin pip version
run: |
if [ "${{ matrix.python-version}}" == "2.7" ] ; then
echo "pip_v=pip < 21.0" >> $GITHUB_ENV
else
echo "pip_v=pip" >> $GITHUB_ENV
fi
echo "pip_v=pip" >> $GITHUB_ENV
- name: Build
run: |
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
extras-required: [".", ".[redis]"]

services:
Expand All @@ -35,13 +35,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Pin pip version for python 2
- name: Pin pip version
run: |
if [ "${{ matrix.python-version}}" == "2.7" ] ; then
echo "pip_v=pip < 21.0" >> $GITHUB_ENV
else
echo "pip_v=pip" >> $GITHUB_ENV
fi
echo "pip_v=pip" >> $GITHUB_ENV
- name: Install dependencies
run: |
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.txt
@@ -1,6 +1,7 @@
Version 0.10.0(2021-11-16)
Version 0.10.0 (2021-12-16)
--------------------------
Add ability to set Session ID (sid) and Session Index (vid)
Add Python 3.10 support (#254)
Add configurable timeout for HTTP requests (#258)

Version 0.9.1 (2021-10-26)
--------------------------
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
@@ -0,0 +1,17 @@
FROM centos:8

RUN yum -y install wget
RUN yum install -y epel-release
RUN yum -y install git tar gcc make bzip2 openssl openssl-devel patch gcc-c++ libffi-devel sqlite-devel
RUN git clone git://github.com/yyuu/pyenv.git ~/.pyenv
ENV HOME /root
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

RUN pyenv install 3.5.10 && pyenv install 3.6.14 && pyenv install 3.7.11 && pyenv install 3.8.11 && pyenv install 3.9.6 && pyenv install 3.10.1
RUN git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv

WORKDIR /app
COPY . .
RUN [ "./run-tests.sh", "deploy"]
CMD [ "./run-tests.sh", "test"]
11 changes: 11 additions & 0 deletions README.rst
Expand Up @@ -70,6 +70,17 @@ Find out more
.. _`Setup Guide`: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/python-tracker/setup/
.. _`Contributing`: https://github.com/snowplow/snowplow-python-tracker/blob/master/CONTRIBUTING.md

Python Support
##############

+----------------+--------------------------+
| Python version | snowplow-tracker version |
+================+==========================+
| >=3.5 | 0.10.0 |
+----------------+--------------------------+
| 2.7 | 0.9.1 |
+----------------+--------------------------+

Maintainer Quickstart
#######################

Expand Down
13 changes: 7 additions & 6 deletions requirements-test.txt
@@ -1,7 +1,8 @@
pytest==4.6.11
attrs==20.3.0
pytest==4.6.11; python_version < '3.10.0'
pytest==6.2.5; python_version >= '3.10.0'
attrs==21.2.0
httmock==1.4.0
freezegun==0.3.15
pytest-cov==2.11.1
coveralls==1.11.1
mock==3.0.5; python_version < '3.0'
freezegun==1.1.0
pytest-cov
coveralls==3.3.1
fakeredis==1.7.0
54 changes: 27 additions & 27 deletions run-tests.sh
Expand Up @@ -15,23 +15,6 @@ eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

function deploy {
# pyenv install 2.7.18
if [ ! -e ~/.pyenv/versions/tracker27 ]; then
pyenv virtualenv 2.7.18 tracker27
pyenv activate tracker27
pip install .
pip install -r requirements-test.txt
source deactivate
fi

if [ ! -e ~/.pyenv/versions/tracker27redis ]; then
pyenv virtualenv 2.7.18 tracker27redis
pyenv activate tracker27redis
pip install .[redis]
pip install -r requirements-test.txt
source deactivate
fi

# pyenv install 3.5.10
if [ ! -e ~/.pyenv/versions/tracker35 ]; then
pyenv virtualenv 3.5.10 tracker35
Expand Down Expand Up @@ -116,18 +99,27 @@ function deploy {
pip install -r requirements-test.txt
source deactivate
fi
}

# pyenv install 3.10.1
if [ ! -e ~/.pyenv/versions/tracker310 ]; then
pyenv virtualenv 3.10.1 tracker310
pyenv activate tracker310
pip install .
pip install -r requirements-test.txt
source deactivate
fi

function run_tests {
pyenv activate tracker27
pytest -s
source deactivate
if [ ! -e ~/.pyenv/versions/tracker310redis ]; then
pyenv virtualenv 3.10.1 tracker310redis
pyenv activate tracker310redis
pip install .[redis]
pip install -r requirements-test.txt
source deactivate
fi
}

pyenv activate tracker27redis
pytest -s
source deactivate

function run_tests {
pyenv activate tracker35
pytest
source deactivate
Expand Down Expand Up @@ -167,11 +159,17 @@ function run_tests {
pyenv activate tracker39redis
pytest
source deactivate

pyenv activate tracker310
pytest
source deactivate

pyenv activate tracker310redis
pytest
source deactivate
}

function refresh_deploy {
pyenv uninstall -f tracker27
pyenv uninstall -f tracker27redis
pyenv uninstall -f tracker35
pyenv uninstall -f tracker35redis
pyenv uninstall -f tracker36
Expand All @@ -182,6 +180,8 @@ function refresh_deploy {
pyenv uninstall -f tracker38redis
pyenv uninstall -f tracker39
pyenv uninstall -f tracker39redis
pyenv uninstall -f tracker310
pyenv uninstall -f tracker310redis
}


Expand Down
16 changes: 5 additions & 11 deletions setup.py
Expand Up @@ -19,7 +19,6 @@
License: Apache License Version 2.0
"""


#!/usr/bin/env python
# -*- coding: utf-8 -*-

Expand All @@ -28,24 +27,22 @@
except ImportError:
from distutils.core import setup

import os

authors_list = [
'Anuj More',
'Alexander Dean',
'Fred Blundun',
'Paul Boocock'
]
]
authors_str = ', '.join(authors_list)

authors_email_list = [
'support@snowplowanalytics.com',
]
]
authors_email_str = ', '.join(authors_email_list)

setup(
name='snowplow-tracker-oda',
version='0.10.1',
version='0.11.0',
author=authors_str,
author_email=authors_email_str,
packages=['snowplow_tracker', 'snowplow_tracker.test', 'snowplow_tracker.redis', 'snowplow_tracker.celery'],
Expand All @@ -60,22 +57,19 @@
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"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",
"Operating System :: OS Independent",
],

install_requires=[
"requests>=2.25.1,<3.0",
"pycontracts>=1.8.12;python_version<'3.0'",
"pycontracts3>=3.0.2;python_version>='3.0'",
"six>=1.9.0,<2.0"
"typing_extensions>=3.7.4"
],

extras_require={
Expand Down
2 changes: 1 addition & 1 deletion snowplow_tracker/__init__.py
Expand Up @@ -3,7 +3,7 @@
from snowplow_tracker.emitters import logger, Emitter, AsyncEmitter
from snowplow_tracker.self_describing_json import SelfDescribingJson
from snowplow_tracker.tracker import Tracker
from contracts import disable_all as disable_contracts, enable_all as enable_contracts
from snowplow_tracker.contracts import disable_contracts, enable_contracts

# celery extra
from .celery import CeleryEmitter
Expand Down
3 changes: 1 addition & 2 deletions snowplow_tracker/_version.py
Expand Up @@ -19,7 +19,6 @@
License: Apache License Version 2.0
"""


__version_info__ = (0, 10, 0)
__version_info__ = (0, 11, 0)
__version__ = ".".join(str(x) for x in __version_info__)
__build_version__ = __version__ + ''
1 change: 0 additions & 1 deletion snowplow_tracker/celery/__init__.py
@@ -1,2 +1 @@
from .celery_emitter import CeleryEmitter

19 changes: 15 additions & 4 deletions snowplow_tracker/celery/celery_emitter.py
Expand Up @@ -20,7 +20,10 @@
"""

import logging
from typing import Any, Optional

from snowplow_tracker.emitters import Emitter
from snowplow_tracker.typing import HttpProtocol, Method

_CELERY_OPT = True
try:
Expand All @@ -33,6 +36,7 @@
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


class CeleryEmitter(Emitter):
"""
Uses a Celery worker to send HTTP requests asynchronously.
Expand All @@ -43,7 +47,14 @@ class CeleryEmitter(Emitter):

celery_app = None

def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_size=None, byte_limit=None):
def __init__(
self,
endpoint: str,
protocol: HttpProtocol = "http",
port: Optional[int] = None,
method: Method = "get",
buffer_size: Optional[int] = None,
byte_limit: Optional[int] = None) -> None:
super(CeleryEmitter, self).__init__(endpoint, protocol, port, method, buffer_size, None, None, byte_limit)

try:
Expand All @@ -57,18 +68,18 @@ def __init__(self, endpoint, protocol="http", port=None, method="get", buffer_si

self.async_flush = self.celery_app.task(self.async_flush)

def flush(self):
def flush(self) -> None:
"""
Schedules a flush task
"""
self.async_flush.delay()
logger.info("Scheduled a Celery task to flush the event queue")

def async_flush(self):
def async_flush(self) -> None:
super(CeleryEmitter, self).flush()

else:

def __new__(cls, *args, **kwargs):
def __new__(cls, *args: Any, **kwargs: Any) -> 'CeleryEmitter':
logger.error("CeleryEmitter is not available. Please install snowplow-tracker with celery extra dependency.")
raise RuntimeError('CeleryEmitter is not available. To use: `pip install snowplow-tracker[celery]`')

0 comments on commit b357528

Please sign in to comment.