Skip to content

Commit 051bffa

Browse files
authored
Merge pull request #658 from pradyunsg/better-linting
Better linting setup
2 parents 677fa09 + 88e4959 commit 051bffa

File tree

176 files changed

+2940
-2405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+2940
-2405
lines changed

.github/CONTRIBUTING.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ data to the new models.
4545
Code Convention
4646
---------------
4747

48-
We follow the `Django Coding Style`_ and enforce it using `flake8`_.
49-
50-
In general, if flake8 is happy with your code, you should be fine. To use
51-
``flake8`` to check your code, you can use the following command::
52-
53-
$ flake8 --max-complexity=24 --statistics --benchmark --ignore=E5,F4 <project_dir>/
48+
We follow the `Black Coding Style`_, and sort our imports with `isort`_. This
49+
code style is enforced with automation.
5450

5551
.. _`issue tracker`: https://github.com/pythonindia/junction/issues
56-
.. _`flake8`: https://flake8.readthedocs.org/en/latest/
57-
.. _`Django Coding Style`: https://docs.djangoproject.com/en/2.2/internals/contributing/writing-code/coding-style/
52+
.. _`isort`: https://isort.readthedocs.org/en/latest/
53+
.. _`Black Coding Style`: https://black.readthedocs.io/en/latest/the_black_code_style.html

.pre-commit-config.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v2.5.0
5+
hooks:
6+
- id: check-builtin-literals
7+
- id: check-added-large-files
8+
- id: check-case-conflict
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
- id: forbid-new-submodules
13+
- id: trailing-whitespace
14+
15+
- repo: https://github.com/pre-commit/pygrep-hooks
16+
rev: v1.4.1
17+
hooks:
18+
- id: python-no-log-warn
19+
- id: python-no-eval
20+
- id: rst-backticks
21+
22+
- repo: https://gitlab.com/pycqa/flake8
23+
rev: 3.7.9
24+
hooks:
25+
- id: flake8
26+
exclude: .*/migrations/.*|settings/.*
27+
28+
- repo: https://github.com/timothycrosley/isort
29+
rev: 4.3.21
30+
hooks:
31+
- id: isort
32+
files: \.py$
33+
34+
- repo: https://github.com/psf/black
35+
rev: stable
36+
hooks:
37+
- id: black
38+
language_version: python3.6
39+
exclude: .*/migrations/.*

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
python: 3.7
3232

3333
install:
34+
# Enable Python 3.6.x, when python: 3.5 (because black is Py3.6+)
35+
- |
36+
if [ "${TRAVIS_PYTHON_VERSION}" == "3.5" ]; then
37+
pyenv shell system:3.6.7
38+
fi
39+
3440
# Get the latest pip
3541
- python -m pip install --upgrade pip
3642
# Reinstall pip, using the latest pip

docs/source/conf.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
project = 'Junction'
2-
copyright = '2019, Junction Developers'
3-
author = 'Junction Developers'
1+
project = "Junction"
2+
copyright = "2019, Junction Developers"
3+
author = "Junction Developers"
44

55

66
# -- General configuration ---------------------------------------------------
77

88
# Add any Sphinx extension module names here, as strings. They can be
99
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1010
# ones.
11-
extensions = ['recommonmark']
11+
extensions = ["recommonmark"]
1212

1313
# Add any paths that contain templates here, relative to this directory.
14-
templates_path = ['_templates']
14+
templates_path = ["_templates"]
1515

1616
# List of patterns, relative to source directory, that match files and
1717
# directories to ignore when looking for source files.
@@ -20,32 +20,29 @@
2020

2121
# The suffix of source filenames.
2222
source_suffix = {
23-
'.rst': 'restructuredtext',
24-
'.md': 'markdown',
23+
".rst": "restructuredtext",
24+
".md": "markdown",
2525
}
2626

2727
# -- Options for HTML output -------------------------------------------------
2828

2929
# The theme to use for HTML and HTML Help pages. See the documentation for
3030
# a list of builtin themes.
3131
#
32-
html_theme = 'alabaster'
32+
html_theme = "alabaster"
3333

3434
# Add any paths that contain custom static files (such as style sheets) here,
3535
# relative to this directory. They are copied after the builtin static files,
3636
# so a file named "default.css" will overwrite the builtin "default.css".
37-
html_static_path = ['_static']
37+
html_static_path = ["_static"]
3838

3939
# -- Recommonmark/Markdown stuff ---------------------------------------------
4040
# NOTE: This entire section should be removed once the old/ folder is removed
4141
# from the docs/ directory.
4242

43-
from recommonmark.parser import CommonMarkParser
44-
from recommonmark.transform import AutoStructify
43+
from recommonmark.transform import AutoStructify # noqa: E402
4544

4645

4746
def setup(app):
48-
app.add_config_value('recommonmark_config', {
49-
'enable_auto_toc_tree': True,
50-
}, True)
47+
app.add_config_value("recommonmark_config", {"enable_auto_toc_tree": True}, True)
5148
app.add_transform(AutoStructify)

junction/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = '0.3.2'
3-
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
2+
__version__ = "0.3.2"
3+
__version_info__ = tuple(
4+
[
5+
int(num) if num.isdigit() else num
6+
for num in __version__.replace("-", ".", 1).split(".")
7+
]
8+
)
49

510
# This will make sure the app is always imported when
611
# Django starts so that shared_task will use this app.

junction/base/admin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
33

4-
# Third Party Stuff
54
from django.contrib import admin
65

76

@@ -17,12 +16,18 @@ def save_model(self, request, obj, form, change):
1716

1817

1918
class TimeAuditAdmin(admin.ModelAdmin):
20-
list_display = ('created_at', 'modified_at',)
19+
list_display = (
20+
"created_at",
21+
"modified_at",
22+
)
2123

2224

2325
class AuditAdmin(TimeAuditAdmin):
24-
list_display = ('created_by', 'modified_by',) + TimeAuditAdmin.list_display
25-
exclude = ('created_by', 'modified_by',)
26+
list_display = ("created_by", "modified_by",) + TimeAuditAdmin.list_display
27+
exclude = (
28+
"created_by",
29+
"modified_by",
30+
)
2631

2732
def save_model(self, request, obj, form, change):
2833
save_model(self, request, obj, form, change)

junction/base/apps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, print_function, unicode_literals
33

4-
# Standard Library
54
import sys
65

7-
# Third Party Stuff
86
from django.apps import AppConfig
97

108
from . import monkey

junction/base/constants.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
33

4-
# Standard Library
54
import inspect
65

76

87
def _user_attributes(cls):
9-
defaults = dir(type(str('defaults'), (object,), {})) # gives all inbuilt attrs
10-
return [
11-
item[0] for item in inspect.getmembers(cls) if item[0] not in defaults]
8+
defaults = dir(type(str("defaults"), (object,), {})) # gives all inbuilt attrs
9+
return [item[0] for item in inspect.getmembers(cls) if item[0] not in defaults]
1210

1311

1412
def choices(cls):
@@ -20,7 +18,7 @@ def choices(cls):
2018
val = getattr(cls, attr)
2119
setattr(cls, attr[1:], val[0])
2220
_choices.append((val[0], val[1]))
23-
setattr(cls, 'CHOICES', tuple(_choices))
21+
setattr(cls, "CHOICES", tuple(_choices))
2422
return cls
2523

2624

@@ -72,8 +70,8 @@ class ProposalReviewVote:
7270
# FIXME: `ProposalReviewerComment` should be Boolean
7371
@choices
7472
class ProposalReviewerComment:
75-
_COMMENTED = ['True', 'Yes']
76-
_NOT_COMMENTED = ['False', 'No']
73+
_COMMENTED = ["True", "Yes"]
74+
_NOT_COMMENTED = ["False", "No"]
7775

7876

7977
@choices
@@ -89,24 +87,29 @@ class ConferenceSettingConstants:
8987
ALLOW_PUBLIC_VOTING_ON_PROPOSALS = {
9088
"name": "allow_public_voting_on_proposals",
9189
"value": True,
92-
"description": "Allow public to vote on proposals"}
90+
"description": "Allow public to vote on proposals",
91+
}
9392

94-
DISPLAY_PROPOSALS_IN_PUBLIC = {"name": "display_proposals_in_public",
95-
"value": True,
96-
"description": "Display proposals in public"}
93+
DISPLAY_PROPOSALS_IN_PUBLIC = {
94+
"name": "display_proposals_in_public",
95+
"value": True,
96+
"description": "Display proposals in public",
97+
}
9798

98-
ALLOW_PLUS_ZERO_REVIEWER_VOTE = {"name": "allow_plus_zero_reviewer_vote",
99-
"value": True,
100-
"description": "Allow +0 vote in reviewer votes"}
99+
ALLOW_PLUS_ZERO_REVIEWER_VOTE = {
100+
"name": "allow_plus_zero_reviewer_vote",
101+
"value": True,
102+
"description": "Allow +0 vote in reviewer votes",
103+
}
101104

102105

103106
@choices
104107
class PSRVotePhase:
105-
_PRIMARY = [0, 'Initial voting']
106-
_SECONDARY = [1, 'Second phase voting']
108+
_PRIMARY = [0, "Initial voting"]
109+
_SECONDARY = [1, "Second phase voting"]
107110

108111

109112
@choices
110113
class ProposalCommentType:
111-
_GENERAL = [0, 'All general comments']
112-
_SECONDARY_VOTING = [1, 'Second phase voting']
114+
_GENERAL = [0, "All general comments"]
115+
_SECONDARY_VOTING = [1, "Second phase voting"]

junction/base/context_processors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
33

4-
# Third Party Stuff
54
from django.conf import settings
65

76

87
def site_info(request):
9-
return {'SITE_INFO': settings.SITE_VARIABLES}
8+
return {"SITE_INFO": settings.SITE_VARIABLES}

junction/base/emailer.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
33

4-
# Standard Library
54
from os import path
65

7-
# Third Party Stuff
86
from django.conf import settings
97
from django.core.mail import send_mail
108
from django.template.loader import render_to_string
@@ -21,18 +19,24 @@ def send_email(to, context, template_dir):
2119
:rtype: None
2220
2321
"""
22+
2423
def to_str(template_name):
2524
return render_to_string(path.join(template_dir, template_name), context).strip()
2625

27-
subject = to_str('subject.txt')
28-
text_message = to_str('message.txt')
29-
html_message = to_str('message.html')
26+
subject = to_str("subject.txt")
27+
text_message = to_str("message.txt")
28+
html_message = to_str("message.html")
3029
from_email = settings.DEFAULT_FROM_EMAIL
3130
recipient_list = [_format_email(to)]
3231

33-
return send_mail(subject, text_message, from_email, recipient_list, html_message=html_message)
32+
return send_mail(
33+
subject, text_message, from_email, recipient_list, html_message=html_message
34+
)
3435

3536

3637
def _format_email(user):
37-
return user.email if user.first_name and user.last_name else \
38-
'"{} {}" <{}>'.format(user.first_name, user.last_name, user.email)
38+
return (
39+
user.email
40+
if user.first_name and user.last_name
41+
else '"{} {}" <{}>'.format(user.first_name, user.last_name, user.email)
42+
)

0 commit comments

Comments
 (0)