Skip to content

Commit

Permalink
Separate code quality checks (#8)
Browse files Browse the repository at this point in the history
* Extract isort to a separate tox environment.

There is no need to run its checks on each environment.

* Imports sorted by isort to make the test happy.

* Extract flake8 to a separate tox environment to run its tests only once.

It is not yet activated because there are way to many flake8 failures in this
package.

* Do not omit tests from coverage.
  • Loading branch information
Michael Howitz committed Dec 3, 2016
1 parent a88fd0c commit b4da29b
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 27 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Expand Up @@ -4,4 +4,3 @@ source = RestrictedPython

[report]
precision = 2
omit = */tests/*
11 changes: 10 additions & 1 deletion .travis.yml
Expand Up @@ -6,10 +6,19 @@ python:
- 3.5
- 3.6-dev
- pypy
env:
- ENVIRON=py
- ENVIRON=isort
matrix:
exclude:
- env: ENVIRON=isort
include:
- python: "3.5"
env: ENVIRON=isort
install:
- pip install tox coveralls coverage
script:
- tox -e py
- tox -e $ENVIRON
after_success:
- coverage combine
- coveralls
Expand Down
1 change: 1 addition & 0 deletions src/RestrictedPython/Eval.py
Expand Up @@ -19,6 +19,7 @@

import string


nltosp = string.maketrans('\r\n', ' ')

default_guarded_getattr = getattr # No restrictions.
Expand Down
2 changes: 2 additions & 0 deletions src/RestrictedPython/Guards.py
Expand Up @@ -16,6 +16,8 @@
# DocumentTemplate.DT_UTil contains a few.

import sys


try:
import builtins
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions src/RestrictedPython/MutatingWalker.py
Expand Up @@ -13,6 +13,7 @@

from compiler import ast


ListType = type([])
TupleType = type(())
SequenceTypes = (ListType, TupleType)
Expand Down
7 changes: 3 additions & 4 deletions src/RestrictedPython/RCompile.py
Expand Up @@ -15,18 +15,17 @@
"""

from compiler import ast as c_ast
from compiler import parse as c_parse
from compiler import misc as c_misc
from compiler import parse as c_parse
from compiler import syntax as c_syntax
from compiler import pycodegen
from compiler.pycodegen import AbstractCompileMode
from compiler.pycodegen import Expression
from compiler.pycodegen import findOp
from compiler.pycodegen import FunctionCodeGenerator
from compiler.pycodegen import Interactive
from compiler.pycodegen import Module
from compiler.pycodegen import ModuleCodeGenerator
from compiler.pycodegen import FunctionCodeGenerator
from compiler.pycodegen import findOp

from RestrictedPython import MutatingWalker
from RestrictedPython.RestrictionMutator import RestrictionMutator

Expand Down
2 changes: 1 addition & 1 deletion src/RestrictedPython/RestrictionMutator.py
Expand Up @@ -18,10 +18,10 @@
"""

from compiler import ast
from compiler.transformer import parse
from compiler.consts import OP_APPLY
from compiler.consts import OP_ASSIGN
from compiler.consts import OP_DELETE
from compiler.transformer import parse


# These utility functions allow us to generate AST subtrees without
Expand Down
14 changes: 7 additions & 7 deletions src/RestrictedPython/SelectCompiler.py
Expand Up @@ -13,15 +13,15 @@
"""Compiler selector.
"""

# Use the compiler from the standard library.
import compiler
from compiler import ast
from compiler.transformer import parse
from compiler.consts import OP_APPLY
from compiler.consts import OP_ASSIGN
from compiler.consts import OP_DELETE
from compiler.consts import OP_APPLY

from compiler.transformer import parse
from RestrictedPython.RCompile import compile_restricted
from RestrictedPython.RCompile import compile_restricted_function
from RestrictedPython.RCompile import compile_restricted_exec
from RestrictedPython.RCompile import compile_restricted_eval
from RestrictedPython.RCompile import compile_restricted_exec
from RestrictedPython.RCompile import compile_restricted_function

# Use the compiler from the standard library.
import compiler
1 change: 1 addition & 0 deletions src/RestrictedPython/Utilities.py
Expand Up @@ -16,6 +16,7 @@
import string
import warnings


# _old_filters = warnings.filters[:]
# warnings.filterwarnings('ignore', category=DeprecationWarning)
# try:
Expand Down
13 changes: 6 additions & 7 deletions src/RestrictedPython/__init__.py
Expand Up @@ -20,15 +20,14 @@

# new API Style
from RestrictedPython.compile import compile_restricted
from RestrictedPython.compile import compile_restricted_exec
from RestrictedPython.compile import compile_restricted_eval
from RestrictedPython.compile import compile_restricted_single
from RestrictedPython.compile import compile_restricted_exec
from RestrictedPython.compile import compile_restricted_function

from RestrictedPython.compile import compile_restricted_single
from RestrictedPython.Guards import safe_builtins
from RestrictedPython.Limits import limited_builtins
from RestrictedPython.PrintCollector import PrintCollector
from RestrictedPython.Utilities import utility_builtins

#from RestrictedPython.Eval import RestrictionCapableEval

from RestrictedPython.Guards import safe_builtins
from RestrictedPython.Utilities import utility_builtins
from RestrictedPython.Limits import limited_builtins
#from RestrictedPython.Eval import RestrictionCapableEval
4 changes: 2 additions & 2 deletions src/RestrictedPython/test_helper.py
Expand Up @@ -21,11 +21,11 @@
function.
"""

from dis import findlinestarts

import dis
import types

from dis import findlinestarts


def verify(code):
"""Verify all code objects reachable from code.
Expand Down
1 change: 1 addition & 0 deletions src/RestrictedPython/tests/testREADME.py
Expand Up @@ -17,6 +17,7 @@

import unittest


__docformat__ = "reStructuredText"


Expand Down
16 changes: 12 additions & 4 deletions tox.ini
@@ -1,13 +1,13 @@
[tox]
envlist = coverage-clean,py{27,34,35,36,py},coverage-report
envlist = coverage-clean,py{27,34,35,36,py},coverage-report,isort

[testenv]
install_command = pip install --egg {opts} {packages}
usedevelop = True
commands =
# py.test --cov=src --cov-report=xml {posargs}
# py.test --cov=src --isort --flake8 --tb=long --cov-report=xml {posargs}
py.test -x --pdb --isort --tb=long --cov=src --cov-report=xml {posargs}
py.test -x --pdb --tb=long --cov=src --cov-report=xml {posargs}
setenv =
COVERAGE_FILE=.coverage.{envname}
deps =
Expand All @@ -17,8 +17,6 @@ deps =
pytest < 3.0
pytest-cov
pytest-remove-stale-bytecode
pytest-flake8
pytest-isort
pytest-mock
# pytest-mypy

Expand All @@ -37,3 +35,13 @@ commands =
coverage report
coverage html
coverage xml

[testenv:isort]
basepython = python3.4
deps = isort
commands = isort --check-only --recursive {toxinidir}/src {posargs}

[testenv:flake8]
basepython = python3.4
deps = flake8
commands = flake8 src setup.py --doctests

0 comments on commit b4da29b

Please sign in to comment.