Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 7 additions & 6 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
14 changes: 4 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
License: Apache License Version 2.0
"""


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

Expand All @@ -28,19 +27,17 @@
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(
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
Original file line number Diff line number Diff line change
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
1 change: 0 additions & 1 deletion snowplow_tracker/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
License: Apache License Version 2.0
"""


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

19 changes: 15 additions & 4 deletions snowplow_tracker/celery/celery_emitter.py
Original file line number Diff line number Diff line change
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]`')
Loading