Skip to content

Commit

Permalink
Enforce trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum5 committed Sep 29, 2019
1 parent 45c7d52 commit cf9cf32
Show file tree
Hide file tree
Showing 44 changed files with 108 additions and 125 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ignore =
W504, # line break occurred after a binary operator
# allow only generator_stop and annotations future imports
FI10,FI11,FI12,FI13,FI14,FI15,FI16,FI17,FI18,FI55,FI58,
C814, # missing trailing comma in Python 2 only
per-file-ignores =
# F401: unused imports, ignore in all __init__.py
# F403: import *
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python: 3.7
install: pip install flake8 flake8-import-order flake8-future-import
install: pip install flake8 flake8-import-order flake8-future-import flake8-commas
script:
- flake8 --version
- flake8
Expand Down
2 changes: 1 addition & 1 deletion dmoj/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
@task_failure.connect()
def celery_failure_log(sender, task_id, exception, traceback, *args, **kwargs):
logger.exception('Celery Task {task_name}: {task_id} on {hostname}'.format(
task_name=sender.name, task_id=task_id, hostname=socket.gethostname()
task_name=sender.name, task_id=task_id, hostname=socket.gethostname(),
), exc_info=(type(exception), exception, traceback))
8 changes: 4 additions & 4 deletions dmoj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
'dashboard': {
'breadcrumbs': True,
},
}
},
}

INSTALLED_APPS += (
Expand Down Expand Up @@ -239,7 +239,7 @@
'django.contrib.messages.context_processors.messages',
],
},
}
},
]

LOCALE_PATHS = [
Expand Down Expand Up @@ -305,7 +305,7 @@
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
},
}

ENABLE_FTS = False
Expand Down Expand Up @@ -375,7 +375,7 @@
'judge.social_auth.make_profile',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details'
'social_core.pipeline.user.user_details',
)

SOCIAL_AUTH_GITHUB_SECURE_SCOPE = ['user:email']
Expand Down
4 changes: 2 additions & 2 deletions dmoj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
), name='auth_login'),
url(r'^logout/$', user.UserLogoutView.as_view(), name='auth_logout'),
url(r'^password/change/$', auth_views.PasswordChangeView.as_view(
template_name='registration/password_change_form.html'
template_name='registration/password_change_form.html',
), name='password_change'),
url(r'^password/change/done/$', auth_views.PasswordChangeDoneView.as_view(
template_name='registration/password_change_done.html',
Expand Down Expand Up @@ -367,7 +367,7 @@ def paged_list_view(view, name):

for favicon in favicon_paths:
urlpatterns.append(url(r'^%s$' % favicon, RedirectView.as_view(
url=lazystr(lambda: static('icons/' + favicon))
url=lazystr(lambda: static('icons/' + favicon)),
)))

handler404 = 'judge.views.error.error404'
Expand Down
2 changes: 1 addition & 1 deletion dmoj/wsgi_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def gevent_waiter(fd, hub=gevent.hub.get_hub()):
hub.wait(hub.loop.io(fd, 1))

MySQLdb.connect = MySQLdb.Connection = MySQLdb.Connect = wraps(MySQLdb.connect)(
partial(MySQLdb.connect, waiter=gevent_waiter)
partial(MySQLdb.connect, waiter=gevent_waiter),
)

from django.core.wsgi import get_wsgi_application # noqa: E402, I202, django must be imported here
Expand Down
6 changes: 3 additions & 3 deletions judge/admin/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_urls(self):
return [
url(r'^rate/all/$', self.rate_all_view, name='judge_contest_rate_all'),
url(r'^(\d+)/rate/$', self.rate_view, name='judge_contest_rate'),
url(r'^(\d+)/judge/(\d+)/$', self.rejudge_view, name='judge_contest_rejudge')
url(r'^(\d+)/judge/(\d+)/$', self.rejudge_view, name='judge_contest_rejudge'),
] + super(ContestAdmin, self).get_urls()

def rejudge_view(self, request, contest_id, problem_id):
Expand Down Expand Up @@ -228,7 +228,7 @@ def get_form(self, *args, **kwargs):
form.base_fields['organizers'].queryset = Profile.objects.filter(
Q(user__is_superuser=True) |
Q(user__groups__permissions__codename__in=perms) |
Q(user__user_permissions__codename__in=perms)
Q(user__user_permissions__codename__in=perms),
).distinct()
return form

Expand All @@ -253,7 +253,7 @@ class ContestParticipationAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return super(ContestParticipationAdmin, self).get_queryset(request).only(
'contest__name', 'contest__format_name', 'contest__format_config',
'user__user__username', 'real_start', 'score', 'cumtime', 'virtual'
'user__user__username', 'real_start', 'score', 'cumtime', 'virtual',
)

def recalculate_results(self, request, queryset):
Expand Down
2 changes: 1 addition & 1 deletion judge/admin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Meta:
class BlogPostAdmin(VersionAdmin):
fieldsets = (
(None, {'fields': ('title', 'slug', 'authors', 'visible', 'sticky', 'publish_on')}),
(_('Content'), {'fields': ('content', 'og_image',)}),
(_('Content'), {'fields': ('content', 'og_image')}),
(_('Summary'), {'classes': ('collapse',), 'fields': ('summary',)}),
)
prepopulated_fields = {'slug': ('title',)}
Expand Down
9 changes: 4 additions & 5 deletions judge/admin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs):
self.fields['testers'].widget.can_add_related = False
self.fields['banned_users'].widget.can_add_related = False
self.fields['change_message'].widget.attrs.update({
'placeholder': gettext('Describe the changes you made (optional)')
'placeholder': gettext('Describe the changes you made (optional)'),
})

class Meta:
Expand Down Expand Up @@ -119,17 +119,16 @@ class ProblemAdmin(VersionAdmin):
(None, {
'fields': (
'code', 'name', 'is_public', 'is_manually_managed', 'date', 'authors', 'curators', 'testers',
'is_organization_private', 'organizations',
'description',
'license')
'is_organization_private', 'organizations', 'description', 'license',
),
}),
(_('Social Media'), {'classes': ('collapse',), 'fields': ('og_image', 'summary')}),
(_('Taxonomy'), {'fields': ('types', 'group')}),
(_('Points'), {'fields': (('points', 'partial'), 'short_circuit')}),
(_('Limits'), {'fields': ('time_limit', 'memory_limit')}),
(_('Language'), {'fields': ('allowed_languages',)}),
(_('Justice'), {'fields': ('banned_users',)}),
(_('History'), {'fields': ('change_message',)})
(_('History'), {'fields': ('change_message',)}),
)
list_display = ['code', 'name', 'show_authors', 'points', 'is_public', 'show_public']
ordering = ['code']
Expand Down
6 changes: 3 additions & 3 deletions judge/admin/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def label(obj):

def label(obj):
return pgettext('contest problem', '%(problem)s in %(contest)s') % {
'problem': obj.problem.name, 'contest': obj.contest.name
'problem': obj.problem.name, 'contest': obj.contest.name,
}
field = super(ContestSubmissionInline, self).formfield_for_dbfield(db_field, **kwargs)
if label is not None:
Expand Down Expand Up @@ -123,7 +123,7 @@ class SubmissionAdmin(admin.ModelAdmin):
def get_queryset(self, request):
queryset = Submission.objects.select_related('problem', 'user__user', 'language').only(
'problem__code', 'problem__name', 'user__user__username', 'language__name',
'time', 'memory', 'points', 'status', 'result'
'time', 'memory', 'points', 'status', 'result',
)
use_straight_join(queryset)
if not request.user.has_perm('judge.edit_all_problem'):
Expand Down Expand Up @@ -237,7 +237,7 @@ def judge_column(self, obj):

def get_urls(self):
return [
url(r'^(\d+)/judge/$', self.judge_view, name='judge_submission_rejudge')
url(r'^(\d+)/judge/$', self.judge_view, name='judge_submission_rejudge'),
] + super(SubmissionAdmin, self).get_urls()

def judge_view(self, request, id):
Expand Down
14 changes: 7 additions & 7 deletions judge/bridge/judgecallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_related_submission_data(self, submission):
logger.error('Submission vanished: %d', submission)
json_log.error(self._make_json_log(
sub=self._working, action='request',
info='submission vanished when fetching info'
info='submission vanished when fetching info',
))
return

Expand Down Expand Up @@ -136,7 +136,7 @@ def _post_update_submission(self, id, state, done=False):
else:
self._submission_cache = data = Submission.objects.filter(id=id).values(
'problem__is_public', 'contest__participation__contest__key',
'user_id', 'problem_id', 'status', 'language__key'
'user_id', 'problem_id', 'status', 'language__key',
).get()
self._submission_cache_id = id

Expand Down Expand Up @@ -238,7 +238,7 @@ def on_grading_end(self, packet):
packet, action='grading-end', time=time, memory=memory,
points=sub_points, total=problem.points, result=submission.result,
case_points=points, case_total=total, user=submission.user_id,
problem=problem.code, finish=True
problem=problem.code, finish=True,
))

submission.user._updating_stats_only = True
Expand All @@ -255,7 +255,7 @@ def on_grading_end(self, packet):
'memory': memory,
'points': float(points),
'total': float(problem.points),
'result': submission.result
'result': submission.result,
})
if hasattr(submission, 'contest'):
participation = submission.contest.participation
Expand All @@ -268,7 +268,7 @@ def on_compile_error(self, packet):
if Submission.objects.filter(id=packet['submission-id']).update(status='CE', result='CE', error=packet['log']):
event.post('sub_%s' % Submission.get_id_secret(packet['submission-id']), {
'type': 'compile-error',
'log': packet['log']
'log': packet['log'],
})
self._post_update_submission(packet['submission-id'], 'compile-error', done=True)
json_log.info(self._make_json_log(packet, action='compile-error', log=packet['log'],
Expand Down Expand Up @@ -364,7 +364,7 @@ def on_test_case(self, packet, max_feedback=SubmissionTestCase._meta.get_field('
packet, action='test-case', case=test_case.case, batch=test_case.batch,
time=test_case.time, memory=test_case.memory, feedback=test_case.feedback,
extended_feedback=test_case.extended_feedback, output=test_case.output,
points=test_case.points, total=test_case.total, status=test_case.status
points=test_case.points, total=test_case.total, status=test_case.status,
))

do_post = True
Expand All @@ -390,7 +390,7 @@ def on_test_case(self, packet, max_feedback=SubmissionTestCase._meta.get_field('
'memory': packet['memory'],
'points': float(test_case.points),
'total': float(test_case.total),
'output': packet['output']
'output': packet['output'],
})
self._post_update_submission(id, state='test-case')

Expand Down
6 changes: 1 addition & 5 deletions judge/bridge/judgehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

logger = logging.getLogger('judge.bridge')


SubmissionData = namedtuple(
'SubmissionData',
'time memory short_circuit pretests_only contest_no attempt_no user_id'
)
SubmissionData = namedtuple('SubmissionData', 'time memory short_circuit pretests_only contest_no attempt_no user_id')


class JudgeHandler(ProxyProtocolMixin, ZlibPacketHandler):
Expand Down
2 changes: 1 addition & 1 deletion judge/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get(self, request, *args, **kwargs):
self.object = self.get_object()
return self.render_to_response(self.get_context_data(
object=self.object,
comment_form=CommentForm(request, initial={'page': self.get_comment_page(), 'parent': None})
comment_form=CommentForm(request, initial={'page': self.get_comment_page(), 'parent': None}),
))

def get_context_data(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion judge/contest_format/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def update_participation(self, participation):
format_data = {}

for result in participation.submissions.values('problem_id').annotate(
time=Max('submission__date'), points=Max('points')
time=Max('submission__date'), points=Max('points'),
):
dt = (result['time'] - participation.start).total_seconds()
if result['points']:
Expand Down
2 changes: 1 addition & 1 deletion judge/dblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LockModel(object):
def __init__(self, write, read=()):
self.tables = ', '.join(chain(
('`%s` WRITE' % model._meta.db_table for model in write),
('`%s` READ' % model._meta.db_table for model in read)
('`%s` READ' % model._meta.db_table for model in read),
))
self.cursor = connection.cursor()

Expand Down
6 changes: 3 additions & 3 deletions judge/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Meta:
if HeavyPreviewPageDownWidget is not None:
widgets['about'] = HeavyPreviewPageDownWidget(
preview=reverse_lazy('profile_preview'),
attrs={'style': 'max-width:700px;min-width:700px;width:700px'}
attrs={'style': 'max-width:700px;min-width:700px;width:700px'},
)

def clean(self):
Expand All @@ -63,7 +63,7 @@ def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
if not user.has_perm('judge.edit_all_organization'):
self.fields['organizations'].queryset = Organization.objects.filter(
Q(is_open=True) | Q(id__in=user.profile.organizations.all())
Q(is_open=True) | Q(id__in=user.profile.organizations.all()),
)


Expand Down Expand Up @@ -128,7 +128,7 @@ class TOTPForm(Form):
TOLERANCE = getattr(settings, 'DMOJ_TOTP_TOLERANCE_HALF_MINUTES', 1)

totp_token = NoAutoCompleteCharField(validators=[
RegexValidator('^[0-9]{6}$', _('Two Factor Authentication tokens must be 6 decimal digits.'))
RegexValidator('^[0-9]{6}$', _('Two Factor Authentication tokens must be 6 decimal digits.')),
])

def __init__(self, *args, **kwargs):
Expand Down
10 changes: 3 additions & 7 deletions judge/jinja2/markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@


class CodeSafeInlineGrammar(mistune.InlineGrammar):
double_emphasis = re.compile(
r'^\*{2}([\s\S]+?)()\*{2}(?!\*)' # **word**
)
emphasis = re.compile(
r'^\*((?:\*\*|[^\*])+?)()\*(?!\*)' # *word*
)
double_emphasis = re.compile(r'^\*{2}([\s\S]+?)()\*{2}(?!\*)') # **word**
emphasis = re.compile(r'^\*((?:\*\*|[^\*])+?)()\*(?!\*)') # *word*


class AwesomeInlineGrammar(MathInlineGrammar, CodeSafeInlineGrammar):
Expand Down Expand Up @@ -87,7 +83,7 @@ def block_html(self, html):
'width="%(width)s" height="%(height)s"%(tail)s>') % {
'svg': result['svg'], 'png': result['png'],
'width': result['meta']['width'], 'height': result['meta']['height'],
'tail': ' /' if self.options.get('use_xhtml') else ''
'tail': ' /' if self.options.get('use_xhtml') else '',
}
style = ['max-width: 100%',
'height: %s' % result['meta']['height'],
Expand Down
2 changes: 1 addition & 1 deletion judge/management/commands/runmoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def handle(self, *args, **options):
contest__participation__virtual__in=(ContestParticipation.LIVE, ContestParticipation.SPECTATE),
contest__participation__contest__key=contest,
result='AC', problem__id=problem.id,
language__common_name=dmoj_lang
language__common_name=dmoj_lang,
).values_list('user__user__username', 'source__source')
if not subs:
print('<no submissions>')
Expand Down
4 changes: 2 additions & 2 deletions judge/migrations/0085_submission_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Migration(migrations.Migration):
['''UPDATE judge_submission sub
INNER JOIN judge_submissionsource src ON sub.id = src.submission_id
SET sub.source = src.source;'''],
elidable=True
elidable=True,
),
migrations.RemoveField(
model_name='submission',
Expand All @@ -34,6 +34,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='submissionsource',
name='submission',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='source', to='judge.Submission', verbose_name='associated submission')
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='source', to='judge.Submission', verbose_name='associated submission'),
),
]
2 changes: 1 addition & 1 deletion judge/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def css_class(self):
class Meta:
permissions = (
('test_site', 'Shows in-progress development stuff'),
('totp', 'Edit TOTP settings')
('totp', 'Edit TOTP settings'),
)
verbose_name = _('user profile')
verbose_name_plural = _('user profiles')
Expand Down
4 changes: 2 additions & 2 deletions judge/social_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def choose_username(backend, user, username=None, *args, **kwargs):
else:
form = UsernameForm(initial={'username': username})
return render(request, 'registration/username_select.html', {
'title': 'Choose a username', 'form': form
'title': 'Choose a username', 'form': form,
})


Expand All @@ -98,7 +98,7 @@ def make_profile(backend, user, response, is_new=False, *args, **kwargs):
revisions.set_comment('Updated on registration')
return
return render(backend.strategy.request, 'registration/profile_creation.html', {
'title': 'Create your profile', 'form': form
'title': 'Create your profile', 'form': form,
})


Expand Down
2 changes: 1 addition & 1 deletion judge/utils/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _update_state(self):
'done': self._done,
'total': self._total,
'stage': self._stage,
}
},
)

@property
Expand Down
Loading

0 comments on commit cf9cf32

Please sign in to comment.