Skip to content

Finish linting on py3ish code #2949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.db
*.egg-info
*.log
*.pyc
*.swp
.DS_Store
Expand Down
35 changes: 20 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
language: python
python:
- 3.6
- 2.7
- 3.6
sudo: false
env:
- TOX_ENV=py27
- TOX_ENV=py36
- TOX_ENV=docs
- TOX_ENV=lint
- TOX_ENV=eslint
matrix:
include:
- python: 2.7
env: TOXENV=docs
- python: 2.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is lint different on 2 or 3, should we be linting both languages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I was going to say bump linting and docs steps up to py3 when our code is ready. I don't know if bumping up before then would yield any unwarranted effects or not from the code not being quiet py3 compatible.

Copy link
Member

@ericholscher ericholscher Jun 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

env: TOXENV=lint
- python: 2.7
env: TOXENV=eslint
script:
- tox
cache:
directories:
- ~/.cache/pip
- ~/.nvm/nvm.sh
install:
- pip install tox
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
- source ~/.nvm/nvm.sh
- nvm install --lts
- nvm use --lts
- npm install
- bower install
- pip install tox-travis
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
- source ~/.nvm/nvm.sh
- nvm install --lts
- nvm use --lts
- npm install
- bower install
script:
- tox -e $TOX_ENV
- tox
notifications:
slack:
rooms:
Expand Down
34 changes: 32 additions & 2 deletions prospector-more.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
inherits: prospector

strictness: medium
strictness: high

ignore-paths:
- restapi/
- constants.py
- urls.py
- wsgi.py
- acl
- api
- betterversion
- bookmarks
- builds
- cdn
- comments
- core
- djangome
- doc_builder
- donate
- gold
- integrations
- locale
- notifications
- oauth
- payments
- privacy
- profiles
- projects
- redirects
- restapi
- rtd_tests
- search
- settings
- tastyapi
- templates
- vcs_support

pylint:
options:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def is_authenticated(self, request, **kwargs):


class EnhancedModelResource(ModelResource):
def obj_get_list(self, request=None, *_, **kwargs):
def obj_get_list(self, request=None, *_, **kwargs): # pylint: disable=arguments-differ
"""
A ORM-specific implementation of ``obj_get_list``.

Expand Down
65 changes: 32 additions & 33 deletions readthedocs/bookmarks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
class BookmarkExistsView(View):

@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(BookmarkExistsView, self).dispatch(*args, **kwargs)
def dispatch(self, request, *args, **kwargs):
return super(BookmarkExistsView, self).dispatch(request, *args, **kwargs)

def get(self, request):
return HttpResponse(
Expand Down Expand Up @@ -81,8 +81,8 @@ class BookmarkListView(ListView):
model = Bookmark

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(BookmarkListView, self).dispatch(*args, **kwargs)
def dispatch(self, request, *args, **kwargs):
return super(BookmarkListView, self).dispatch(request, *args, **kwargs)

def get_queryset(self):
return Bookmark.objects.filter(user=self.request.user)
Expand All @@ -94,8 +94,8 @@ class BookmarkAddView(View):

@method_decorator(login_required)
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(BookmarkAddView, self).dispatch(*args, **kwargs)
def dispatch(self, request, *args, **kwargs):
return super(BookmarkAddView, self).dispatch(request, *args, **kwargs)

def get(self, request):
return HttpResponse(
Expand Down Expand Up @@ -157,8 +157,8 @@ class BookmarkRemoveView(View):

@method_decorator(login_required)
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(BookmarkRemoveView, self).dispatch(*args, **kwargs)
def dispatch(self, request, *args, **kwargs):
return super(BookmarkRemoveView, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
return render_to_response(
Expand All @@ -176,30 +176,29 @@ def post(self, request, *args, **kwargs):
bookmark = get_object_or_404(Bookmark, pk=kwargs['bookmark_pk'])
bookmark.delete()
return HttpResponseRedirect(reverse('bookmark_list'))
else:
try:
post_json = json.loads(request.body)
project = Project.objects.get(slug=post_json['project'])
version = project.versions.get(slug=post_json['version'])
url = post_json['url']
page = post_json['page']
except KeyError:
return HttpResponseBadRequest(
json.dumps({'error': "Invalid parameters"})
)

bookmark = get_object_or_404(
Bookmark,
user=request.user,
url=url,
project=project,
version=version,
page=page
try:
post_json = json.loads(request.body)
project = Project.objects.get(slug=post_json['project'])
version = project.versions.get(slug=post_json['version'])
url = post_json['url']
page = post_json['page']
except KeyError:
return HttpResponseBadRequest(
json.dumps({'error': "Invalid parameters"})
)
bookmark.delete()

return HttpResponse(
json.dumps({'removed': True}),
status=200,
content_type="application/json"
)
bookmark = get_object_or_404(
Bookmark,
user=request.user,
url=url,
project=project,
version=version,
page=page
)
bookmark.delete()

return HttpResponse(
json.dumps({'removed': True}),
status=200,
content_type="application/json"
)
4 changes: 2 additions & 2 deletions readthedocs/builds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Meta(object):
model = Version
fields = ['active', 'privacy_level', 'tags']

def save(self, *args, **kwargs):
obj = super(VersionForm, self).save(*args, **kwargs)
def save(self, commit=True):
obj = super(VersionForm, self).save(commit=commit)
if obj.active and not obj.built and not obj.uploaded:
trigger_build(project=obj.project, version=obj)
return obj
7 changes: 3 additions & 4 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def commit_name(self):
if self.slug == LATEST:
if self.project.default_branch:
return self.project.default_branch
else:
return self.project.vcs_repo().fallback_branch
return self.project.vcs_repo().fallback_branch

if self.slug == STABLE:
if self.type == BRANCH:
Expand Down Expand Up @@ -148,7 +147,7 @@ def get_absolute_url(self):
private = self.privacy_level == PRIVATE
return self.project.get_docs_url(version_slug=self.slug, private=private)

def save(self, *args, **kwargs):
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
"""Add permissions to the Version for all owners on save."""
from readthedocs.projects import tasks
obj = super(Version, self).save(*args, **kwargs)
Expand All @@ -161,7 +160,7 @@ def save(self, *args, **kwargs):
broadcast(type='app', task=tasks.symlink_project, args=[self.project.pk])
return obj

def delete(self, *args, **kwargs):
def delete(self, *args, **kwargs): # pylint: disable=arguments-differ
from readthedocs.projects import tasks
log.info('Removing files for version %s', self.slug)
tasks.clear_artifacts.delay(version_pk=self.pk)
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/builds/version_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"""

from __future__ import absolute_import
from builtins import range

import math
import re
import string
from operator import truediv

from django.db import models
from django.utils.encoding import force_text
from six.moves import range
from builtins import range


# Regex breakdown:
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/cdn/purge.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Utility to purge MaxCDN files, if configured."""

from __future__ import absolute_import
from builtins import range

import logging

from django.conf import settings
from six.moves import range
from builtins import range


log = logging.getLogger(__name__)

Expand Down
27 changes: 12 additions & 15 deletions readthedocs/comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def from_hash(self, version_slug, page, node_hash, project_slug=None):
if project_slug:
snapshots = snapshots.filter(node__project__slug=project_slug)

if len(snapshots) == 0:
if not snapshots.exists():
raise DocumentNode.DoesNotExist(
"No node exists on %s with a current hash of %s" % (
page, node_hash))

if len(snapshots) == 1:
if snapshots.count() == 1:
# If we have found only one snapshot, we know we have the correct node.
node = snapshots[0].node
else:
Expand Down Expand Up @@ -89,22 +89,20 @@ def latest_commit(self):
def visible_comments(self):
if not self.project.comment_moderation:
return self.comments.all()
else:
# non-optimal SQL warning.
decisions = ModerationAction.objects.filter(
comment__node=self,
decision=1,
date__gt=self.snapshots.latest().date
)
valid_comments = self.comments.filter(moderation_actions__in=decisions).distinct()
return valid_comments
# non-optimal SQL warning.
decisions = ModerationAction.objects.filter(
comment__node=self,
decision=1,
date__gt=self.snapshots.latest().date
)
valid_comments = self.comments.filter(moderation_actions__in=decisions).distinct()
return valid_comments

def update_hash(self, new_hash, commit):
latest_snapshot = self.snapshots.latest()
if latest_snapshot.hash == new_hash and latest_snapshot.commit == commit:
return latest_snapshot
else:
return self.snapshots.create(hash=new_hash, commit=commit)
return self.snapshots.create(hash=new_hash, commit=commit)


class DocumentNodeSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -190,8 +188,7 @@ def has_been_approved_since_most_recent_node_change(self):
# If we do have an approval action which is newer than the most recent change,
# we'll return True or False commensurate with its "approved" attribute.
return latest_moderation_action.approved()
else:
return False
return False

def is_orphaned(self):
raise NotImplementedError('TODO')
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def get_queryset(self):
return queryset

@method_decorator(login_required)
def create(self, request):
def create(self, request, *args, **kwargs):
project = Project.objects.get(slug=request.data['project'])
comment = project.add_comment(version_slug=request.data['version'],
page=request.data['document_page'],
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __init__(self, *args, **kwargs):
except AttributeError:
pass

def save(self, *args, **kwargs):
def save(self, commit=True):
first_name = self.cleaned_data.pop('first_name', None)
last_name = self.cleaned_data.pop('last_name', None)
profile = super(UserProfileForm, self).save(*args, **kwargs)
if kwargs.get('commit', True):
profile = super(UserProfileForm, self).save(commit=commit)
if commit:
user = profile.user
user.first_name = first_name
user.last_name = last_name
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/management/commands/import_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Command(BaseCommand):
help = __doc__

def handle(self, *args, **options):
if len(args):
if args:
for slug in args:
for service in GitHubService.for_user(
User.objects.get(username=slug)
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/management/commands/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Command(BaseCommand):
help = __doc__

def handle(self, *args, **options):
if len(args):
if args:
for slug in args:
tasks.update_imported_docs(
utils.version_from_slug(slug, LATEST).pk
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/management/commands/update_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def handle(self, *args, **options):
record = options['record']
force = options['force']
version = options['version']
if len(args):
if args:
for slug in args:
if version and version != "all":
log.info("Updating version %s for %s", version, slug)
Expand Down
Loading