Skip to content

Commit

Permalink
Test against Python 3.8, PyPy and PyPy3
Browse files Browse the repository at this point in the history
Test explicit Python versions with Tox

Add more Tox targets (bandit, clean, readme)
  • Loading branch information
bittner committed Nov 3, 2019
1 parent 16cd0d4 commit 6b662d9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 70 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
dist: xenial
sudo: true
language: python

language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7
- 3.8
- pypy2.7-6.0
- pypy3.5

install:
- pip install tox-travis
Expand All @@ -20,5 +23,7 @@ stages:

jobs:
include:
- { stage: lint, python: 3.7, env: TOXENV=bandit }
- { stage: lint, python: 3.7, env: TOXENV=flake8 }
- { stage: lint, python: 3.7, env: TOXENV=pylint }
- { stage: lint, python: 3.7, env: TOXENV=readme }
13 changes: 10 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ How to Contribute
Please `open an issue`_ to discuss your plans for a `pull request`_. After
writing code make sure your changes pass our quality gate before you push.

.. code-block:: bash
.. code-block:: console
# list all tox targets
tox -lv
# run all linting and tests
tox
$ tox
$ python setup.py clean
# run tests just for Python 3.8
# (e.g. if you don't have all Pythons installed via pyenv)
tox -e py38
Please write tests! Test coverage is still low and the code quality needs
to improve. Please help by adding tests with each contribution you make!
Expand Down
73 changes: 8 additions & 65 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,13 @@
#!/usr/bin/env python3
"""Packaging implementation for Sentry Logs"""
from __future__ import print_function

from glob import glob
import os
"""
Packaging setup for Sentry Logs
"""
from os.path import abspath, dirname, join
import shutil

from setuptools import Command, setup
from setuptools import setup

import sentrylogs as package


class SimpleCommand(Command):
"""A simple setuptools command (implementation of abstract base class)"""
user_options = []

def initialize_options(self):
"""Abstract method of the base class (required to be overridden)"""

def finalize_options(self):
"""Abstract method of the base class (required to be overridden)"""


class Clean(SimpleCommand):
"""Remove build files and folders, including Python byte-code"""
description = __doc__

@staticmethod
def run():
"""
Clean up files not meant for version control
"""
delete_in_root = [
'build',
'dist',
'.eggs',
'*.egg-info',
'.tox',
]
delete_everywhere = [
'*.pyc',
'__pycache__',
]
for candidate in delete_in_root:
rmtree_glob(candidate)
for visible_dir in glob('[A-Za-z0-9_]*'):
for candidate in delete_everywhere:
rmtree_glob(join(visible_dir, candidate))
rmtree_glob(join(visible_dir, '*', candidate))
rmtree_glob(join(visible_dir, '*', '*', candidate))


def rmtree_glob(file_glob):
"""Platform independent rmtree, which also allows wildcards (globbing)"""
for item in glob(file_glob, recursive=True):
try:
os.remove(item)
print('%s removed ...' % item)
except OSError:
try:
shutil.rmtree(item)
print('%s/ removed ...' % item)
except OSError as err:
print(err)


def read_file(filename):
"""Read the contents of a file located relative to setup.py"""
with open(join(abspath(dirname(__file__)), filename)) as file:
Expand All @@ -89,9 +31,13 @@ def read_file(filename):
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
description=package.__doc__.strip(),
long_description=read_file('README.rst'),
long_description_content_type='text/x-rst',
license=package.__license__,
url=package.__url__,
install_requires=read_file('requirements.txt'),
Expand All @@ -108,7 +54,4 @@ def read_file(filename):
],
test_suite='tests',
tests_require=['tox'],
cmdclass={
'clean': Clean,
},
)
33 changes: 32 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
[tox]
envlist =
bandit
flake8
pylint
python
py{27,34,35,36,37,38,py,py3}
readme
clean

[testenv]
description = Unit tests
deps =
cli-test-helpers
py27: mock
pypy: mock
pytest
commands = pytest
usedevelop = True

[testenv:bandit]
description = PyCQA security linter
deps = bandit<1.6.0
commands = bandit -r . --ini tox.ini

[testenv:clean]
description = Clean up bytecode and other debris
deps = pyclean
commands =
py3clean -v {toxinidir}
rm -rf build/ dist/ SentryLogs.egg-info/ .pytest_cache/ .tox/
whitelist_externals =
rm

[testenv:flake8]
description = Static code analysis and code style
deps = flake8
commands = flake8

[testenv:pylint]
description = Check for errors and code smells
deps = pylint
commands = pylint --rcfile=tox.ini setup.py sentrylogs

[testenv:readme]
description = Ensure README renders on PyPI
deps = twine
commands =
{envpython} setup.py -q sdist bdist_wheel
twine check dist/*

[bandit]
exclude = .tox,build,dist,tests

[flake8]
max-line-length = 81
exclude = build,dist,*.egg*,reports,.tox
Expand Down

0 comments on commit 6b662d9

Please sign in to comment.