Skip to content

Commit 49d7a0b

Browse files
committed
Add command for running flake8 and fix linting errors
1 parent a3925ca commit 49d7a0b

File tree

8 files changed

+69
-18
lines changed

8 files changed

+69
-18
lines changed

.circleci/config.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2
22
jobs:
3-
python35:
3+
test-python35:
44
docker:
55
- image: python:3.5-alpine
66
- image: postgres:11.0
@@ -22,7 +22,7 @@ jobs:
2222
environment:
2323
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'
2424

25-
python36:
25+
test-python36:
2626
docker:
2727
- image: python:3.6-alpine
2828
- image: postgres:11.0
@@ -44,7 +44,7 @@ jobs:
4444
environment:
4545
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'
4646

47-
python37:
47+
test-python37:
4848
docker:
4949
- image: python:3.7-alpine
5050
- image: postgres:11.0
@@ -66,11 +66,27 @@ jobs:
6666
environment:
6767
DATABASE_URL: 'postgres://psqlextra:psqlextra@localhost:5432/psqlextra'
6868

69+
lint:
70+
docker:
71+
- image: python3.5-alpine
72+
steps:
73+
- checkout
74+
- run:
75+
name: Install packages
76+
command: apk add postgresql-libs gcc musl-dev postgresql-dev git
77+
- run:
78+
name: Install Python packages
79+
command: pip install -r requirements/test.txt
80+
- run:
81+
name: Lint code
82+
command: python setup.py lint
83+
6984

7085
workflows:
7186
version: 2
7287
build:
7388
jobs:
74-
- python35
75-
- python36
76-
- python37
89+
- test-python35
90+
- test-python36
91+
- test-python37
92+
- lint

psqlextra/fields/hstore_field.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from django.db.models.fields import Field
55
from django.contrib.postgres.fields import HStoreField as DjangoHStoreField
66

7-
from psqlextra.expressions import HStoreValue
8-
97

108
class HStoreField(DjangoHStoreField):
119
"""Improved version of Django's :see:HStoreField that

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[flake8]
22
max-line-length = 120
3+
ignore = E252
34
exclude = env,.tox,.git,config/settings,*/migrations/*,*/static/CACHE/*,docs,node_modules
45

56
[pep8]

setup.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
import os
2+
import distutils.cmd
3+
import subprocess
24

35
from setuptools import find_packages, setup
46

7+
8+
class BaseCommand(distutils.cmd.Command):
9+
user_options = []
10+
11+
def initialize_options(self):
12+
pass
13+
14+
def finalize_options(self):
15+
pass
16+
17+
18+
def create_command(text, commands):
19+
"""Creates a custom setup.py command."""
20+
21+
class CustomCommand(BaseCommand):
22+
description = text
23+
24+
def run(self):
25+
for cmd in commands:
26+
subprocess.check_call(cmd)
27+
28+
return CustomCommand
29+
30+
531
with open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8') as readme:
632
README = readme.read().split('h1>\n\n', 2)[1]
733

34+
835
setup(
936
name='django-postgres-extra',
10-
version='1.21a13',
37+
version='1.21a14',
1138
packages=find_packages(),
1239
include_package_data=True,
1340
license='MIT License',
@@ -27,5 +54,11 @@
2754
'Programming Language :: Python :: 3.5',
2855
'Topic :: Internet :: WWW/HTTP',
2956
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
30-
]
57+
],
58+
cmdclass={
59+
'lint': create_command(
60+
'Lints the code',
61+
[['flake8', 'setup.py', 'psqlextra', 'tests']],
62+
),
63+
},
3164
)

tests/test_conditional_unique_index.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ def test_migrations():
5959
calls = [call[0] for _, call, _ in simulator.migrate('CREATE UNIQUE INDEX')[0]['CREATE UNIQUE INDEX']]
6060

6161
db_table = Model._meta.db_table
62-
assert str(calls[0]) == 'CREATE UNIQUE INDEX "index1" ON "{0}" ("name", "other_name") WHERE "name" IS NOT NULL'.format(
62+
query = 'CREATE UNIQUE INDEX "index1" ON "{0}" ("name", "other_name") WHERE "name" IS NOT NULL'
63+
assert str(calls[0]) == query.format(
6364
db_table
6465
)
65-
assert str(calls[1]) == 'CREATE UNIQUE INDEX "index2" ON "{0}" ("other_name") WHERE "name" IS NULL'.format(
66+
67+
query = 'CREATE UNIQUE INDEX "index2" ON "{0}" ("other_name") WHERE "name" IS NULL'
68+
assert str(calls[1]) == query.format(
6669
db_table
6770
)
6871

tests/test_on_conflict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ def test_on_conflict_bulk():
414414
for index, obj in enumerate(list(model.objects.all())):
415415
assert obj.title == rows[index]['title']
416416

417+
417418
def test_bulk_return():
418-
"""Tests if primary keys are properly returned from 'bulk_insert'
419-
"""
419+
"""Tests if primary keys are properly returned from 'bulk_insert'"""
420420

421421
model = get_fake_model({
422422
'id': models.BigAutoField(primary_key=True),

tests/test_on_conflict_nothing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,4 @@ def test_on_conflict_nothing_foreign_key_by_id():
191191
assert obj1.other == other_obj
192192
assert obj2.other == other_obj
193193
assert obj1.data == "some data"
194-
assert obj2.data == "some data"
194+
assert obj2.data == "some data"

tests/test_signals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def mock_signal_handler(signal):
1616
"""
1717

1818
model = get_fake_model({
19-
'title': models.CharField(max_length=255),
20-
'flag': models.BooleanField(default=False)
21-
})
19+
'title': models.CharField(max_length=255),
20+
'flag': models.BooleanField(default=False)
21+
})
2222

2323
signal_handler = Mock()
2424
signal.connect(signal_handler, sender=model, weak=False)

0 commit comments

Comments
 (0)