Cleanup tox configuration

There were issues with dependencies and tox environments under Python 3
so refactored the tox configuration to be more consistent and clearer.

- Moved travis to default to Python 3 for linting and tests.
- Fixed missing mock for cairo in sphinx config.
- Collated the base deps sections to improve readability.
- Added PYTEST_ADDOPTS env to override pytest verbosity in just tox
  tests as this was a common option being used.
- Renamed env 'testcoverage' to the more concise 'coverage' and moved
  html creation under single env as handy to have this output as well
  as report.
- Cleaned up the isort config for gtk3.
- Added `bad-continuation` to pylint config as conflcts with black
  formatting.
- Fix isort issue with bbfreeze script. This will likely be removed
  in future so just skip sorting it.
This commit is contained in:
Calum Lind 2018-10-25 15:02:53 +01:00
parent 26c28445a5
commit 97e7d95dd3
7 changed files with 98 additions and 105 deletions

View File

@ -69,7 +69,7 @@ confidence=
# Arranged by category and use symbolic names instead of ids. # Arranged by category and use symbolic names instead of ids.
disable= disable=
# Convention # Convention
missing-docstring, invalid-name, missing-docstring, invalid-name, bad-continuation,
# Error # Error
no-member, no-name-in-module, no-member, no-name-in-module,
# Information # Information

View File

@ -3,7 +3,7 @@ sudo: required
language: python language: python
python: python:
- 2.7 - 3.5
cache: pip cache: pip
virtualenv: virtualenv:
system_site_packages: true system_site_packages: true
@ -16,8 +16,8 @@ matrix:
include: include:
- name: Unit tests - Python 2 - name: Unit tests - Python 2
env: TOX_ENV=py27 env: TOX_ENV=py27
python: 2.7
- name: Unit tests - Python 3 - name: Unit tests - Python 3
python: 3.5
env: TOX_ENV=py3 env: TOX_ENV=py3
- if: commit_message =~ SECURITY_TEST - if: commit_message =~ SECURITY_TEST
env: TOX_ENV=security env: TOX_ENV=security
@ -25,8 +25,9 @@ matrix:
env: TOX_ENV=lint env: TOX_ENV=lint
- name: Docs build - name: Docs build
env: TOX_ENV=docs env: TOX_ENV=docs
- name: PyGTK unit tests python: 2.7
env: TOX_ENV=pygtkui - name: GTK unit tests
env: TOX_ENV=gtkui
- name: Plugins unit tests - name: Plugins unit tests
env: TOX_ENV=plugins env: TOX_ENV=plugins
@ -46,8 +47,9 @@ addons:
# Install dependencies # Install dependencies
install: install:
- pip install tox tox-venv - pip install tox tox-venv
- "if [ $TOX_ENV == 'pygtkui' ]; then - "if [ $TOX_ENV == 'gtkui' ]; then
sudo apt install python-gi python-gi-cairo gir1.2-gtk-3.0; sudo apt install python-gi python-gi-cairo python3-gi python3-gi-cairo \
gir1.2-gtk-3.0;
fi" fi"
- "if [ $TOX_ENV == 'security' ]; then - "if [ $TOX_ENV == 'security' ]; then
testssl_url=https://github.com/drwetter/testssl.sh/archive/v2.9.5-5.tar.gz; testssl_url=https://github.com/drwetter/testssl.sh/archive/v2.9.5-5.tar.gz;
@ -59,7 +61,7 @@ before_script:
- export PYTHONPATH=$PYTHONPATH:$PWD - export PYTHONPATH=$PYTHONPATH:$PWD
- python -c "import libtorrent as lt; print(lt.__version__)" - python -c "import libtorrent as lt; print(lt.__version__)"
# Start xvfb for the GTKUI tests # Start xvfb for the GTKUI tests
- "if [ $TOX_ENV == 'pygtkui' ]; then - "if [ $TOX_ENV == 'gtkui' ]; then
/sbin/start-stop-daemon --start --quiet --background \ /sbin/start-stop-daemon --start --quiet --background \
--make-pidfile --pidfile /tmp/custom_xvfb_99.pid \ --make-pidfile --pidfile /tmp/custom_xvfb_99.pid \
--exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16; --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16;

View File

@ -96,6 +96,7 @@ autodoc_mock_imports = [
'libtorrent', 'libtorrent',
'psyco', 'psyco',
'gi', 'gi',
'cairo',
'curses', 'curses',
'win32api', 'win32api',
'win32file', 'win32file',

View File

@ -10,7 +10,7 @@
# the additional special exception to link portions of this program with the OpenSSL library. # the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details. # See LICENSE for more details.
# #
# isort:skip_file
from __future__ import print_function from __future__ import print_function
import glob import glob
@ -19,6 +19,7 @@ import re
import shutil import shutil
import sys import sys
import bbfreeze import bbfreeze
import gtk import gtk
from win32verstamp import stamp from win32verstamp import stamp

View File

@ -2,6 +2,7 @@ pytest
pytest-twisted pytest-twisted
pytest-cov pytest-cov
mock mock
pre-commit
flake8 flake8
flake8-quotes flake8-quotes
flake8-isort flake8-isort

View File

@ -19,10 +19,8 @@ frameworks = CoreFoundation, Foundation, AppKit
[isort] [isort]
known_standard_library = future_builtins known_standard_library = future_builtins
known_third_party = known_third_party =
# Ignore Windows specific modules.
bbfreeze, win32verstamp,
# Ignore gtk modules, primarily for tox testing. # Ignore gtk modules, primarily for tox testing.
pygtk, gtk, gobject, gtk.gdk, pango, cairo, pangocairo, gi cairo, gi,
# Ignore other module dependencies for pre-commit isort. # Ignore other module dependencies for pre-commit isort.
twisted, OpenSSL, pytest, recommonmark, chardet, pkg_resources, zope, mock, twisted, OpenSSL, pytest, recommonmark, chardet, pkg_resources, zope, mock,
sphinx sphinx

176
tox.ini
View File

@ -5,45 +5,74 @@
[tox] [tox]
envlist = py27, py3, lint, docs envlist = py27, py3, lint, docs
minversion=2.0 minversion=3.0
[base]
deps =
# Minimum pip version and setuptools to fix issue running on travis.
pip>=10
setuptools
-rrequirements.txt
[testenv]
install_command = {envpython} -m pip install --ignore-installed {opts} {packages}
passenv = DISPLAY PYTHONPATH
setenv = PYTHONPATH = {toxinidir}
sitepackages = True
deps =
{[base]deps}
-rrequirements-tests.txt
commands =
python -c "import libtorrent as lt; print(lt.__version__)"
pytest -v -s -m "not (todo or gtkui or security)" deluge/tests
[pytest] [pytest]
# Hide logged warnings and errors in test output. # Hide logged warnings and errors in test output.
log_cli_level = CRITICAL log_cli_level = CRITICAL
addopts = -p no:warnings --basetemp=_pytest_temp addopts = -p no:warnings --basetemp=_pytest_temp
# =================
# Base dependencies
# =================
[basesetup]
# Minimum pip and setuptools versions to fix system and travis issues.
deps =
pip>=10
setuptools>=40
[basetests]
deps =
{[basesetup]deps}
-rrequirements.txt
-rrequirements-tests.txt
[baselint]
deps =
{[basesetup]deps}
-rrequirements-tests.txt
[basedev]
deps =
{[basesetup]deps}
-rrequirements.txt
-rrequirements-dev.txt
-rrequirements-tests.txt
[basedocs]
deps =
{[basesetup]deps}
-rrequirements-docs.txt
# ======================
# Test environment setup
# ======================
[testenv]
install_command = python -m pip install --ignore-installed {opts} {packages}
passenv = DISPLAY PYTHONPATH
setenv =
PYTHONPATH = {toxinidir}
PYTEST_ADDOPTS = -v -s
sitepackages = True
deps = {[basetests]deps}
commands =
python -c "import libtorrent as lt; print(lt.__version__)"
pytest -m "not (todo or gtkui or security)" deluge/tests
# ========== # ==========
# Unit tests # Unit tests
# ========== # ==========
[testenv:security] [testenv:security]
setenv = SECURITY_TESTS = True setenv = SECURITY_TESTS = True
commands = pytest -v -s -m "security" deluge/tests/ commands = pytest -m "security" deluge/tests
[testenv:pygtkui] [testenv:gtkui]
commands = pytest -v -s -m "gtkui" deluge/tests commands = pytest -m "gtkui" deluge/tests
[testenv:todo] [testenv:todo]
commands = pytest -v -s -m "todo" deluge/tests commands = pytest -m "todo" deluge/tests
[testenv:trial] [testenv:trial]
setenv = {[testenv]setenv}{:}{toxinidir}/deluge/tests setenv = {[testenv]setenv}{:}{toxinidir}/deluge/tests
@ -55,56 +84,44 @@ commands =
setenv = PYTHONPATH = {toxinidir}{:}{toxinidir}/deluge/plugins setenv = PYTHONPATH = {toxinidir}{:}{toxinidir}/deluge/plugins
commands = commands =
python setup.py build_plugins --develop --install-dir={toxinidir}/deluge/plugins/ python setup.py build_plugins --develop --install-dir={toxinidir}/deluge/plugins/
pytest -v -s -m "not gtkui" deluge/plugins pytest -m "not gtkui" deluge/plugins
[testenv:pluginsgtkui] [testenv:pluginsgtkui]
setenv = PYTHONPATH = {toxinidir}{:}{toxinidir}/deluge/plugins setenv = PYTHONPATH = {toxinidir}{:}{toxinidir}/deluge/plugins
commands = commands =
python setup.py build_plugins --develop --install-dir={toxinidir}/deluge/plugins/ python setup.py build_plugins --develop --install-dir={toxinidir}/deluge/plugins/
pytest -v -s deluge/plugins pytest deluge/plugins
# ============
# =======================
# Code linting # Code linting
# ======================= # ============
# Disable site-packages to avoid using system installed commands.
[testenv:lint] [testenv:lint]
sitepackages = False
passenv = HOMEPATH SSH_AUTH_SOCK passenv = HOMEPATH SSH_AUTH_SOCK
deps = deps = {[baselint]deps}
pre-commit commands = pre-commit run --all-files
commands =
pre-commit run --all-files
[testenv:flake8] [testenv:flake8]
# Disable site packages to avoid using system flake8 which uses
# hardcoded python path which imports the wrong libraries.
sitepackages = False sitepackages = False
deps = deps = {[baselint]deps}
{[testenv]deps}
flake8
flake8-quotes
flake8-isort
pep8-naming
commands = commands =
flake8 --version flake8 --version
python -c 'import isort; print(isort.__version__)' python -c 'import isort; print(isort.__version__)'
flake8 flake8 *.py deluge
[testenv:flake8-complexity] [testenv:flake8-complexity]
sitepackages = False sitepackages = False
deps = deps = {[baselint]deps}
{[testenv:flake8]deps}
mccabe
commands = flake8 --exit-zero --max-complexity 15 deluge commands = flake8 --exit-zero --max-complexity 15 deluge
[testenv:pylint] [testenv:pylint]
# Disable site packages to avoid using system installed version
sitepackages = False sitepackages = False
ignore_errors = True ignore_errors = True
deps = deps = {[baselint]deps}
{[testenv]deps}
pylint
commands = commands =
pylint --version pylint --version
pylint deluge pylint deluge
@ -112,63 +129,40 @@ commands =
python -m pylint *.py deluge/scripts/*.py python -m pylint *.py deluge/scripts/*.py
python -m pylint deluge/plugins/*/deluge/ python -m pylint deluge/plugins/*/deluge/
# ========
# Coverage
# ========
# ============= [coveragebase]
# Test coverage commands = coverage run --branch --source=deluge -m pytest -m "not todo" deluge/tests
# =============
[testcoveragebase] [testenv:coverage]
deps =
{[testenv]deps}
pytest-cov
coverage
commands = coverage run --branch --source=deluge -m pytest -m "not todo" deluge/tests/
[testenv:testcoverage]
setenv = {[testenv]setenv}
deps = {[testcoveragebase]deps}
commands = commands =
{[testcoveragebase]commands} {[coveragebase]commands}
coverage report
[testenv:testcoverage-html]
setenv = {[testenv]setenv}
deps = {[testcoveragebase]deps}
commands =
{[testcoveragebase]commands}
coverage html -d docs/build/htmlcoverage coverage html -d docs/build/htmlcoverage
coverage report
# =================== # ===================
# Documentation build # Documentation build
# =================== # ===================
# We do not have all dependencies on RTD and travis so we exclude the
# site packages (sitepackages=False) when building docs so that local
# tests have a similar environment.
[docsbase]
sitepackages = False
changedir = docs
deps =
-rrequirements-docs.txt
[testenv:docs] [testenv:docs]
basepython = python2.7 basepython = python2.7
sitepackages = {[docsbase]sitepackages} # Exclude site-packages so local builds have a similar environment to ReadTheDocs.
sitepackages = False
skip_install = True skip_install = True
deps = {[docsbase]deps} deps = {[basedocs]deps}
commands = commands =
python setup.py clean_docs python setup.py clean_docs
sphinx-build -v -j auto -E -T -b html -d docs/build/doctrees docs/source docs/build/html sphinx-build -v -j auto -E -T -b html -d docs/build/doctrees docs/source docs/build/html
[testenv:docscoverage] [testenv:docscoverage]
basepython = python2.7 basepython = python2.7
sitepackages = {[docsbase]sitepackages} sitepackages = False
skip_install = True skip_install = True
changedir = {[docsbase]changedir} changedir = docs
deps = deps =
{[docsbase]deps} {[basedocs]deps}
pytest-cov pytest-cov
whitelist_externals = mkdir whitelist_externals = mkdir
commands = commands =
@ -176,24 +170,20 @@ commands =
sphinx-build -W -b coverage -d build/doctrees source build/doccoverage sphinx-build -W -b coverage -d build/doctrees source build/doccoverage
pytest --doctest-glob='*.rst' pytest --doctest-glob='*.rst'
# ======================== # ========================
# Development Environment # Development Environment
# ======================== # ========================
[basedev]
usedevelop = True
deps = -rrequirements-dev.txt
[testenv:denv2] [testenv:denv2]
basepython = python2.7 basepython = python2.7
envdir = .venv2 envdir = .venv2
usedevelop = {[basedev]usedevelop} usedevelop = True
deps = {[basedev]deps} deps = {[basedev]deps}
commands = commands =
[testenv:denv3] [testenv:denv3]
basepython = python3 basepython = python3
envdir = .venv3 envdir = .venv3
usedevelop = {[basedev]usedevelop} usedevelop = True
deps = {[basedev]deps} deps = {[basedev]deps}
commands = commands =