Skip to content

Commit

Permalink
Add tox config and mypy typechecks.
Browse files Browse the repository at this point in the history
  • Loading branch information
hengfengli committed Dec 5, 2018
1 parent d94ff6f commit f51a00e
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ bumpversion = "*"
"flake8" = "*"
moto = "*"
twine = "*"
tox = "*"
mypy = "*"
74 changes: 73 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions kcpy/checkpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sqlite3

from typing import Optional

class Checkpoint(object):
def __init__(self, sqlite_file_path, db_name, consumer_name: str, stream_name: str, shard_id: str) -> None:
Expand Down Expand Up @@ -41,7 +41,7 @@ def set(self, seq_no: str) -> None:
conn.commit()
conn.close()

def get(self) -> str:
def get(self) -> Optional[str]:
conn = sqlite3.connect(self.sqlite_file_path)
c = conn.cursor()
c.execute(f'SELECT seq_no FROM {self.db_name} '
Expand All @@ -54,6 +54,8 @@ def get(self) -> str:

if row:
return row[0]
else:
return None

def reset(self) -> None:
conn = sqlite3.connect(self.sqlite_file_path)
Expand Down
6 changes: 3 additions & 3 deletions kcpy/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import boto3
import time
from multiprocessing import Process, Queue
from typing import Optional
from typing import Optional, Dict
import uuid

from .checkpoint import Checkpoint
Expand Down Expand Up @@ -57,7 +57,7 @@ class ShardConsumerProcess(Process):
def __init__(self, stream_name, shard_id, options, checkpoint: Optional[Checkpoint] = None):
Process.__init__(self)
self.consumer = ShardConsumer(stream_name, shard_id, options, checkpoint)
self.queue = Queue()
self.queue = Queue() # type: Queue

def run(self):
for record in self.consumer:
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self,
self.stream_name = stream_name
self.options = options
self.client = boto3.client('kinesis', **self.options)
self.processes = {}
self.processes = {} # type: Dict[str, ShardConsumerProcess]
self.sleep_time = self.DEFAULT_SLEEP_TIME
self.enable_checkpoint = checkpoint

Expand Down
1 change: 1 addition & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3>=1.9
5 changes: 5 additions & 0 deletions requirements/dist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
twine>=1.12.1
bumpversion>=0.5.3
flake8>=3.6.0
tox>=3.5.3
mypy>=0.641
3 changes: 3 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest>=4.0.1
faker>=1.0.0
moto>=1.3.7
File renamed without changes.
Empty file added t/unit/__init__.py
Empty file.
File renamed without changes.
24 changes: 24 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tox]
envlist = py37,py36,py35,flake8,typecheck

[testenv]
deps=
-r{toxinidir}/requirements/default.txt
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/dist.txt
sitepackages = False
recreate = False
commands = py.test -xv

basepython =
py37,flake8,typecheck: python3.7
py36: python3.6
py35: python3.5

[testenv:flake8]
commands =
flake8 {toxinidir}/kcpy

[testenv:typecheck]
commands =
mypy --ignore-missing-imports -p kcpy

0 comments on commit f51a00e

Please sign in to comment.