Skip to content

Commit bd76cea

Browse files
authored
Merge pull request #3 from novafloss/tox-ini-revamp-linters
A few tox.ini cleanups and improvements
2 parents c55e55b + f5a65dd commit bd76cea

File tree

8 files changed

+85
-35
lines changed

8 files changed

+85
-35
lines changed

.travis.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
# Config file for automatic testing at travis-ci.org
22
language: python
3-
python:
4-
- "3.5"
5-
env:
6-
- TOX_ENV=py27-django18
7-
- TOX_ENV=py35-django18
8-
- TOX_ENV=py27-django19
9-
- TOX_ENV=py35-django19
10-
- TOX_ENV=py27-django110
11-
- TOX_ENV=py35-django110
3+
4+
matrix:
5+
include:
6+
# Python version is just for the look on travis.
7+
- python: 2.7
8+
env: TOX_ENV=py27-django18
9+
10+
- python: 2.7
11+
env: TOX_ENV=py27-django19
12+
13+
- python: 2.7
14+
env: TOX_ENV=py27-django110
15+
16+
- python: 3.5
17+
env: TOX_ENV=py35-django18
18+
19+
- python: 3.5
20+
env: TOX_ENV=py35-django19
21+
22+
- python: 3.5
23+
env: TOX_ENV=py35-django110
24+
25+
- env: TOX_ENV=linters
26+
1227
install:
13-
- pip install tox
28+
- pip install tox codecov
29+
1430
script:
1531
- tox -e $TOX_ENV
32+
33+
after_success:
34+
- codecov

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ clean-pyc: ## remove Python file artifacts
1717
find . -name '*~' -exec rm -f {} +
1818

1919
lint: ## check style with flake8
20-
flake8 django_readonly_field tests
20+
flake8 --exclude="migrations,.tox,docs,build" .
2121

2222
test: ## run tests quickly with the default Python
2323
python runtests.py
@@ -27,8 +27,6 @@ test-all: ## run tests on every Python version with tox
2727

2828
coverage: ## check code coverage quickly with the default Python
2929
coverage run --source django_readonly_field runtests.py
30-
coverage report -m
31-
coverage html
3230

3331
docs: ## generate Sphinx HTML documentation, including API docs
3432
rm -f docs/django-readonly-field.rst

django_readonly_field/compiler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from django.db.models.sql.compiler import SQLCompiler
2-
from django.db.models.sql.compiler import SQLInsertCompiler as BaseSQLInsertCompiler
2+
from django.db.models.sql.compiler import SQLInsertCompiler as BaseSQLInsertCompiler # noqa
33
from django.db.models.sql.compiler import SQLDeleteCompiler
4-
from django.db.models.sql.compiler import SQLUpdateCompiler as BaseSQLUpdateCompiler
4+
from django.db.models.sql.compiler import SQLUpdateCompiler as BaseSQLUpdateCompiler # noqa
55
from django.db.models.sql.compiler import SQLAggregateCompiler
66

7+
SQLCompiler = SQLCompiler
8+
SQLDeleteCompiler = SQLDeleteCompiler
9+
SQLAggregateCompiler = SQLAggregateCompiler
10+
711

812
class ReadOnlySQLCompilerMixin(object):
913

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
bumpversion==0.5.3
33
wheel==0.29.0
44
sphinx>=1.4.6
5+
tox>=1.7.0

requirements_test.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-r requirements.txt
22
coverage==4.1
33
mock>=1.0.1
4-
flake8>=2.1.0
5-
tox>=1.7.0
64
psycopg2>=2.6.2
75
dj_database_url>=0.4.1

runtests.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
#!/usr/bin/env python
22
import sys
33
import os
4+
import contextlib
45

5-
try:
6-
from django import setup
7-
except ImportError:
8-
import traceback
9-
traceback.print_exc()
10-
msg = "To fix this error, run: pip install -r requirements_test.txt"
11-
raise ImportError(msg)
126

13-
from django.test.utils import get_runner
14-
from django.conf import settings
15-
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.readonly_project.settings"
16-
setup()
7+
@contextlib.contextmanager
8+
def cover():
9+
do_coverage = "COVERAGE" in os.environ
10+
11+
if do_coverage:
12+
import coverage
13+
cov = coverage.Coverage(source=["django_readonly_field"])
14+
cov.start()
15+
print("Coverage will be generated")
16+
17+
try:
18+
yield
19+
finally:
20+
if do_coverage:
21+
cov.stop()
22+
cov.save()
1723

1824

1925
def run_tests(*test_args):
20-
from django.core.management import execute_from_command_line
21-
execute_from_command_line(["", "test", ] + sys.argv[1:])
26+
27+
with cover():
28+
try:
29+
from django import setup
30+
except ImportError:
31+
import traceback
32+
traceback.print_exc()
33+
msg = ("To fix this error, run: "
34+
"pip install -r requirements_test.txt")
35+
raise ImportError(msg)
36+
37+
module = "tests.readonly_project.settings"
38+
os.environ["DJANGO_SETTINGS_MODULE"] = module
39+
setup()
40+
41+
from django.core.management import execute_from_command_line
42+
execute_from_command_line(["", "test", ] + sys.argv[1:])
2243

2344

2445
if __name__ == '__main__':

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
'django_readonly_field',
4343
],
4444
include_package_data=True,
45-
install_requires=[],
45+
install_requires=["Django>=1.8,<1.11"],
46+
test_requires=["tox"],
4647
license="MIT",
4748
zip_safe=False,
4849
keywords='django-readonly-field',

tox.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[tox]
2+
skipsdist = True
23
envlist =
3-
{py27,py35}-django18
4-
{py27,py35}-django19
5-
{py27,py35}-django110
4+
{py27,py35}-django{18,19,110},linters
65

76
[testenv]
8-
passenv = DATABASE_URL
7+
passenv = DATABASE_URL COVERAGE
98
setenv =
109
PYTHONPATH = {toxinidir}:{toxinidir}/django_readonly_field
1110
commands =
@@ -16,3 +15,12 @@ deps =
1615
django-19: Django>=1.9,<1.10
1716
django-110: Django>=1.10,<1.11
1817
-r{toxinidir}/requirements_test.txt
18+
19+
# Dedicated linter tox target
20+
[testenv:linters]
21+
whitelist_externals = make
22+
deps =
23+
# Does not need any other requirement
24+
flake8>=2.1.0
25+
commands =
26+
make lint

0 commit comments

Comments
 (0)