Skip to content

Commit 8c8dad9

Browse files
author
roll
authored
Setup linting (#81)
* setup linting * fixed linting * fixed linting for py2
1 parent 977c9c0 commit 8c8dad9

17 files changed

+46
-62
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ install:
1919
- pip install coveralls
2020

2121
script:
22-
# FIXME: configure linter
23-
# - make lint
2422
- make test
2523

2624
after_success:

CONTRIBUTING.md

+12-17
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,33 @@ To install package and development dependencies into active environment:
1111
$ make install
1212
```
1313

14-
## Linting
14+
## Testing
1515

16-
To lint the project codebase:
16+
To run tests with linting and coverage:
1717

1818
```
19-
$ make lint
19+
$ make test
2020
```
2121

22-
Under the hood `pylint` configured in `pylintrc` is used. On this stage it's already
22+
For linting `pylama` configured in `pylama.ini` is used. On this stage it's already
2323
installed into your environment and could be used separately with more fine-grained control
24-
as described in documentation - https://www.pylint.org/.
24+
as described in documentation - https://pylama.readthedocs.io/en/latest/.
2525

26-
For example to check only errors:
26+
For example to sort results by error type:
2727

2828
```
29-
$ pylint -E <path>
29+
$ pylama --sort <path>
3030
```
3131

32-
## Testing
33-
34-
To run tests with coverage:
35-
36-
```
37-
$ make test
38-
```
39-
Under the hood `tox` powered by `py.test` and `coverage` configured in `tox.ini` is used.
40-
It's already installed into your environment and could be used separately with more fine-grained control
41-
as described in documentation - https://testrun.org/tox/latest/.
32+
For testing `tox` configured in `tox.ini` is used.
33+
It's already installed into your environment and could be used separately with more fine-grained control as described in documentation - https://testrun.org/tox/latest/.
4234

4335
For example to check subset of tests against Python 2 environment with increased verbosity.
4436
All positional arguments and options after `--` will be passed to `py.test`:
4537

4638
```
4739
tox -e py27 -- -v tests/<path>
4840
```
41+
42+
Under the hood `tox` uses `pytest` configured in `pytest.ini`, `coverage`
43+
and `mock` packages. This packages are available only in tox envionments.

MANIFEST.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
global-include VERSION
22
include LICENSE.md
33
include Makefile
4-
include pylintrc
4+
include pylama.ini
5+
include pytest.ini
56
include README.md
67
include tox.ini
78

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all install list lint release test version
1+
.PHONY: all install list release test version
22

33

44
PACKAGE := $(shell grep '^PACKAGE =' setup.py | cut -d "'" -f2)
@@ -14,14 +14,14 @@ list:
1414
@grep '^\.PHONY' Makefile | cut -d' ' -f2- | tr ' ' '\n'
1515

1616
lint:
17-
pylint $(PACKAGE)
1817

1918
release:
2019
bash -c '[[ -z `git status -s` ]]'
2120
git tag -a -m release $(VERSION)
2221
git push --tags
2322

2423
test:
24+
pylama $(PACKAGE)
2525
tox
2626

2727
version:

jsontableschema/constraints/maximum.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from __future__ import print_function
55
from __future__ import unicode_literals
66

7-
from datetime import datetime, date, time
8-
from dateutil.parser import parse as date_parse
97
from .. import exceptions
108

119

jsontableschema/constraints/minimum.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from __future__ import print_function
55
from __future__ import unicode_literals
66

7-
from datetime import datetime, date, time
8-
from dateutil.parser import parse as date_parse
97
from .. import exceptions
108

119

jsontableschema/infer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,14 @@ def get(self, results):
137137
else:
138138
counts[result] = 1
139139

140-
# tuple representation of `counts` dict, sorted by values of `counts`
140+
# tuple representation of `counts` dict sorted by values
141141
sorted_counts = sorted(counts.items(), key=operator.itemgetter(1),
142142
reverse=True)
143143
rv = {
144144
'type': sorted_counts[0][0][0],
145145
'format': sorted_counts[0][0][1]
146146
}
147147

148-
149148
return rv
150149

151150

jsontableschema/types/base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
from __future__ import print_function
55
from __future__ import unicode_literals
66

7+
import six
8+
from six import add_metaclass
79
from functools import partial
810
from abc import ABCMeta, abstractmethod
9-
import six
1011
from .. import compat
1112
from .. import exceptions
1213
from .. import constraints
1314

1415

1516
# Module API
1617

18+
@add_metaclass(ABCMeta)
1719
class JTSType(object):
1820
"""Base class for all JSON Table Schema types.
1921
@@ -96,7 +98,8 @@ def cast(self, value, skip_constraints=False):
9698
# Check required constraint
9799
if not skip_constraints:
98100
required = self.__constraints.get('required', False)
99-
constraints.check_required(self.__field_name, value, required,
101+
constraints.check_required(
102+
self.__field_name, value, required,
100103
self.null_values+[None])
101104

102105
return None

jsontableschema/types/geojson.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ def cast_default(self, value, fmt=None):
4040
try:
4141
jsonschema.validate(value, _geojson_schema)
4242
return value
43-
except jsonschema.exceptions.ValidationError as e:
43+
except jsonschema.exceptions.ValidationError:
4444
raise_with_traceback(exceptions.InvalidGeoJSONType())
4545
if isinstance(value, compat.str):
4646
try:
4747
geojson = json.loads(value)
4848
jsonschema.validate(geojson, _geojson_schema)
4949
return geojson
50-
except (TypeError, ValueError) as e:
50+
except (TypeError, ValueError):
5151
raise_with_traceback(exceptions.InvalidGeoJSONType())
52-
except jsonschema.exceptions.ValidationError as e:
52+
except jsonschema.exceptions.ValidationError:
5353
raise_with_traceback(exceptions.InvalidGeoJSONType())
5454

5555
def cast_topojson(self, value, fmt=None):

jsontableschema/types/number.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class NumberType(base.JTSType):
3232
]
3333
# ---
3434
python_type = decimal.Decimal
35-
# TODO: Change this initialization to something more performant (http://bit.ly/1qgkK7B)
35+
# We could change this initialization to something
36+
# more performant (http://bit.ly/1qgkK7B)
3637
currencies = u''.join(compat.chr(i) for i
3738
in range(0xffff)
3839
if unicodedata.category(compat.chr(i)) == 'Sc')
@@ -41,7 +42,7 @@ def __preprocess_value(self, value):
4142
if type(value) is six.text_type:
4243
group_char = self.field.get('groupChar', ',')
4344
decimal_char = self.field.get('decimalChar', '.')
44-
percent_char = '%‰‱%﹪٪';
45+
percent_char = '%‰‱%﹪٪'
4546
value = value.replace(group_char, '').replace(decimal_char, '.')
4647
value = re.sub('['+percent_char+']', '', value)
4748
return value

jsontableschema/utilities.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def load_json_source(source):
4545

4646
try:
4747
return json.loads(source)
48-
except ValueError as e:
48+
except ValueError:
4949
raise exceptions.InvalidJSONError
5050

5151

jsontableschema/validate.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def iter_errors(self, instance, _schema=None):
9797
'be a string when foreignKey.reference.fields.'
9898
'is a string'
9999
)
100-
if not len(fk.get('fields')) == len(fk['reference']['fields']):
100+
if not (len(fk.get('fields')) ==
101+
len(fk['reference']['fields'])):
101102
yield exceptions.SchemaValidationError(
102103
'A JSON Table Schema foreignKey.fields must '
103104
'contain the same number entries as '

pylama.ini

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[pylama]
2+
linters = pyflakes,mccabe,pep8
3+
4+
[pylama:mccabe]
5+
complexity = 24
6+
7+
[pylama:*/__init__.py]
8+
ignore = W0611
9+
10+
[pylama:*/compat.py]
11+
ignore = W0611,E0602

pylintrc

-14
This file was deleted.

pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
testpaths = tests

setup.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ def read(*paths):
3030
'tabulator>=0.3',
3131
'unicodecsv>=0.14',
3232
]
33-
LINT_REQUIRES = [
34-
'pylint',
35-
]
3633
TESTS_REQUIRE = [
34+
'pylama',
3735
'tox',
3836
]
3937
README = read('README.md')
@@ -49,7 +47,7 @@ def read(*paths):
4947
include_package_data=True,
5048
install_requires=INSTALL_REQUIRES,
5149
tests_require=TESTS_REQUIRE,
52-
extras_require={'develop': LINT_REQUIRES + TESTS_REQUIRE},
50+
extras_require={'develop': TESTS_REQUIRE},
5351
entry_points={
5452
'console_scripts': [
5553
'jsontableschema = jsontableschema.cli:main',

tox.ini

-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,3 @@ commands=
2424
--cov-config tox.ini \
2525
--cov-report term-missing \
2626
{posargs}
27-
28-
[pytest]
29-
# pytest.ini configuration here
30-
testpaths = tests
31-
32-
[report]
33-
# .coveragerc configuration here

0 commit comments

Comments
 (0)