Skip to content

Commit d7b88f0

Browse files
author
Ryan Lane
authored
Use lru-dict, if it is available (#16)
* Use lru-dict, if it is available * Use github actions rather than travis * Ensure build directory exists * Lock python 3 version to 3.6 * Upgrade boto3 * Test all of python3 * Upgrade coverage
1 parent bf143e1 commit d7b88f0

File tree

10 files changed

+82
-30
lines changed

10 files changed

+82
-30
lines changed

.github/workflows/pull_request.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on: pull_request
2+
jobs:
3+
pre-commit:
4+
runs-on: ubuntu-18.04
5+
steps:
6+
- name: Checkout
7+
uses: actions/checkout@v1
8+
- name: Setup python 3.6
9+
uses: actions/setup-python@v1
10+
with:
11+
python-version: 3.6
12+
- name: Install pre-commit
13+
run: pip install pre-commit
14+
- name: Run pre-commit
15+
run: pre-commit run --all-files
16+
test:
17+
runs-on: ubuntu-18.04
18+
strategy:
19+
matrix:
20+
python-version: ['2.x', '3.6.x', '3.7.x', '3.8.x']
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v1
24+
- name: Setup python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v1
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: pip install -r requirements.txt
30+
- name: Run tests
31+
run: make test

.github/workflows/push.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build and Deploy
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- '*'
8+
jobs:
9+
build-and-publish-python-module:
10+
name: Build and publish python module to pypi
11+
runs-on: ubuntu-18.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v1
15+
- name: Setup python 3.6
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: 3.6
19+
- name: Add wheel dependency
20+
run: pip install wheel
21+
- name: Generate dist
22+
run: python setup.py sdist bdist_wheel
23+
- name: Publish to PyPI
24+
if: startsWith(github.event.ref, 'refs/tags')
25+
uses: pypa/gh-action-pypi-publish@master
26+
with:
27+
user: __token__
28+
password: ${{ secrets.pypi_password }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ nosetests.xml
4444
coverage.xml
4545
*,cover
4646
.hypothesis/
47+
.mypy_cache
4748

4849
# Translations
4950
*.mo

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exclude: '^docs/.*$'
2+
repos:
3+
- repo: https://gitlab.com/pycqa/flake8
4+
rev: 3.7.9
5+
hooks:
6+
- id: flake8

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.0
2+
3+
* kmsauth will use lru-dict library for its token cache, rather than a slower pure-python implementation, if lru-dict is available.
4+
15
## 0.5.0
26

37
* KMSTokenValidator now accepts a ``stats`` argument, which allows you to pass in an instance of a statsd client, so that the validator can track stats.

Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# bash needed for pipefail
22
SHELL := /bin/bash
33

4-
test: test_lint test_unit
5-
6-
test_lint:
7-
mkdir -p build
8-
set -o pipefail; flake8 | sed "s#^\./##" > build/flake8.txt || (cat build/flake8.txt && exit 1)
4+
test: test_unit
95

106
test_unit:
7+
mkdir -p build
118
nosetests --with-coverage tests/unit

kmsauth/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
EndpointConnectionError)
1212

1313
import kmsauth.services
14-
from kmsauth.utils import lru
14+
# Try to import the more efficient lru-dict, and fallback to slower pure-python
15+
# lru dict implementation if it's not available.
16+
try:
17+
from lru import LRU
18+
except ImportError:
19+
from kmsauth.utils.lru import LRUCache as LRU
1520

1621
TOKEN_SKEW = 3
1722
TIME_FORMAT = "%Y%m%dT%H%M%SZ"
@@ -114,7 +119,7 @@ def __init__(
114119
self.extra_context = {}
115120
else:
116121
self.extra_context = extra_context
117-
self.TOKENS = lru.LRUCache(token_cache_size)
122+
self.TOKENS = LRU(token_cache_size)
118123
self.KEY_METADATA = {}
119124
self.stats = stats
120125
self._validate()

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# for Python.
33
# License: Apache2
44
# Use: For KMS
5-
boto3==1.2.3
5+
boto3==1.11.9
66

77
# The modular source code checker: pep8, pyflakes and co
88
# License: MIT
@@ -12,7 +12,7 @@ flake8==2.3.0
1212
# Measures code coverage and emits coverage reports
1313
# Licence: BSD
1414
# Upstream url: https://pypi.python.org/pypi/coverage
15-
coverage==4.4.2
15+
coverage==4.5.4
1616

1717
# tool to check your Python code against some of the style conventions
1818
# License: Expat License

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from setuptools import setup, find_packages
1515

16-
VERSION = "0.5.0"
16+
VERSION = "0.6.0"
1717

1818
requirements = [
1919
# Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK)

0 commit comments

Comments
 (0)